-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Test/fix case where use of "All" causes problems in pivot_table with margins=True #3335
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
I'd like to take a stab at this if no one minds |
go for it! |
Would it be an appropriate solution to have any instances of "All" used as an index or column changed to "All_" in the original dataframe and the resulting pivot table so that having a user use "All" as a column name will not cause issues anymore? |
I'm not sure exactly what "problems" are caused by this issue, but generally speaking it's a better idea to raise an exception and force users to take some fallback action themselves rather than silently proceeding with some guess about user intent. |
Alright then, I think I'll just scan the DataFrame for any instances of All being used as a value or column title, and if there is one, I'll raise an exception. The problem was that when margins was passed in as true, columns with the title "All" were added to the dataframe, and then add a later point, instances of "All" columns had aggregates data filled into them, so if the original data used "All" it was being replaced I think |
need to define what is the incorrect behavior here first. |
So this is what I have so far showing the issue. What happens is that when aggregating the data, as the script is going through the columns, it looks for All columns to aggregate data under. When "foo" was changed to "All" in the next DataFrame, the output is clearly nothing like that of the first pivot table. As a result, its probably most appropriate to raise an error when "All" is being used as a data point since it would be more trouble than its worth to rewrite the code around just this corner case.
|
…column. ref pandas-dev#3335. Adds margin_column parameter to pivot_table so that user can set it to something other than 'All'. Raises ValueError exception if there is a conflict between the value of margin_column and one of the other values appearing in the indices of the pivot table.
…column. ref pandas-dev#3335. Adds margin_name parameter to pivot_table so that user can set it to something other than 'All'. Raises ValueError exception if there is a conflict between the value of margin_column and one of the other values appearing in the indices of the pivot table.
…_margins ENH: #3335 Pivot table support for setting name of margins column.
No description provided.
The text was updated successfully, but these errors were encountered: