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

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

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

Comments

Projects
None yet
7 participants
@dclong

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

This comment has been minimized.

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

This comment has been minimized.

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 gfyoung added the Enhancement label Aug 5, 2017

@gfyoung

This comment has been minimized.

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

This comment has been minimized.

Member

jorisvandenbossche commented Aug 7, 2017

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

This comment has been minimized.

Contributor

ibrahimsharaf commented Aug 7, 2017

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

@jorisvandenbossche

This comment has been minimized.

Member

jorisvandenbossche commented 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)

@sunilk747

This comment has been minimized.

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.

@jreback jreback modified the milestones: Next Major Release, 0.22.0 Dec 5, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment