pandas.infer_freq#
- pandas.infer_freq(index)[source]#
Infer the most likely frequency given the input index.
This method attempts to deduce the most probable frequency (e.g., ‘D’ for daily,‘H’ for hourly) from a sequence of datetime-like objects. It is particularly usefulwhen the frequency of a time series is not explicitly set or known but can beinferred from its values.
- Parameters:
- indexDatetimeIndex, TimedeltaIndex, Series or array-like
If passed a Series will use the values of the series (NOT THE INDEX).
- Returns:
- str or None
None if no discernible frequency.
- Raises:
- TypeError
If the index is not datetime-like.
- ValueError
If there are fewer than three values.
See also
date_rangeReturn a fixed frequency DatetimeIndex.
timedelta_rangeReturn a fixed frequency TimedeltaIndex with day as the default.
period_rangeReturn a fixed frequency PeriodIndex.
DatetimeIndex.freqReturn the frequency object if it is set, otherwise None.
Examples
>>>idx=pd.date_range(start="2020/12/01",end="2020/12/30",periods=30)>>>pd.infer_freq(idx)'D'
On this page