compare pandas Timestamp to datetime

Viewed 160

I have a time column in a pandas data frame that looks like this

df.time[df.last_valid_index()]

Timestamp('2022-03-31 08:26:00')

I would like to do a simple operation like

start = time(9, 26, 00).strftime("%H:%M:%S")

start <= df.time[df.last_valid_index()]

but I get the following errors

TypeError: '>' not supported between instances of 'Timestamp' and 'str'

how do I make the pandas Timestamp compatible with time object such that I can compare them?

1 Answers

You need compare datetimes, not strings generate strftime method:

start = pd.to_datetime('09:26:00')
print (start)
2022-03-31 09:26:00
Related