-2

My question is related to this post:

How to filter csv data by applying conditions on certain columns in python

How would I apply another condition? For example, let's say I'm only interested in Albania and Zambia when Energy_Supply_per_capita > 280 and emissions_of_co2 < 30? Thanks

1 Answers1

1

Try this:

q = "Country_Area in ['Albania','Zambia'] "+\
    "and Energy_Supply_per_capita > 280 "+\
    "and emissions_of_co2 < 30"
df.query(q)
MaxU - stand with Ukraine
  • 205,989
  • 36
  • 386
  • 419
  • One of the comments included these lines of code: cols = ['Country_Area', 'Energy_Supply_per_capita', 'Avg_GDP'] data_c.query('Energy_Supply_per_capita > 280')[cols]. How would I incorporate them? ps sorry for the poor formatting. I'm very new to stack overflow and still figuring things out. – Pistol Pete Jun 12 '17 at 22:54
  • To be more clear, how would I include the rows from another column of data, such as Avg_GDP for those countries? Thanks again – Pistol Pete Jun 12 '17 at 23:04
  • @PistolPete, it's not clear - what are you trying to achieve. Please edit your question and provide a small reproducible data set and a desired data set – MaxU - stand with Ukraine Jun 13 '17 at 17:43