Open In App

Python | Pandas PeriodIndex.freq

Last Updated : 20 Aug, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

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.freq attribute returns the time series frequency that is applied on the given PeriodIndex object.

Syntax : PeriodIndex.freq
Parameters : None
Return : Index 
 

Example #1: Use PeriodIndex.freq attribute to find the time series frequency of the given PeriodIndex object. 

Python3




# 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.freq attribute to find the time series frequency of the given object.

Python3




# return the frequency
pidx.freq


Output : 

As we can see in the output, the PeriodIndex.freq attribute has returned ‘Hourly’ frequency. This is the time series frequency that is applied on the given PeriodIndex object.

Example #2: Use PeriodIndex.freq attribute to find the time series frequency of the given PeriodIndex object. 

Python3




# 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.freq attribute to find the time series frequency of the given object.

Python3




# return the frequency
pidx.freq


Output : 
 

As we can see in the output, the PeriodIndex.freq attribute has returned the ‘Monthly’ frequency. This is the time series frequency that is applied on the given PeriodIndex object.
 



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads