Skip to content

ENH: Implement nlargest and nsmallest for DataFrameGroupBy #46986

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

Closed

Conversation

lorentzbao
Copy link
Contributor

@lorentzbao lorentzbao commented May 10, 2022

Try to implement nlargest and nsmallest methods for DataFrameGroupBy. Appreciate any comments.

>>> df
  group name  data
0   bar   b1     1
1   bar   b2     3
2   bar   b3     3
3   foo   f1     1
4   foo   f2     1
5   foo   f3     3


>>> df.groupby("group").nlargest(n=2)
        name  data
group
bar   1   b2     3
      2   b3     3
foo   5   f3     3
      3   f1     1


>>> df.groupby("group").nlargest(n=2, keep="all")
        name  data
group
bar   1   b2     3
      2   b3     3
foo   5   f3     3
      3   f1     1
      4   f2     1

>>> df.groupby("group").nsmallest(n=2)
        name  data
group
bar   0   b1     1
      1   b2     3
foo   3   f1     1
      4   f2     1


>>> df.groupby("group").nsmallest(n=2, keep="all")
        name  data
group
bar   0   b1     1
      1   b2     3
      2   b3     3
foo   3   f1     1
      4   f2     1

@lorentzbao lorentzbao marked this pull request as draft May 20, 2022 01:51
@github-actions
Copy link
Contributor

This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this.

@github-actions github-actions bot added the Stale label Jun 20, 2022
@mroeschke
Copy link
Member

Thanks for the pull request, but it appears to have gone stale. If interested in continuing, please merge in the main branch, address any review comments and/or failing tests, and we can reopen.

@mroeschke mroeschke closed this Jun 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENH: implement nlargest and nsmallest for DataFrameGroupBy like SeriesGroupBy
2 participants