我有一个python系列,我想选择它的最后5行。如果我使用ts-5:-1,它不会返回最后一行。我该怎么做呢?谢谢!
发布于 2016-10-06 18:15:48
使用tail
tail
s.tail(5)
或iloc
iloc
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
https://stackoverflow.com/questions/39893327
相似问题