Make `DataFrame.pivot` accepts a list of column names as values
See original GitHub issueProblem description
Currently DataFrame.pivot
accepts either None
or a column name for the option values
but not a list of column names.
# this works
df.pivot(values = None)
df.pivot(values = 'column_name')
# this doesn't work
df.pivot(values = ['cn1', 'cn2'])
It is not convenient if I want to create a pivot table for multiple columns at the same time. Of course, we can pass None
to values
and then select columns we want to. But this is not as convenient.
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
python - pandas - pivot column names as values
Try: df1 = df.copy() df1.columns = df1.columns.droplevel([1,2]) df1.stack().reset_index().pivot(index='level_0', columns=0).
Read more >pandas.DataFrame.pivot — pandas 1.5.2 documentation
Reshape data (produce a “pivot” table) based on column values. Uses unique values from specified index / columns to form axes of the...
Read more >Guide to Create Pivot Tables from Pandas DataFrame
The values parameter accepts column names whose values will be grouped and kept in the pivot table after performing aggregate statistics. If we ......
Read more >Pivot Tables in Pandas with Python
Pandas gives access to creating pivot tables in Python using the .pivot_table() function. The function has the following default parameters:.
Read more >How to Create Pandas Pivot Multiple Columns
By manipulating given index or column values we can reshape the data based on column values. Use the pandas.pivot_table to create a spreadsheet-style...
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
@ibrahimsharaf Did you already go through the contributing guide (to set up development environment and such: http://pandas.pydata.org/pandas-docs/stable/contributing.html). If not, you should start with that.
For this issue: I would recommend to first write some tests for the desired new functionality, and then you can look at changing the
pivot
function to do this (the function is located here: thepivot
function in this file: https://github.com/pandas-dev/pandas/blob/master/pandas/core/reshape/reshape.py)Hello. I am new to this library. I would like to work on this issue. Any sort of help would be appreciated.