I have a dataframe with all Fifa 19 players. I've used group by to get the top 10 countries with the best players (best as in the highest overall mean), including only countries with more than 250 players in the Dataframe.
df[df.groupby('Nationality')['Overall'].transform('size') > 250].groupby(['Nationality'])['Overall'].mean().nlargest(10)
Now, I want to get the entire dataframe, all columns included, but only with these top 10 countries. How can I do this?
UPDATE:
Example created to better illustrate:
import pandas as pd
df = pd.DataFrame({'user': ['Bob', 'Jane', 'Alice','Rick'],
'income': [40000, 50000, 42000, 10000],
'country':['Brazil','USA','Brazil','Canada']})
df[df.groupby('country')['income'].transform('size') > 1].groupby(['country'])['income'].mean().nlargest(2)
I would like to filter only brazil on this dataframe