ValueError: Inferred frequency None from passed values does not conform to passed frequency H

I have a pandas dataframe that I have reindexed to use hourly values. It is a list of weather observations that was a mix of 3-hourly, hourly, and more-than-once-per-hour data. Now I am trying to add some columns to calculate and plot the values I need, but I have been getting the odd error I put as my question. In this code, "winter_months" is a list of tuples of date-time-groups and temperatures.

    # compute 24-hour rolling mean for winter months
    dfw = pd.DataFrame(winter_months, columns = ('date_time','temp'))
    dfw['date_time'] = pd.to_datetime(dfw['date_time'])
    dfw = dfw.set_index('date_time', drop=True).resample('H').mean()
    dfw = dfw.sort_index()
    dfw
    

This returns a lovely dataframe that is just what I wanted:
beginning of the output dataframe with hourly values from 1948 to 2021. The index is now hourly, which is terrific.

    dfw.index
    DatetimeIndex(['1948-02-15 06:00:00', '1948-02-15 07:00:00',
           '1948-02-15 08:00:00', '1948-02-15 09:00:00',
           '1948-02-15 10:00:00', '1948-02-15 11:00:00',
           '1948-02-15 12:00:00', '1948-02-15 13:00:00',
           '1948-02-15 14:00:00', '1948-02-15 15:00:00',
           ...
           '2021-03-31 14:00:00', '2021-03-31 15:00:00',
           '2021-03-31 16:00:00', '2021-03-31 17:00:00',
           '2021-03-31 18:00:00', '2021-03-31 19:00:00',
           '2021-03-31 20:00:00', '2021-03-31 21:00:00',
           '2021-03-31 22:00:00', '2021-03-31 23:00:00'],
          dtype='datetime64[ns]', name='date_time', length=641010, freq='H')

The problem comes up when I try to create a new date index so that the low temperature data can be grouped within a continuous period of Oct-Mar.

    dfw['pretend_winter'] = dfw.index + pd.DateOffset(months=9)


  

ValueError: Inferred frequency None from passed values does not conform to passed frequency H

I have looked at ValueError: Inferred frequency None from passed values does not conform to passed frequency MS and Pandas not able to infer time series frequency, despite proper formatting? and tried the solutions posted there with no luck.

What am I missing?

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum