pandas.DataFrame.first#
- DataFrame.first(offset)[源代码]#
根据日期偏移量选择时间序列数据的初始期间。
当使用日期作为索引的DataFrame时,此函数可以根据日期偏移量选择前几行。
- 参数
- offset字符串、日期偏移量或日期.relativedelta
将选择的数据的偏移长度。例如,‘1M’将显示第一个月内具有索引的所有行。
- 退货
- 系列或DataFrame
调用方的子集。
- 加薪
- TypeError
如果索引不是
DatetimeIndex
参见
last
根据日期偏移量选择时间序列的最终期间。
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.first('3D') A 2018-04-09 1 2018-04-11 2
请注意,返回的是前3个日历日的数据,而不是数据集中观察到的前3天的数据,因此未返回2018-04-13年的数据。