@@ -1913,20 +1913,58 @@ cdef class _Period(PeriodMixin):
1913
1913
Parameters
1914
1914
----------
1915
1915
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
+
1918
1920
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.
1920
1924
1921
1925
Returns
1922
1926
-------
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.
1924
1935
1925
1936
Examples
1926
1937
--------
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' )
1928
1941
>>> period.asfreq('h')
1929
1942
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')
1930
1968
"""
1931
1969
freq = self ._maybe_convert_freq(freq)
1932
1970
how = validate_end_alias(how)
@@ -2014,11 +2052,45 @@ cdef class _Period(PeriodMixin):
2014
2052
"""
2015
2053
Return the month this Period falls on.
2016
2054
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
+
2017
2069
Examples
2018
2070
--------
2071
+ Create a Period object for January 2022 and get the month:
2072
+
2019
2073
>>> period = pd.Period(' 2022-01' , ' M' )
2020
2074
>>> period.month
2021
2075
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
2022
2094
"""
2023
2095
base = self ._dtype._dtype_code
2024
2096
return pmonth(self.ordinal , base )
0 commit comments