Skip to content

BUG: groupby.nth after selection #53518

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
rhshadrach opened this issue Jun 4, 2023 · 0 comments · Fixed by #53519
Closed

BUG: groupby.nth after selection #53518

rhshadrach opened this issue Jun 4, 2023 · 0 comments · Fixed by #53519
Assignees
Labels
Bug Filters e.g. head, tail, nth Groupby
Milestone

Comments

@rhshadrach
Copy link
Member

df = DataFrame(
    {
        "a": [1, 1, 2],
        "b": [np.nan, 4, 5],
        "c": [6, 7, 8],
    }
)
gb = df.groupby("a")[["b"]]
result = gb.nth(0, dropna="any")

raises ValueError: Item wrong length 3 instead of 2. If you remove the null value, column selection is no longer reflected in the result

df = DataFrame(
    {
        "a": [1, 1, 2],
        "b": [3, 4, 5],
        "c": [6, 7, 8],
    }
)
gb = df.groupby("a")[["b"]]
result = gb.nth(0, dropna="any")
print(result)
#    a  b  c
# 0  1  3  6
# 2  2  5  8

Replacing dropna=None in the above gives the expected

   b
0  3
2  5
@rhshadrach rhshadrach added Bug Groupby Filters e.g. head, tail, nth labels Jun 4, 2023
@rhshadrach rhshadrach self-assigned this Jun 4, 2023
@rhshadrach rhshadrach added this to the 2.1 milestone Jun 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Filters e.g. head, tail, nth Groupby
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant