pandas.Period.month#
- Period.month#
Return the month this Period falls on.
Months are numbered from 1 (January) through 12 (December).
- Returns:
- int
See also
period.weekGet the week of the year on the given Period.
Period.yearReturn the year this Period falls on.
Period.dayReturn the day of the month this Period falls on.
Period.start_timeGet the Timestamp for the start of the period.
Period.end_timeGet 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.Examples
Create a Period object for January 2022 and get the month:
>>> period = pd.Period('2022-01', 'M') >>> period.month 1
A yearly period uses its last month:
>>> period = pd.Period('2022', 'Y') >>> period.month 12
Create a Period object with a specified frequency but an incomplete date string:
>>> period = pd.Period('2022', 'M') >>> period.month 1
Handle a case where the Period object is empty, which results in NaN:
>>> period = pd.Period('nan', 'M') >>> period.month nan