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

Solution to Question 27 is no longer supported. #41

Open
tomleary opened this issue May 27, 2024 · 1 comment
Open

Solution to Question 27 is no longer supported. #41

tomleary opened this issue May 27, 2024 · 1 comment

Comments

@tomleary
Copy link

I was able to get the correct result with the following:

df.groupby('grps')['vals'].nlargest(3).groupby('grps').sum()

but I'm sure there's a more elegant way to do it than by using the groupby method twice in one line.

@Akshitlohani
Copy link

Akshitlohani commented Jul 4, 2024

we can also use lambda function
df.groupby('grps')['vals'].apply(lambda x: x.nlargest(3,'last').sum())

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

2 participants