I have a dataframe that includes a column of datetimes, past and future. Is there a way to find the index of the most recent datetime?
I can not assume that each datetime is unique, nor that they are in order.
In the event that the most recent datetime is not unique, all the relevant indeces should be returned.
import pandas as pd
from datetime import datetime as dt
df = pd.read_excel('file.xlsx')
# Create datetime column
df['datetime'] = pd.to_datetime(df['Date'].astype(str) + ' ' + df['Time'].astype(str))
print(df['datetime'])
Out[1]:
0 2021-02-13 09:00:00
1 2021-02-13 11:00:00
2 2021-02-13 12:00:00
3 2021-02-13 15:00:00
4 2021-02-13 18:00:00
5 2021-02-13 16:45:00
6 2021-02-13 19:00:00
7 2021-02-13 19:00:00
8 2021-02-13 20:30:00
9 2021-02-14 01:30:00
Name: datetime, dtype: datetime64[ns]