Comparison between datetime and datetime64[ns] in pandas

You can use

pd.Timestamp('today')

or

pd.to_datetime('today')

But both of those give the date and time for 'now'.


Try this instead:

pd.Timestamp('today').floor('D')

or

pd.to_datetime('today').floor('D')

You could have also passed the datetime object to pandas.to_datetime but I like the other option mroe.

pd.to_datetime(datetime.datetime.today()).floor('D')

Pandas also has a Timedelta object

pd.Timestamp('now').floor('D') + pd.Timedelta(-3, unit='D')

Or you can use the offsets module

pd.Timestamp('now').floor('D') + pd.offsets.Day(-3)

To check for membership, try one of these

cur_date in df['date'].tolist()

Or

df['date'].eq(cur_date).any()

For anyone who also stumbled across this when comparing a dataframe date to a variable date, and this did not exactly answer your question; you can use the code below.

Instead of:

self.df["date"] = pd.to_datetime(self.df["date"])

You can import datetime and then add .dt.date to the end like:

self.df["date"] = pd.to_datetime(self.df["date"]).dt.date