0

i have pandas dataframe

aa={'month':[1,2,3,4,5,6,7,8,9,10,11,12]*3,'year':[2018]*12+[2019]*12+[2020]*12}

df = pd.DataFrame(aa,columns = ['month','year'])

I want to filter only month 10 and year 2020 and 2019 how can it be done.

i am trying this but gives dataframe with zero rows.

ncdf = df.loc[(df['year'] == 2020+'|'+2019)&(df['month'] == 10)]
raheel
  • 164
  • 7

1 Answers1

1

Filter like this:

df[(df['month']==10)&(df['year'].isin([2019,2020]))]
Wasif
  • 14,755
  • 3
  • 14
  • 34