2

I have the following python code:

current_ts = datetime.datetime.now()
current_date = current_ts.date()

new_df = df[df.index >= current_date]

The df.index is a datetime64[ns] and when I run the code I get Invalid comparison between dtype=datetime64[ns] and date.

How can I convert the index into a date so that the comparison works?

1 Answer 1

1

Pandas datetime64[ns] doesn't compare directly to datetime.date. You need to convert:

df[df.index >= pd.Timestamp(current_date)]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.