Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.
Pandas PeriodIndex.freqstr attribute return the frequency object as a string if its set, otherwise the function return None for the given PeriodIndex object.
Syntax : PeriodIndex.freqstr
Parameters : None
Return : frequency as a string
Â
Example #1: Use PeriodIndex.freqstr attribute to find the time series frequency applied on the given PeriodIndex object.Â
Python3
# importing pandas as pdimport pandas as pdÂ
# Create the PeriodIndex objectpidx = pd.PeriodIndex(start ='2005-12-21 08:45 ', Â Â Â Â Â Â Â Â Â Â Â Â Â Â end ='2005-12-21 11:55', freq ='H')Â
# Print the PeriodIndex objectprint(pidx) |
Output :Â
Now we will use the PeriodIndex.freqstr attribute to find the time series frequency of the given object.
Python3
# return the frequency object as a stringpidx.freqstr |
Output :Â
As we can see in the output, the PeriodIndex.freqstr attribute has returned ‘H’ indicating that hourly frequency is applied on the given PeriodIndex object.Â
 Â
Example #2: Use PeriodIndex.freqstr attribute to find the time series frequency of the given PeriodIndex object.
Python3
# importing pandas as pdimport pandas as pdÂ
# Create the PeriodIndex objectpidx = pd.PeriodIndex(start ='2011-02-1 ', Â Â Â Â Â Â Â Â Â Â Â Â Â end ='2011-08-14', freq ='M')Â
# Print the PeriodIndex objectprint(pidx) |
Output :Â
Now we will use the PeriodIndex.freqstr attribute to find the time series frequency of the given object.
Python3
# return the frequency object as a stringpidx.freqstr |
Output :Â
As we can see in the output, the PeriodIndex.freqstr attribute has returned ‘M’ indicating that monthly frequency is applied on the given PeriodIndex object.
Â

