Skip to content

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

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

Closed
dclong opened this issue Aug 3, 2017 · 7 comments
Closed

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

dclong opened this issue Aug 3, 2017 · 7 comments
Labels
Enhancement good first issue Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Milestone

Comments

@dclong
Copy link

dclong commented Aug 3, 2017

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.

@gfyoung gfyoung added Enhancement Reshaping Concat, Merge/Join, Stack/Unstack, Explode and removed Enhancement labels Aug 3, 2017
@gfyoung
Copy link
Member

gfyoung commented Aug 3, 2017

@dclong : Thanks for the issue! Have you tried "df.pivot_table" ? I think this might better address your needs. df.pivot is not meant for what you've described AFAIK.

@dclong
Copy link
Author

dclong commented Aug 5, 2017

@gfyoung: It seems that pandas.pivot_table requires an aggregation function? I don't want to aggregate the data but just pivot the table.

@gfyoung
Copy link
Member

gfyoung commented Aug 5, 2017

@dclong : Ah, gotcha. I'll tag this as an enhancement for now, though then again I'm not sure that that's how pivot is supposed to be used (or whether the original designers intended that to be allowed).

@jorisvandenbossche
Copy link
Member

I think this is sensible to allow. pivot already either pivots a single column are all remaining columns, so I don't see a reason to not allow to pivot a selection of the columns (certainly because pivot_table also allows this).

PRs welcome!

@jorisvandenbossche jorisvandenbossche added this to the Next Major Release milestone Aug 7, 2017
@ibrahimsharaf
Copy link
Contributor

Hello @jorisvandenbossche, I would love to work on this, how can I start?

@jorisvandenbossche
Copy link
Member

@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)

@sunilk747
Copy link

sunilk747 commented 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement good first issue Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants