pandas.Period.year#

Period.year#

Return the year this Period falls on.

The year is derived from the internal representation of the Period based on its ordinal value and frequency.

Returns:
int

See also

period.month

Get the month of the year for the given Period.

period.day

Return the day of the month the Period falls on.

Period.qyear

Fiscal year the Period lies in according to its starting-quarter.

Period.start_time

Get the Timestamp for the start of the period.

Period.end_time

Get the Timestamp for the end of the period.

Notes

The value comes from the last day of the first unit of the period’s frequency, so a "2M" period uses the last day of its first month. For fiscal quarterly frequencies such as "Q-MAR", this can differ from the year shown in the period; see qyear.

Examples

Create a Period object for January 2023 and get the year:

>>> period = pd.Period('2023-01', 'M')
>>> period.year
2023

Create a Period object for 01 January 2023 and get the year:

>>> period = pd.Period('2023', 'D')
>>> period.year
2023

Get the year for a period representing a quarter:

>>> period = pd.Period('2023Q2', 'Q')
>>> period.year
2023

Handle a case where the Period object is empty, which results in NaN:

>>> period = pd.Period('nan', 'M')
>>> period.year
nan