-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Some str reducers fail in Groupby.transform with axis=1 #45986
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
Comments
For When we make the transform call,
pandas/pandas/core/groupby/groupby.py Line 1712 in 4c5db2e
In the pandas/pandas/core/groupby/generic.py Lines 1775 to 1781 in 4c5db2e
This is why it works for So, to fix:
Let me know which way makes the most sense and I will make a PR for it. |
For df = pd.DataFrame({"a": [1, 2, 3], "b": [3, 4, 5], "c": [5, 6, 7]}, index=["x", "y", "z"])
result = df.groupby([0, 0, 1], axis=1).transform("ngroup") The above df = pd.DataFrame({"a": [1, 2,], "b": [3, 4], "c": [5, 6]}, index=["x", "y"])
result = df.groupby([0, 0, 1], axis=1).transform("ngroup") will fail for For >>> result = df.groupby([0, 0, 1], axis=1).transform("nth", 1)
# Output
ValueError: 'nth' is not a valid function name for transform(name) It fails because pandas/pandas/core/groupby/groupby.py Lines 1693 to 1695 in 4c5db2e
|
Thanks for digging into these!
I don't think we should require the user to pass axis=1 twice to get axis=1 behavior. The 2nd looks like a good solution to me, assuming specification of axis gives the correct result (the column label of the min/max value).
This looks correct to me - nth is a filter and as such we may end up with multiple or no values in a given group. As there isn't a reliable way to transform, I believe raising is the correct thing to do. |
Closing since axis=1 is deprecated. |
Uh oh!
There was an error while loading. Please reload this page.
Reducers:
All raise a ValueError when used with
axis=1
, e.g.The text was updated successfully, but these errors were encountered: