Home > Net >  How to create a mask with 3 conditions and using numbers
How to create a mask with 3 conditions and using numbers

Time:06-14

I have a df and I need to filter this by date, a have 3 columns with year, month and day. I try use:

mask = (df_atleti_cadiz['year']== 2021) | (df_atleti_cadiz['month']==1) | (df_atleti_cadiz['day']== 31)

And after create a new df using:

df_atleti_cadiz_match = df_atleti_cadiz[mask]

But don't have sucess

CodePudding user response:

mask = df[df_atleti_cadiz['year'].eq(2021) | df_atleti_cadiz['month'].eq(1) | df_atleti_cadiz['day'].eq(31)]
df_atleti_cadiz_match = df_atleti_cadiz[mask]

This currently reads as:

  • Year is 2021 OR Month is 1 OR Day is 31....

Do you perhaps mean to use & instead of |?

  • Related