如何分割数据帧的开头和结尾?

2024-06-03 03:55:55 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

现在,这个打印出整个数据帧。我无法在此处获取相关的切片信息:Understanding Python's slice notation

但是我想打印出前5个值,然后是一些...,然后是最后5个值

示例:

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

我该怎么做


Tags: 数据信息示例切片slicekeysdatheaders
1条回答
网友
1楼 · 发布于 2024-06-03 03:55:55

您将需要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

相关问题 更多 >