How can I add an offset to an Panda Dataframe with a TimedeltaIndex?
dfN.index
Outputs:
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')
This does not work:
dfN.index = Offset #Offset = 100
Outputs
TypeError: Addition/subtraction of integers and integer-arrays with TimedeltaArray is no longer supported. Instead of adding/subtracting `n`, use `n * obj.freq`
In this case the data is spaced in every 100miliseconds. And I would like to add and offset of 500miliseconds.
CodePudding user response:
The variable Offset
can't be an integer. You need to create a Timedelta object to add it. Try this:
dfN.index = pd.Timedelta(100, unit=‘milliseconds’) #This will add 100 miliseconds
or
dfN.index = pd.Timedelta(milliseconds = 100)