0

I'm trying to filter a dataframe based on the following conditions, if end_date is Nan OR if the end_date is greater than the current date. How exactly can I do this? I'm using the following code, I am aware the | and & operators are series operators.

end_series = ((~df.end_date.notna()) | (df.end_date > datetime.datetime.utcnow().date()))
new_df = df[(df.column1 > 0)  &  end_series].copy()
0

1 Answer 1

2

You can do:

current_date = pd.to_datetime("today").date()
new_df = df.query("end_date.isna() or (end_date > @current_date) and column1 > 0")
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.