0

I am trying to filter out some rows by a condition value:

_a = my_df[my_df['A'] < 0.01]

But it also filters out rows with empty values. What I want is to filter rows that satisfy that condition and also keep empty values.

I am trying this but returns 0 rows. What I am doing wrong?

_a = my_df[pd.isnull(my_df['A']) | my_df['A'] < 0.01]

Thank you in advance!

1 Answer 1

2

There are missing parentheses for second condition, because priority of operators:

_a = my_df[pd.isnull(my_df['A']) | (my_df['A'] < 0.01)]

Or use Series.lt:

_a = my_df[pd.isnull(my_df['A']) | my_df['A'].lt(0.01)]
Sign up to request clarification or add additional context in comments.

2 Comments

oh my... thank you! How is this possible? Pandas is unable to interpret the operands of the conditions without parentheses?
@P.Solar - If chain condition then not.

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.