I want to groupby some athletes by their name an get the smallst age from every person and then sort them by their age from the youngest to the oldest, but in my data there are also some Nan values and i get a FutureWarning: Passing list-likes to .loc or [] with any missing label will raise KeyError in the future, you can use .reindex() as an alternative. Is there any option to skip the records with the Nan values?
Here is my code, tab is a table I read form an csv file which i got from my teacher:
tabYoungest=tab.sort_values(by='Age')
tabYoungestgesamt=tabYoungest.loc[tabYoungest.groupby('Name')['Age'].idxmin()]
tabYoungestgesamt.head(20)
.dropna
within the.loc
:tabYoungest.groupby('Name')['Age'].idxmin().dropna()
.fillna()
to change those values, if you dont want to lose the infotab.groupby('Name').min()
, note also, you could have usedtabYoungest.reindex(tabYoungest.groupby('Name')['Age'].idxmin())
as the warning states, if you didn't want to change your approach.