0

I have a pandas datetime index idx with with minute frequency, I also have a list(or set) of dates list_of_dates. I would like to return a boolean array of the same size of idx with the condition that the dates of datetime index belong is in the list_of_dates. Is it possible to do it in a vectorized way (i.e. not using a for loop)?

3

1 Answer 1

1

Since you're trying to compare only the dates, you could remove the times and compare like so:

>>> df.index.normalize().isin(list_of_dates)

Or:

>>> df.index.floor('D').isin(list_of_dates)
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.