-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
It's difficult to predict what DataFrame.groupby().apply() will return: #9867
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
docs are here: http://pandas-docs.github.io/pandas-docs-travis/groupby.html#flexible-apply |
DataFrame.groupby().apply()
will return:
I am at the Pandas Sprint. I am starting to work on this one, and trying to create a mini-table example. |
I agree, I think this could definitely use some cleaning up. In particular, the identity specific behavior seems highly questionable -- nothing else in numpy/pandas works like that. The first step would be to thoroughly document the existing behavior and see it's possible to come up with a more consistent set of rules. |
Link to a notebook from @mbirdi illustrating the current behavior: http://nbviewer.ipython.org/gist/mbirdi/05f8a83d340476e5f03a |
tracked in #13056 |
Hi could you please confirm whether this issue fixed on pandas 0.20.2. I am still getting the issue. some times groupby lambda returns pivot table and some time it returns normal dataframe |
see #13056 you would have to show an example |
pls create a new issue and show a copy-pastable example (NO images), showing |
I consider myself confused on this point, per my question here. |
I found It's difficult to predict what
DataFrame.groupby().apply()
will return. the result depends on the type of the return object and the index of the return object. for example:When the argument and the return object is
DataFrame
and has the same index object, there are not group keys in the result:the output is:
if the index is not the same object, there are group keys, even the index values are the same:
the output is:
if the function returns
Series
object and the index of theseSeries
objects are not he same values, the index of the result is aMultiIndex
:the output:
If all the
Series
objects have the same index values, theSeries
objects are the rows of the result:the output:
Here are more exampes:
Because the index is the same object:
not group keys in the output:
If we copy the return value, the index is not the same object:
the output contains group keys:
no group keys because the index object is the same (but use
x[:]
will get the group keys):It seems that there is no document about this.
The text was updated successfully, but these errors were encountered: