pandas.Series.dt.is_year_start#
- Series.dt.is_year_start[source] #
Indicate whether the date is the first day of a year.
- Returns:
- Series or DatetimeIndex
The same type as the original data with boolean values. Series will have the same name and index. DatetimeIndex will have the same name.
See also
is_year_end
Similar property indicating the last day of the year.
Examples
This method is available on Series with datetime values under the
.dt
accessor, and directly on DatetimeIndex.>>> dates = pd.Series(pd.date_range("2017年12月30日", periods=3)) >>> dates 0 2017年12月30日 1 2017年12月31日 2 2018年01月01日 dtype: datetime64[ns]
>>> dates.dt.is_year_start 0 False 1 False 2 True dtype: bool
>>> idx = pd.date_range("2017年12月30日", periods=3) >>> idx DatetimeIndex(['2017年12月30日', '2017年12月31日', '2018年01月01日'], dtype='datetime64[ns]', freq='D')
>>> idx.is_year_start array([False, False, True])
This method, when applied to Series with datetime values under the
.dt
accessor, will lose information about Business offsets.>>> dates = pd.Series(pd.date_range("2020年10月30日", periods=4, freq="BYS")) >>> dates 0 2021年01月01日 1 2022年01月03日 2 2023年01月02日 3 2024年01月01日 dtype: datetime64[ns]
>>> dates.dt.is_year_start 0 True 1 False 2 False 3 True dtype: bool
>>> idx = pd.date_range("2020年10月30日", periods=4, freq="BYS") >>> idx DatetimeIndex(['2021年01月01日', '2022年01月03日', '2023年01月02日', '2024年01月01日'], dtype='datetime64[ns]', freq='BYS-JAN')
>>> idx.is_year_start array([ True, True, True, True])