0

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

  • [How to convert columns into one datetime column in pandas?](https://stackoverflow.com/questions/19350806/how-to-convert-columns-into-one-datetime-column-in-pandas) - make a datetime Series; compare the Series to your condition; use the resulting boolean Series for the *filter*. – wwii Jun 13 '22 at 22:05

1 Answers1

0
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 |?

BeRT2me
  • 12,699
  • 2
  • 13
  • 31