Open In App

Python | Pandas PeriodIndex.freqstr

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. 




# importing pandas as pd
import pandas as pd
 
# Create the PeriodIndex object
pidx = pd.PeriodIndex(start ='2005-12-21 08:45 ',
              end ='2005-12-21 11:55', freq ='H')
 
# Print the PeriodIndex object
print(pidx)

Output : 

Now we will use the PeriodIndex.freqstr attribute to find the time series frequency of the given object.




# return the frequency object as a string
pidx.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.




# importing pandas as pd
import pandas as pd
 
# Create the PeriodIndex object
pidx = pd.PeriodIndex(start ='2011-02-1 ',
             end ='2011-08-14', freq ='M')
 
# Print the PeriodIndex object
print(pidx)

Output : 

Now we will use the PeriodIndex.freqstr attribute to find the time series frequency of the given object.




# return the frequency object as a string
pidx.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.
 


Article Tags :