【发布时间】:2021-11-10 15:46:23
【问题描述】:
如何使用 TimedeltaIndex 向 Panda Dataframe 添加偏移量?
dfN.index
输出:
TimedeltaIndex([ '00:00:00', '00:00:00.100000', '00:00:00.200000',
'00:00:00.300000', '00:00:00.400000', '00:00:00.500000',
'00:00:00.600000', '00:00:00.700000', '00:00:00.800000',
'00:00:00.900000',
...
'01:56:26.700000', '01:56:26.800000', '01:56:26.900000',
'01:56:27', '01:56:27.100000', '01:56:27.200000',
'01:56:27.300000', '01:56:27.400000', '01:56:27.500000',
'01:56:27.600000'],
dtype='timedelta64[ns]', name='timestamps', length=69877, freq='100L')
这不起作用:
dfN.index += Offset #Offset = 100
输出
TypeError: Addition/subtraction of integers and integer-arrays with TimedeltaArray is no longer supported. Instead of adding/subtracting `n`, use `n * obj.freq`
在这种情况下,数据每 100 毫秒间隔一次。我想添加和偏移 500 毫秒。
【问题讨论】:
标签: python pandas datetime offset timedelta