pandas.Series.last#

Series.last(offset)[源代码]#

根据日期偏移量选择时间序列数据的最终期间。

对于具有排序的DatetimeIndex的DataFrame,此函数根据日期偏移量选择最后几行。

参数
offset字符串、日期偏移量、日期.relativedelta

将选择的数据的偏移长度。例如,‘3D’将显示最近3天内具有索引的所有行。

退货
系列或DataFrame

调用方的子集。

加薪
TypeError

如果索引不是 DatetimeIndex

参见

first

根据日期偏移量选择时间序列的初始期间。

at_time

选择一天中特定时间的值。

between_time

选择一天中特定时间之间的值。

示例

>>> i = pd.date_range('2018-04-09', periods=4, freq='2D')
>>> ts = pd.DataFrame({'A': [1, 2, 3, 4]}, index=i)
>>> ts
            A
2018-04-09  1
2018-04-11  2
2018-04-13  3
2018-04-15  4

获取最近3天的行数:

>>> ts.last('3D')
            A
2018-04-13  3
2018-04-15  4

请注意,返回的是最后3个日历日的数据,而不是数据集中观察到的最后3个天数,因此没有返回2018-04-11年的数据。