Suppose you have the following df
:
End Date Close Price
2022-05-12 09:59:59.999000 0.00711
2022-05-12 10:14:59.999000 0.00704
2022-05-12 10:29:59.999000 0.00712
The column ['End Date']
was set as the index column of thedf
When executing:
In [1]: df.index[0]
You get:
Out[1]: Timestamp('2022-05-12 09:59:59.999000')
How could you subtract 15 minutes from the value df.index[0]
in order to get the following output?
Out[2]: Timestamp('2022-05-12 09:44:59.999000')
Good day,
The easiest way to do this is using
pandas.Timedelta
.I created a
dataframe
test in the file "sample2.csv" using the data from your question and set the column "End Date" as index and it is of typedatetime
This returns:
The only thing to do is
Printing again the
dataframe
we get:Solved, it was very simple actually:
Source: https://thispointer.com/how-to-add-minutes-to-datetime-in-python/