-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
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
Groupby built by columns : cannot use .head() or .apply() #9772
Comments
These do look like bugs to me -- thanks for the report! If you're interested in digging in to figure out what's going on, such efforts would be appreciated :). |
this is an error in |
Eventually, there seems to be 2 different bugs. The problem with head() may not be so relevant, cause if you groups columns, when you show the head of each group you see the head of the whole df. Yet, the error's still here and maybe address with an exception or warning (cause atm it's silent when you have more rows than columns.). The pb with apply seems to be a bit deeper. The given function is applied without transmitting the 'axis' argument given in the first groupby call. I couldn't find where this 'axis' argument is stored, if so. Would you agree setting a new attribute to BaseGrouper class, so as to remind the orientation of the build ? If so I will propose a correction. |
no it just needs to be passed thru |
I don't think the issue with
If you want to pass an extra argument, you can add an argument to the lambda and pass it to
We could actually inspect the arguments of the passed-in function using reflection, and pass through the axis parameter whenever it takes an argument named 'axis', but that seems like it might be overkill:
|
Yep, I agree it's not a bug. I was thinking about adding a small warning in the doc, just for people like me not to forget the 'axis' argument in the applied function, but I had no time to do so yet. Still, it's surprising that
and
have not the same result. |
When The issue with Of course, an argument against transposing the group when passing it to the UDF is that this would be a rather large change for what seems to me to be of little value. After all, any UDF can be rewritten under the presumption that the values passed in haven't been transposed. In this case, the UDF would be:
Using this in the OP example then produces the same result as |
This, if I well understood, should build a groupby object grouping columns, and so give the possibility to later aggregate them. And indeed :
works well. But
Throws an error:
and
from which I expected the same result as the first example, gives this table :
I didn't really get what's happening, I don't exclude a misunderstanding or an error from myself.
The text was updated successfully, but these errors were encountered: