pandas.PeriodIndex.asfreq#
- PeriodIndex.asfreq(freq=None, how='E')[source]#
Convert the PeriodIndex to the specified frequency freq.
Equivalent to applying
pandas.Period.asfreq()with the given arguments to eachPeriodin this PeriodIndex.- Parameters:
- freqstr
A frequency.
- how{‘end’, ‘start’, ‘e’, ‘s’}, default ‘end’
Whether the elements should be aligned to the end or start of each period, e.g. January 31st vs. January 1st. Case-insensitive.
- Returns:
- PeriodIndex
The transformed PeriodIndex with the new frequency.
See also
arrays.PeriodArray.asfreqConvert each Period in a PeriodArray to the given frequency.
Period.asfreqConvert a
Periodobject to the given frequency.
Examples
>>> pidx = pd.period_range("2010-01-01", "2015-01-01", freq="Y") >>> pidx PeriodIndex(['2010', '2011', '2012', '2013', '2014', '2015'], dtype='period[Y-DEC]')
>>> pidx.asfreq("M") PeriodIndex(['2010-12', '2011-12', '2012-12', '2013-12', '2014-12', '2015-12'], dtype='period[M]')
>>> pidx.asfreq("M", how="S") PeriodIndex(['2010-01', '2011-01', '2012-01', '2013-01', '2014-01', '2015-01'], dtype='period[M]')