Search code examples
datetimeindexingtimeseriesfrequency

How to set datetime index frequency in workdays time series pandas


When dealing with a time series pandas dataframe with date index (working days from Monday to Friday), I tried to change the index frequency from None to 'D' for daily time series. I got the following error: ValueError: Inferred frequency None from passed values does not conform to passed frequency D

This is how my dataframe looks like: enter image description here

And this is my code for setting the frequency:

df.index.freq = 'D'

Solution

  • df = df.asfreq('B')

    'B' stands for business day frequency (Mon-Fri).