【问题标题】:How to choose last several rows of python series? [duplicate]如何选择python系列的最后几行? [复制] 【发布时间】:2017-02-15 00:59:36 【问题描述】: 我有一个 python 系列,我想选择它的最后 5 行。如果我使用 ts[-5:-1],它不会返回最后一行。我该怎么做?谢谢! 【问题讨论】: 标签: python pandas 【解决方案1】: 使用tail: s.tail(5) 或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 【讨论】: