pandas.Series.first#

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

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

自 2.1 版本弃用: first() 已弃用,将在未来版本中删除。请创建掩码并使用 .loc 进行过滤。

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

Parameters:
offsetstr, DateOffset or dateutil.relativedelta

The offset length of the data that will be selected. For instance, ‘1ME’ will display all the rows having their index within the first month.

Returns:
Series 或 DataFrame

A subset of the caller.

Raises:
TypeError

如果索引不是 DatetimeIndex

参见

last

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

at_time

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

between_time

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

Examples

>>> 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

Get the rows for the first 3 days:

>>> ts.first('3D')
            A
2018-04-09  1
2018-04-11  2

Notice the data for 3 first calendar days were returned, not the first 3 days observed in the dataset, and therefore data for 2018-04-13 was not returned.