pandas.DatetimeIndex.dayofyear #

属性 DatetimeIndex。年中的某一天[来源] #

一年中的第一个日子。

例子

对于系列:

>>> s = pd.Series(["1/1/2020 10:00:00+00:00", "2/1/2020 11:00:00+00:00"])
>>> s = pd.to_datetime(s)
>>> s
0   2020-01-01 10:00:00+00:00
1   2020-02-01 11:00:00+00:00
dtype: datetime64[ns, UTC]
>>> s.dt.dayofyear
0    1
1   32
dtype: int32

对于日期时间索引:

>>> idx = pd.DatetimeIndex(["1/1/2020 10:00:00+00:00",
...                         "2/1/2020 11:00:00+00:00"])
>>> idx.dayofyear
Index([1, 32], dtype='int32')