如何选择python系列的最后几行?

2024-03-29 13:37:42 发布

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

我有一个python系列,我想选择它的最后5行。如果我使用ts[-5:-1],它不会返回最后一行。我该怎么做?谢谢!你知道吗


Tags: ts
1条回答
网友
1楼 · 发布于 2024-03-29 13:37:42

使用^{}

s.tail(5)

^{}

s.iloc[-5:]

样品:

s = pd.Series(range(10))    
print (s)
0    0
1    1
2    2
3    3
4    4
5    5
6    6
7    7
8    8
9    9
dtype: int32

print (s.tail(5))
5    5
6    6
7    7
8    8
9    9
dtype: int32

print (s.iloc[-5:])
5    5
6    6
7    7
8    8
9    9
dtype: int32

相关问题 更多 >