1

I am trying to convert a timestamp to a datetime to do some date comparisons but I cant seem to get it to work.

date = pd.to_datetime(df.at[i,"Date"])

however when I do date comparisons using the > and < operators its not always working. From what I have researched dates need to be set to datetime objects not timestamps.

but when i check the type of my date variable it still shows as being a timestamp.

print(type(date))

<class 'pandas._libs.tslibs.timestamps.Timestamp'>

How can I convert this to a datetime object/variable ?

Samir112
  • 125
  • 1
  • 12

1 Answers1

2

You can use Timestamp.to_pydatetime

$ type(date.to_pydatetime())

<class 'datetime.datetime'>
Ynjxsjmh
  • 28,441
  • 6
  • 34
  • 52