pandas.DatetimeIndex.inferred_freq#
- DatetimeIndex.inferred_freq[source]#
Return the inferred frequency of the index.
Deprecated since version 3.1.0: A future version of pandas will return a
BaseOffsetinstead of a string. Usepd.set_option('future.infer_freq_returns_offset', True)to opt in to the future behavior.Attempts to determine the frequency of the index by analyzing the differences between consecutive values using
infer_freq.- Returns:
- str or None
A string representing a frequency generated by
infer_freq. ReturnsNoneif the frequency cannot be inferred.
See also
DatetimeIndex.freqstrReturn the frequency object as a string if it’s set, otherwise
None.
Examples
For
DatetimeIndex:>>> idx = pd.DatetimeIndex(["2018-01-01", "2018-01-03", "2018-01-05"]) >>> idx.inferred_freq '2D'
For
TimedeltaIndex:>>> tdelta_idx = pd.to_timedelta(["0 days", "10 days", "20 days"]) >>> tdelta_idx TimedeltaIndex(['0 days', '10 days', '20 days'], dtype='timedelta64[us]', freq=None) >>> tdelta_idx.inferred_freq '10D'