显示"长" jupyter笔记本中的pandas数据帧" foldover" (包装)?

时间:2016-10-09 00:47:55

标签: python pandas ipython jupyter jupyter-notebook

我们说我有一个包含许多列的pandas数据框:

enter image description here

我可以通过向左/向右滚动查看所有列。然而,这有点不方便,我想知道是否有一种优雅的方式来显示表格" foldover":

enter image description here

为了生成上述内容,我手动将数据帧切割成块并显示每个块(这就是为什么间距/等不完美)。

我想知道是否有办法更干净地做上述事情,可能是通过改变熊猫或jupyter设置?

2 个答案:

答案 0 :(得分:2)

试试这个:

In [135]: df = pd.DataFrame(np.random.rand(3, 30), columns=list(range(30)))

In [136]: pd.options.display.expand_frame_repr=True

In [137]: pd.options.display.max_columns = None

In [138]: pd.options.display.width = 80

In [139]: df
Out[139]:
         0         1         2         3         4         5         6   \
0  0.072370  0.388609  0.112033  0.829140  0.700152  0.645331  0.063483
1  0.890765  0.330274  0.900561  0.128318  0.056443  0.239560  0.568522
2  0.295088  0.101399  0.417066  0.657503  0.872717  0.153140  0.909876

         7         8         9         10        11        12        13  \
0  0.497130  0.852824  0.778126  0.710167  0.526406  0.416188  0.154483
1  0.451316  0.409711  0.352989  0.810885  0.540569  0.999328  0.144429
2  0.442140  0.892209  0.150371  0.337189  0.584538  0.152138  0.278306

         14        15        16        17        18        19        20  \
0  0.520901  0.857807  0.969782  0.577220  0.016009  0.809139  0.231900
1  0.561181  0.446312  0.468740  0.076465  0.383884  0.850491  0.815509
2  0.147742  0.957585  0.010312  0.021724  0.572048  0.952412  0.033100

         21        22        23        24        25        26        27  \
0  0.656393  0.823157  0.507222  0.889953  0.076415  0.820150  0.441099
1  0.919607  0.942032  0.586774  0.469604  0.596542  0.156348  0.099294
2  0.978045  0.537873  0.283019  0.582568  0.012389  0.943704  0.028346

         28        29
0  0.921219  0.569421
1  0.016056  0.298474
2  0.061831  0.488659

答案 1 :(得分:2)

除了像你一样设置max cols,我还要导入import pandas as pd pd.set_option('display.max_columns', None) from IPython.display import display

df = pd.DataFrame([range(200)])

cols = df.shape[1]

for i in range(0,cols,30):   
    display(df.iloc[:,i:i+30])

创建一个框架然后一个简单的for循环来显示每30个cols

var ss = SpreadsheetApp.openById(ssId);
dataSheet = ss.getSheetByName('ProjectIndex');
var data = dataSheet.getRange('A1:B').getValues();

... // search data and find row i

var j = i+1; // account for zero-based array but 1-based row numbering
var rc = 'A'+j+':BL'+j; // there are BL columns in Projects
var record = ss.getSheetByName('Projects').getRange(rc).getValues();

编辑:忘记添加输出图片

enter image description here