Search code examples
pandasdataframejupyter-notebookkaggle

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


Solution

  • @wen ansered this in the comments.

    df['variety'].value_counts().loc[lambda x : x>1]