Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about reset_index #30

Open
XXXVivilovesBoba opened this issue Sep 1, 2021 · 0 comments
Open

Question about reset_index #30

XXXVivilovesBoba opened this issue Sep 1, 2021 · 0 comments

Comments

@XXXVivilovesBoba
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant