2
Hello,
i have the DF below which I would like to group by 'country' and get the maximum population value:
df = pd.DataFrame({'pais': ['Brasil', 'Brasil' , 'EUA', 'EUA'],
'cidade': ['Santos', 'São Paulo', 'Orlando', 'Nova York'],
'populacao': [100000, 500000, 200000, 550000],
'idade':[430,440,200,150]})
df
The result I want:
country populated city
Brazil São Paulo 500000
USA New York 550000
What I’ve already done:
df.groupby(['pais','cidade']).loc[df.populacao == df.populacao.max()]
It returns me: "Attributeerror: Cannot access callable attribute 'Loc' of 'Dataframegroupby' Objects, Try using the 'apply' method"
I understand that I have to use a function and apply it, but I don’t know exactly how. Can anyone help me?