-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Apply vs Transform on a group object #9235
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
This is definitely a documentation/usage question (pull requests to improve the docs are very welcome!) Here are a couple things we say about transform:
In this case, the first group (corresponding to "foo") is an array with shape (5, 3). So the returned result also needs to have shape (5, 3). Instead, it has shape (5,) in your first example (corresponding to a single column) or shape () in your second example (corresponding to a scalar). In my experience, it's never worth bothering with |
here is the rule of thumb
|
The DataFrameGroupBy docstring does say
In [17]: gr.get_group("foo")
Out[17]:
A B C D
0 foo one 0.733783 0.043300
2 foo two 1.046065 -1.899229
4 foo two 0.899932 -0.510403
6 foo one -0.102515 -1.300482
7 foo three 0.867948 -0.570468 This should be clarified. |
going to close, but if you'd like to improve the docs would be great!. |
Hi,
I understand this ticket is a borderline usage question, but I think it may signal an example of inconsistency either in the documentation or on the way these methods work.
The original question on SO is here.
Consider the following dataframe:
The following commands work:
but none of the following work:
Why? The example on the documentation seems to suggest that calling
transform
on a group allows one to do row-wise operation processing:In other words, I thought that transform is essentially a specific type of apply (the one that does not aggregate). Where am I wrong?
For reference, below is the construction of the original dataframe above:
The text was updated successfully, but these errors were encountered: