-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

0

1 Answer 1

1

Try this:

q = "Country_Area in ['Albania','Zambia'] "+\
    "and Energy_Supply_per_capita > 280 "+\
    "and emissions_of_co2 < 30"
df.query(q)
Sign up to request clarification or add additional context in comments.

3 Comments

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.
To be more clear, how would I include the rows from another column of data, such as Avg_GDP for those countries? Thanks again
@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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.