@@ -2011,15 +2011,61 @@ cdef class _Period(PeriodMixin):
2011
2011
2012
2012
@property
2013
2013
def month(self ) -> int:
2014
- """
2015
- Return the month this Period falls on.
2014
+ """
2015
+ Return the month this Period falls on.
2016
+
2017
+ Parameters
2018
+ ----------
2019
+ None
2020
+
2021
+ Returns
2022
+ -------
2023
+ int : The month number of the Period.
2024
+
2025
+ See Also
2026
+ --------
2027
+ period.week : Get the week of the year on the given Period.
2028
+ Period.year : Return the year this Period falls on.
2029
+ Period.day : Return the day of the month this Period falls on.
2030
+
2031
+
2032
+ Examples
2033
+ --------
2034
+ Create a Period object for January 2022 and get the month:
2035
+
2036
+ >>> period = pd.Period(' 2022-01' , ' M' )
2037
+ >>> period.month
2038
+ 1
2039
+
2040
+ Create a Period object with no specified frequency , resulting in a default frequency:
2041
+
2042
+ >>> period = pd.Period(' 2022' , ' Y' )
2043
+ >>> period.month
2044
+ 12
2045
+
2046
+ Create a Period object with a specified frequency but an incomplete date string:
2047
+
2048
+ >>> period = pd.Period(' 2022' , ' M' )
2049
+ >>> period.month
2050
+ 1
2051
+
2052
+ Handle a case where the Period object is invalid or empty , which results in `NaN`:
2053
+
2054
+ >>> period = pd.Period(' nan' , ' M' )
2055
+ >>> period.month
2056
+ nan
2057
+
2058
+ Handle a case where the Period object is invalid or empty , which results in `NaN`:
2059
+
2060
+ >>> period = pd.Period(' nan' , ' M' )
2061
+ >>> period.month
2062
+ nan
2063
+
2064
+ Notes
2065
+ -----
2066
+ The month is determined based on the `ordinal` and `base` attributes of the Period.
2067
+ """
2016
2068
2017
- Examples
2018
- --------
2019
- >>> period = pd.Period(' 2022-01' , ' M' )
2020
- >>> period.month
2021
- 1
2022
- """
2023
2069
base = self ._dtype._dtype_code
2024
2070
return pmonth(self.ordinal , base )
2025
2071
0 commit comments