@@ -1913,20 +1913,58 @@ cdef class _Period(PeriodMixin):
19131913 Parameters
19141914 ----------
19151915 freq : str , BaseOffset
1916- The desired frequency. If passing a `str`, it needs to be a
1917- valid :ref:`period alias <timeseries.period_aliases>`.
1916+ The target frequency to convert the Period object to.
1917+ If a string is provided ,
1918+ it must be a valid :ref:`period alias <timeseries.period_aliases>`.
1919+
19181920 how : {'E', 'S', 'end', 'start'}, default 'end'
1919- Start or end of the timespan.
1921+ Specifies whether to align the period to the start or end of the interval:
1922+ - 'E' or 'end': Align to the end of the interval.
1923+ - 'S' or 'start': Align to the start of the interval.
19201924
19211925 Returns
19221926 -------
1923- resampled : Period
1927+ Period : Period object with the specified frequency , aligned to the parameter.
1928+
1929+ See Also
1930+ --------
1931+ Period.end_time : Return the end Timestamp.
1932+ Period.start_time : Return the start Timestamp.
1933+ Period.dayofyear : Return the day of the year.
1934+ Period.dayofweek : Return the day of the week.
19241935
19251936 Examples
19261937 --------
1927- >>> period = pd.Period(' 2023-1-1' , freq = ' D' )
1938+ Convert a daily period to an hourly period , aligning to the end of the day:
1939+
1940+ >>> period = pd.Period(' 2023-01-01' , freq = ' D' )
19281941 >>> period.asfreq('h')
19291942 Period('2023-01-01 23:00', 'h')
1943+
1944+ Convert a monthly period to a daily period , aligning to the start of the month:
1945+
1946+ >>> period = pd.Period(' 2023-01' , freq = ' M' )
1947+ >>> period.asfreq('D', how = ' start' )
1948+ Period('2023-01-01', 'D')
1949+
1950+ Convert a yearly period to a monthly period , aligning to the last month:
1951+
1952+ >>> period = pd.Period(' 2023' , freq = ' Y' )
1953+ >>> period.asfreq('M', how = ' end' )
1954+ Period('2023-12', 'M')
1955+
1956+ Convert a monthly period to an hourly period ,
1957+ aligning to the first day of the month:
1958+
1959+ >>> period = pd.Period(' 2023-01' , freq = ' M' )
1960+ >>> period.asfreq('h', how = ' start' )
1961+ Period('2023-01-01 00:00', 'H')
1962+
1963+ Convert a weekly period to a daily period , aligning to the last day of the week:
1964+
1965+ >>> period = pd.Period(' 2023-08-01' , freq = ' W' )
1966+ >>> period.asfreq('D', how = ' end' )
1967+ Period('2023-08-04', 'D')
19301968 """
19311969 freq = self ._maybe_convert_freq(freq)
19321970 how = validate_end_alias(how)
@@ -2014,11 +2052,45 @@ cdef class _Period(PeriodMixin):
20142052 """
20152053 Return the month this Period falls on.
20162054
2055+ Returns
2056+ -------
2057+ int
2058+
2059+ See Also
2060+ --------
2061+ period.week : Get the week of the year on the given Period.
2062+ Period.year : Return the year this Period falls on.
2063+ Period.day : Return the day of the month this Period falls on.
2064+
2065+ Notes
2066+ -----
2067+ The month is based on the `ordinal` and `base` attributes of the Period.
2068+
20172069 Examples
20182070 --------
2071+ Create a Period object for January 2022 and get the month:
2072+
20192073 >>> period = pd.Period(' 2022-01' , ' M' )
20202074 >>> period.month
20212075 1
2076+
2077+ Period object with no specified frequency , resulting in a default frequency:
2078+
2079+ >>> period = pd.Period(' 2022' , ' Y' )
2080+ >>> period.month
2081+ 12
2082+
2083+ Create a Period object with a specified frequency but an incomplete date string:
2084+
2085+ >>> period = pd.Period(' 2022' , ' M' )
2086+ >>> period.month
2087+ 1
2088+
2089+ Handle a case where the Period object is empty , which results in `NaN`:
2090+
2091+ >>> period = pd.Period(' nan' , ' M' )
2092+ >>> period.month
2093+ nan
20222094 """
20232095 base = self ._dtype._dtype_code
20242096 return pmonth(self.ordinal , base )
0 commit comments