You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi Emma,
For Exercise 6. Find the top 3 universities with the largest numbers of undergraduate students for each state.
My code is listed below:
state2 = df[['stabbr','ugds','instnm']]
state3 = state2.groupby(["stabbr"]).apply(lambda x: x.sort_values(["ugds"], ascending = False)).reset_index(drop=True)
df4 = state3.groupby('stabbr').head(3).head(100)
I do not understand why I have to reset_index for this question.
And another question,
for the code listed below:
result = df[['stabbr','ugds','instnm']]
result.groupby('stabbr').apply({'ugds':{lambda x: x.nlargest(3)}})
I got the error message: TypeError: unhashable type: 'dict'
I do not understand why.
I appreciate your help.
The text was updated successfully, but these errors were encountered:
Hi Emma,
For Exercise 6. Find the top 3 universities with the largest numbers of undergraduate students for each state.
My code is listed below:
state2 = df[['stabbr','ugds','instnm']]
state3 = state2.groupby(["stabbr"]).apply(lambda x: x.sort_values(["ugds"], ascending = False)).reset_index(drop=True)
df4 = state3.groupby('stabbr').head(3).head(100)
I do not understand why I have to reset_index for this question.
And another question,
for the code listed below:
result = df[['stabbr','ugds','instnm']]
result.groupby('stabbr').apply({'ugds':{lambda x: x.nlargest(3)}})
I got the error message: TypeError: unhashable type: 'dict'
I do not understand why.
I appreciate your help.
The text was updated successfully, but these errors were encountered: