I have this dataset:
Data A
2015-01-01 00:15:00 0
2015-01-01 00:30:00 1
2015-01-01 00:45:00 2
2015-01-01 01:00:00 3
2015-01-01 01:15:00 4
I'm trying to set the data to a frequency. I've got pandas to recognize the DateTime to the index.
DatetimeIndex(['2015-01-01 00:00:00', '2015-01-01 00:15:00',
'2015-01-01 00:30:00', '2015-01-01 00:45:00',
'2015-01-01 01:00:00', '2015-01-01 01:15:00',
'2015-01-01 01:30:00', '2015-01-01 01:45:00',
'2015-01-01 02:00:00', '2015-01-01 02:15:00',
...
'2016-09-30 21:30:00', '2016-09-30 21:45:00',
'2016-09-30 22:00:00', '2016-09-30 22:15:00',
'2016-09-30 22:30:00', '2016-09-30 22:45:00',
'2016-09-30 23:00:00', '2016-09-30 23:15:00',
'2016-09-30 23:30:00', '2016-09-30 23:45:00'],
dtype='datetime64[ns]', name='Data', length=61340, freq=None)
I've tried doing this
df.asfreq(freq='15M')
But I get the following error
ValueError: cannot reindex from a duplicate axis
CodePudding user response:
You can use DataFrame.resample
with some aggregation function like sum
, mean
, first
:
df.resample('15M').sum()