Skip to content
Advertisement

Get the index of a datatime in a dataframe pandas

for row in data['column_name']: if row.date() < datetime.today().date(): print(row,????)

I was not able to get the index of a datatime of a specific column in a dataframe. I used this code and i want to return with the row the index of the row. Could anyone help me please?

Advertisement

Answer

You can try with something as follows

df.index[df['column_name'].dt.date < pd.Timestamp('now').date()].tolist()
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement