pandas.tseries.offsets.YearBegin#

class pandas.tseries.offsets.YearBegin#

DateOffset increments between calendar year begin dates.

YearBegin goes to the next date which is the start of the year.

Parameters:
nint, default 1

The number of years represented.

normalizebool, default False

Normalize start/end dates to midnight before generating date range.

monthint, default 1

A specific integer for the month of the year.

Attributes

month

Return the month of the year on which this offset applies.

See also

DateOffset

Standard kind of date increment.

Examples

>>> ts = pd.Timestamp(2022, 12, 1)
>>> ts + pd.offsets.YearBegin()
Timestamp('2023-01-01 00:00:00')
>>> ts = pd.Timestamp(2023, 1, 1)
>>> ts + pd.offsets.YearBegin()
Timestamp('2024-01-01 00:00:00')
>>> ts = pd.Timestamp(2022, 1, 1)
>>> ts + pd.offsets.YearBegin(month=2)
Timestamp('2022-02-01 00:00:00')

If you want to get the start of the current year:

>>> ts = pd.Timestamp(2023, 1, 1)
>>> pd.offsets.YearBegin().rollback(ts)
Timestamp('2023-01-01 00:00:00')