pivot_table function with renaming columns
See original GitHub issueHere is the example from the documentation.
df = ks.DataFrame({"A": ["foo", "foo", "foo", "foo", "foo",
"bar", "bar", "bar", "bar"],
"C": ["small", "large", "large", "small",
"small", "large", "small", "small",
"large"],
"E": [2, 4, 5, 5, 6, 6, 8, 9, 9]},
columns=['A', 'C', 'E'])
df.pivot_table(values='E', index=['A'],
columns='C', aggfunc='sum')
The above code works as expected. Then I rename the columns like
df.columns =['New_A','New_C','New_E']
print(df.columns)
This works fine with applymap
and other functions like to_datetime
but as soon as I use pivot_table
, I got an error.
df.pivot_table(values='New_E', index=['New_A'],
columns='New_C', aggfunc='sum')
The above code will give the following error:
KeyError: 'No StructField named New_E'
Is it not allowed to change the column name right now?? Thanks.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Rename a table or field in Power Pivot - Microsoft Support
In the Power Pivot window, right-click the tab that contains the table that you want to rename, and then click Rename. For columns,...
Read more >Quick tip: Rename headers in pivot table so they are ...
Just type over the headers / total fields to make them user friendly. See this quick demo to understand what I mean: So...
Read more >How to rename fields in a pivot table - Exceljet
You can do this by accessing Field Settings for the field in question. Either right-click on the field and choose Value field settings,...
Read more >How to Modify Column Names in Pandas Pivot Table - Statology
... or format the column names in a pandas pivot table in a specific way. Fortunately this is easy to do using built-in...
Read more >How to Rename Pandas DataFrame Columns (with Examples)
This method is best when you want to rename all columns following the same ... Say we create a Pandas pivot table and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ll work on this.
Shall we fix the
columns
setter to rename the Spark columns for now? @itholic @harupy Do you want to fix it?I’ll handle
merge
andpivot_table
soon.