pandas filter row null and

I have a pandas dataframe as

my_df = pd.DataFrame({"months":[0,1,2,3,4,5], "value":[12,123,np.nan,234,345,456]})

I wanted to check for specific month value is not null or 0

I tried to do following way but does not work

if my_df[(my_df["months"].isin([0, 1, 3])) & (my_df["value"].isnull() | my_df["value"] == 0)].empty:

this still gives output as True

Read more here:

Content Attribution

This content was originally published by Rachana Mahajan at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: