Python | Pandas PeriodIndex.freqstr
Last Updated :
20 Aug, 2021
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
import pandas as pd
pidx = pd.PeriodIndex(start = '2005-12-21 08:45 ' ,
end = '2005-12-21 11:55' , freq = 'H' )
print (pidx)
|
Output :
Now we will use the PeriodIndex.freqstr attribute to find the time series frequency of the given object.
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
import pandas as pd
pidx = pd.PeriodIndex(start = '2011-02-1 ' ,
end = '2011-08-14' , freq = 'M' )
print (pidx)
|
Output :
Now we will use the PeriodIndex.freqstr attribute to find the time series frequency of the given object.
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.
Share your thoughts in the comments
Please Login to comment...