Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas Value Counts With Constraint For More Than One Occurance

Working with the Wine Review Data from Kaggle here. I am able to return the number of occurrences by variety using value_counts()

enter image description here

However, I am trying to find a quick way to limit the results to varieties and their counts where there is more than one occurrence.

Trying df.loc[df['variety'].value_counts()>1].value_counts() and df['variety'].loc[df['variety'].value_counts()>1].value_counts() both return errors.

The results can be turned into a DataFrame and the constraint added there, but something tells me that there is a way more elegant way to achieve this.

enter image description here

like image 855
Michael Avatar asked Jan 28 '23 03:01

Michael


1 Answers

@wen ansered this in the comments.

df['variety'].value_counts().loc[lambda x : x>1] 
like image 188
Michael Avatar answered Jan 31 '23 08:01

Michael