0

I want to check if BOTH 'Rating' and 'Grp' are in df2.columns. Oddly, I get 'yes' although I have dropped 'Rating'. Thank you

df2 = pd.DataFrame({'Grp': ['a' , 'b', 'c', 'd'],
                    'Rating': ['H', 'L', 'L', 'H']
                    })

df2=df2[['Grp']]
if 'Rating' and 'Grp' in df2.columns:
    print('yes')
else:
    print('no')  
Peter
  • 353
  • 3
  • 10
  • This does not work as you think: `if 'Rating' and 'Grp' in df2.columns` – Dani Mesejo Sep 29 '21 at 07:49
  • My above question is not working as expected be'cos it should be if 'Rating' in df2.columns and 'Grp' in df2.column. The other query is for "OR" condition which differs from my query. Thanks – Peter Sep 30 '21 at 07:46

0 Answers0