@@ -1913,20 +1913,57 @@ 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. If a string is provided ,
1917
+ it must be a valid :ref:`period alias <timeseries.period_aliases>`.
1918
+
1918
1919
how : {'E', 'S', 'end', 'start'}, default 'end'
1919
- Start or end of the timespan.
1920
+ Specifies whether to align the converted period to the start or end of the interval:
1921
+ - 'E' or 'end': Align to the end of the interval.
1922
+ - 'S' or 'start': Align to the start of the interval.
1920
1923
1921
1924
Returns
1922
1925
-------
1923
- resampled : Period
1926
+ Resampled Period : A new Period object with the specified frequency , aligned according to the `how` parameter.
1927
+
1928
+ See Also
1929
+ --------
1930
+ Period.end_time : Return the end Timestamp.
1931
+ Period.start_time : Return the start Timestamp.
1932
+ Period.dayofyear : Return the day of the year.
1933
+ Period.dayofweek : Return the day of the week.
1924
1934
1925
1935
Examples
1926
1936
--------
1927
- >>> period = pd.Period(' 2023-1-1' , freq = ' D' )
1937
+ Convert a daily period to an hourly period , aligning to the end of the day:
1938
+
1939
+ >>> period = pd.Period(' 2023-01-01' , freq = ' D' )
1928
1940
>>> period.asfreq('h')
1929
1941
Period('2023-01-01 23:00', 'h')
1942
+
1943
+ Convert a monthly period to a daily period , aligning to the start of the month:
1944
+
1945
+ >>> period = pd.Period(' 2023-01' , freq = ' M' )
1946
+ >>> period.asfreq('D', how = ' start' )
1947
+ Period('2023-01-01', 'D')
1948
+
1949
+ Convert a yearly period to a monthly period , aligning to the last month of the year:
1950
+
1951
+ >>> period = pd.Period(' 2023' , freq = ' Y' )
1952
+ >>> period.asfreq('M', how = ' end' )
1953
+ Period('2023-12', 'M')
1954
+
1955
+ Convert a monthly period to an hourly period , aligning to the start of the first day of the month:
1956
+
1957
+ >>> period = pd.Period(' 2023-01' , freq = ' M' )
1958
+ >>> period.asfreq('h', how = ' start' )
1959
+ Period('2023-01-01 00:00', 'H')
1960
+
1961
+ Convert a weekly period to a daily period , aligning to the last day of the week:
1962
+
1963
+ >>> period = pd.Period(' 2023-08-01' , freq = ' W' )
1964
+ >>> period.asfreq('D', how = ' end' )
1965
+ Period('2023-08-04', 'D')
1966
+
1930
1967
"""
1931
1968
freq = self ._maybe_convert_freq(freq)
1932
1969
how = validate_end_alias(how)
0 commit comments