2

I have a dataframe that has various columns and rows of data. I want to select all rows where the Year column = 2015 and Month column = 7.

The following works:

new_result.loc[new_result['Year'] == 2015,:].loc[new_result['Month'] == 7,:]

However, is there a more elegant way to express the same thing? i.e. Fewer text because I can see how total text can get out of control for a multiple conditioned query.

codingknob
  • 11,108
  • 25
  • 89
  • 126

1 Answers1

2
new_result[(new_result['Year']==2015) & (new_result['Month']==7)]

or

new_result.query("Year==2015 and Month==7")
vk1011
  • 7,011
  • 6
  • 26
  • 42