@@ -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)
@@ -2000,11 +2038,44 @@ cdef class _Period(PeriodMixin):
2000
2038
"""
2001
2039
Return the year this Period falls on.
2002
2040
2041
+ Returns
2042
+ -------
2043
+ int
2044
+
2045
+ See Also
2046
+ --------
2047
+ period.month : Get the month of the year for the given Period.
2048
+ period.day : Return the day of the month the Period falls on.
2049
+
2050
+ Notes
2051
+ -----
2052
+ The year is based on the `ordinal` and `base` attributes of the Period.
2053
+
2003
2054
Examples
2004
2055
--------
2005
- >>> period = pd.Period(' 2022-01' , ' M' )
2056
+ Create a Period object for January 2023 and get the year:
2057
+
2058
+ >>> period = pd.Period(' 2023-01' , ' M' )
2006
2059
>>> period.year
2007
- 2022
2060
+ 2023
2061
+
2062
+ Create a Period object for 01 January 2023 and get the year:
2063
+
2064
+ >>> period = pd.Period(' 2023' , ' D' )
2065
+ >>> period.year
2066
+ 2023
2067
+
2068
+ Get the year for a period representing a quarter:
2069
+
2070
+ >>> period = pd.Period(' 2023Q2' , ' Q' )
2071
+ >>> period.year
2072
+ 2023
2073
+
2074
+ Handle a case where the Period object is empty , which results in `NaN`:
2075
+
2076
+ >>> period = pd.Period(' nan' , ' M' )
2077
+ >>> period.year
2078
+ nan
2008
2079
"""
2009
2080
base = self ._dtype._dtype_code
2010
2081
return pyear(self.ordinal , base )
@@ -2014,11 +2085,45 @@ cdef class _Period(PeriodMixin):
2014
2085
"""
2015
2086
Return the month this Period falls on.
2016
2087
2088
+ Returns
2089
+ -------
2090
+ int
2091
+
2092
+ See Also
2093
+ --------
2094
+ period.week : Get the week of the year on the given Period.
2095
+ Period.year : Return the year this Period falls on.
2096
+ Period.day : Return the day of the month this Period falls on.
2097
+
2098
+ Notes
2099
+ -----
2100
+ The month is based on the `ordinal` and `base` attributes of the Period.
2101
+
2017
2102
Examples
2018
2103
--------
2104
+ Create a Period object for January 2022 and get the month:
2105
+
2019
2106
>>> period = pd.Period(' 2022-01' , ' M' )
2020
2107
>>> period.month
2021
2108
1
2109
+
2110
+ Period object with no specified frequency , resulting in a default frequency:
2111
+
2112
+ >>> period = pd.Period(' 2022' , ' Y' )
2113
+ >>> period.month
2114
+ 12
2115
+
2116
+ Create a Period object with a specified frequency but an incomplete date string:
2117
+
2118
+ >>> period = pd.Period(' 2022' , ' M' )
2119
+ >>> period.month
2120
+ 1
2121
+
2122
+ Handle a case where the Period object is empty , which results in `NaN`:
2123
+
2124
+ >>> period = pd.Period(' nan' , ' M' )
2125
+ >>> period.month
2126
+ nan
2022
2127
"""
2023
2128
base = self ._dtype._dtype_code
2024
2129
return pmonth(self.ordinal , base )
0 commit comments