Pandas DatetimeIndex property inferred_freq in Python
The Pandas DatetimeIndex property inferred_freq used to retrieve a frequency string that represents a frequency generated by infer_freq. It returns None, if it can't autodetect the frequency.
Syntax
 1 DatetimeIndex.inferred_freq
inferred_freq property
 1 import pandas as pd
 2 
 3 dIndex = pd.date_range('2022-12-30', periods = 3, freq = 'y')
 4 
 5 print('The DatetimeIndex object :')
 6 print(dIndex)
 7 
 8 res = dIndex.inferred_freq
 9 print('The inferred frequency is :')
 10 print(res)
In the above example, a DatetimeIndex object is created by calling a date_range() function that returns a DatetimeIndex with frequency. A inferred_freq property is access that returns string representation of inferred frequency. The result is assign to the variable that will be printed on console.
Output
 1 The DatetimeIndex object :
 2 DatetimeIndex(['2022-12-31', '2023-12-31', '2024-12-31'], 
 3                    dtype='datetime64[ns]', freq='A-DEC')
 4 
 5 The inferred frequency is :
 6 A-DEC

Example 2

Example 2
 1 import pandas as pd
 2 
 3 dIndex = pd.date_range('2022-01-01 12:30:32',
 4 	periods = 3, freq = 'YE', tz = 'Europe/Berlin')
 5 
 6 print('The DatetimeIndex object :')
 7 print(dIndex)
 8 
 9 res = dIndex.inferred_freq
 10 print('The inferred frequency is :')
 11 print(res)
In the above example, a DatetimeIndex object is created by calling a date_range() function that returns a DatetimeIndex with frequency. A inferred_freq property is access that returns string representation of inferred frequency. The result is assign to the variable that will be print.
Output
 1 The DatetimeIndex object :
 2 DatetimeIndex(['2022-12-31 12:30:32+01:00', '2023-12-31 12:30:32+01:00',
 3                '2024-12-31 12:30:32+01:00'],
 4               dtype='datetime64[ns, Europe/Berlin]', freq='YE-DEC')
 5 
 6 The inferred frequency is :
 7 YE-DEC
Privacy Policy
Terms of Service
Disclaimer
Contact us
About us