DatetimeIndex.inferred_freq in Pandas

In this tutorial, we are going to learn about the DatetimeIndex.inferred_freq method in Pandas using python along with a few examples.

DatetimeIndex.inferred_freq in Pandas

DatetimeIndex.inferred_freq in Pandas

Python is an awesome language for performing data analysis mainly because of the ecosystem of the data-centric Python packages. Python is one of the important packages in Python that lets us import and analyze data at a very feasible level. 

The DatetimeIndex.inferred_freq returns a string with the frequency guess.  We use this method where we are unable to detect the frequency of the DatetimeIndex. For example:

# importing pandas as pd
import pandas as pd

# Create the DatetimeIndex
my_dti = pd.date_range("2021-12-31", periods = 10, freq ='A')

# Print the DatetimeIndex


DatetimeIndex(['2021-12-31', '2022-12-31', '2023-12-31', '2024-12-31',

               '2025-12-31', '2026-12-31', '2027-12-31', '2028-12-31',

               '2029-12-31', '2030-12-31'],

              dtype='datetime64[ns]', freq='A-DEC')

Now let’s Use the DatetimeIndex.inferred_freq function to detect the frequency of the DatetimeIndex object.