question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make `DataFrame.pivot` accepts a list of column names as values

See original GitHub issue

Problem 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:closed
  • Created 6 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jorisvandenbosschecommented, Aug 7, 2017

@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: the pivot function in this file: https://github.com/pandas-dev/pandas/blob/master/pandas/core/reshape/reshape.py)

0reactions
sunilk747commented, Dec 4, 2017

Hello. I am new to this library. I would like to work on this issue. Any sort of help would be appreciated.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found