+

Python | Pandas PeriodIndex.freq

PeriodIndex.freq Pandas PeriodIndex.freq returns the time series frequency that is applied to a given PeriodIndex object.

Syntax: PeriodIndex.freq

Parameters: None

Return : Index

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

Output:

We will now use the PeriodIndex.freq attribute to find the frequency of the given object`s time series.

# import pandas as pd

import pandas as pd

 
# Create PeriodIndex object

pidx = pd.PeriodIndex (start = `2005-12-21 08:45`

end = `2005-12-21 11: 55` , freq = `H` )

  
# Print PeriodIndex object

print (pidx)

# return frequency
pidx.freq

Output:

As we can see in the output, the PeriodIndex.freq attribute returned the frequency in PeriodIndex.freq . This is the time period that applies to this PeriodIndex object.

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

# import pandas as pd

import pandas as pd

 
# Create PeriodIndex object

pidx = pd.PeriodIndex (start = `2011-02-1`

end = `2011-08-14` , freq `M` )

  
# Print PeriodIndex object

print (pidx)

Output:

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

# return frequency
pidx.freq

Output:

As we can see in the output, the PeriodIndex.freq attribute returned the frequency “ Monthly". This is the frequency of the time series that is applied to this PeriodIndex.

Get Solution for free from DataCamp guru