如何切片熊猫数据框的开始和结束



我在数据框中有100个值,我想使用tabulate打印一个漂亮的表。这对我有用:

print(tabulate(dat], headers='keys', tablefmt='psql'))

现在,这打印出整个数据框架。我无法在此处获得相关的切片信息:了解Python的切片符号

,但我想打印出前5个值,然后打印出几个...,然后打印出最后5个值。

示例:

4
2
1
5
1
.
.
4
1
2
4
5

我该怎么做?

您需要set_option,最大行应该为10,头5和尾巴5

For example 
s=pd.Series([1,2,3,4,5,6,7,8,9,10,11,12])
pd.set_option('max_rows', 10)
s
Out[1443]: 
0      1
1      2
2      3
3      4
4      5
      ..
7      8
8      9
9     10
10    11
11    12
Length: 12, dtype: int64