I have a csv file with data and a datetime stamp, and I am trying to correctly format the datetime so that I can resample the data.
I have a csv that I have imported of the format:
DryBulbTemperature
LocalTime
2023-01-01 00:00:00-07:00 -4.0
2023-01-01 01:00:00-07:00 -2.0
2023-01-01 02:00:00-07:00 -4.0
2023-01-01 03:00:00-07:00 -4.0
2023-01-01 04:00:00-07:00 -6.0
[9995 rows x 1 columns]
I have already run:
data['LocalTime'] = pd.to_datetime(data['LocalTime'])
data.set_index('LocalTime', inplace=True)
data.index = pd.to_datetime(data.index)
(intentionally redundant, just to check)
and confirmed that the values in the index are timestamps
data.index[999] Timestamp('2023-02-06 00:00:00-0700', tz='UTC-07:00')
But then later when trying to resample:
data['DryBulbTemperature'].resample('D').mean()
I get this error:
TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'Index'
I’ve been through several other posts and example, and is seems like this should work, so any help is appreciated.
user24821909 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.