1

I want to explain my question with an example. I have a dataset which includes avocado average prices and many features about these prices(I guess avocado prices dataset is very popular, idk). And there is a feature called "region" that shows where avocadoes grew. I wrote this line of code to get to avocados feature which grews on "west". my data's name is data btw

west = data[data['region'] =='West'] 

And i thinked that what if i wanted to get the avocadoes which grew in 2016 and also grew on West. How can i get these data at the same time ?

1
  • 1
    Can you add few rows of your dataframe Commented May 2, 2021 at 20:32

3 Answers 3

2

I think the pandas DataFrame filter with boolean conditions can solve your question.

Suppose your column name for avocado growing year is grew_in. Then try this:

west_2016 = data[(data['region'] =='West') & (data['grew_in'] == 2016)] 
Sign up to request clarification or add additional context in comments.

Comments

1

You can try query interfrace of pandas.

In particular, if your "grew in" data is present in year column, you could do something like,

data.query('region == "West" and year == 2016')

References:

1 Comment

I've learned a new thing thanks to you sir.
0
west = data[(data['region']=='west')&(data['year']==2016)]

1 Comment

Thank you for your answer sir. You solved my problem.

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.