pandas.Period.asfreq — pandas 3.0.0.dev0+2100.gf496acffcc documentation (original) (raw)

Period.asfreq(freq, how='E')#

Convert Period to desired frequency, at the start or end of the interval.

Parameters:

freqstr, DateOffset

The target frequency to convert the Period object to. If a string is provided, it must be a valid period alias.

how{‘E’, ‘S’, ‘end’, ‘start’}, default ‘end’

Specifies whether to align the period to the start or end of the interval: - ‘E’ or ‘end’: Align to the end of the interval. - ‘S’ or ‘start’: Align to the start of the interval.

Returns:

PeriodPeriod object with the specified frequency, aligned to the parameter.

Examples

Convert a daily period to an hourly period, aligning to the end of the day:

period = pd.Period('2023-01-01', freq='D') period.asfreq('h') Period('2023-01-01 23:00', 'h')

Convert a monthly period to a daily period, aligning to the start of the month:

period = pd.Period('2023-01', freq='M') period.asfreq('D', how='start') Period('2023-01-01', 'D')

Convert a yearly period to a monthly period, aligning to the last month:

period = pd.Period('2023', freq='Y') period.asfreq('M', how='end') Period('2023-12', 'M')

Convert a monthly period to an hourly period, aligning to the first day of the month:

period = pd.Period('2023-01', freq='M') period.asfreq('h', how='start') Period('2023-01-01 00:00', 'H')

Convert a weekly period to a daily period, aligning to the last day of the week:

period = pd.Period('2023-08-01', freq='W') period.asfreq('D', how='end') Period('2023-08-04', 'D')