Skip to content

ENH/CLN: Make df.pivot to the mapping of pivot_table #6950

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
sinhrks opened this issue Apr 24, 2014 · 8 comments · Fixed by #14650
Closed

ENH/CLN: Make df.pivot to the mapping of pivot_table #6950

sinhrks opened this issue Apr 24, 2014 · 8 comments · Fixed by #14650
Labels
API Design Docs Reshaping Concat, Merge/Join, Stack/Unstack, Explode

Comments

@sinhrks
Copy link
Member

sinhrks commented Apr 24, 2014

Related to #6913.

DataFrame.pivot function uses separate logic and has less keyword options than pandas.tools.pivot_table. How about making DataFrame.pivot to call pivot_table internally to support same keywords as pivot_table?

@jreback
Copy link
Contributor

jreback commented Apr 24, 2014

I remember an issue about this, but can't find it now. What API change would this entail, e.g. visible to user?

@sinhrks
Copy link
Member Author

sinhrks commented Apr 24, 2014

From user, keywords only in pivot_table (aggfunc, fill_value, margins and dropna) will be available in DataFrame.pivot

@jreback
Copy link
Contributor

jreback commented Apr 24, 2014

oh...this is just a pass-trhu of keywords....ok then

@jreback jreback added this to the 0.14.0 milestone Apr 24, 2014
@sinhrks
Copy link
Member Author

sinhrks commented Apr 24, 2014

Thanks, let me try.

@jorisvandenbossche
Copy link
Member

I don't know if it is that simple: there is also a pandas.pivot function, which is what DataFrame.pivot calls, and this is clearly distinct from pandas.pivot_table. So I think the question is also: is there a reason there are two functions (pivot/pivot_table)? Have they incompatible functionality? Or could we maybe merge them into one?

Because it would be strange to have a pd.pivot but a DataFrame.pivot calling pd.pivot_table. So I think we should think it a bit more through.

@sinhrks
Copy link
Member Author

sinhrks commented Apr 25, 2014

I've compared pivot and pivot_table, and understand that these are different function.

  • pivot only intends pivotting, not aggregation. Thus it can handle non-numeric values, such as string.
  • pivot_table intends pivotting with aggregation.

I noticed that DataFrame.pivot_table methods already exists separatelly, but not listed in api.rst (briefly explained in reshape.rst). So now I understand:

  • Both functions should not be changed.
  • Include DataFrame.pivot_table to api.rst.

If it is OK, I'll prepare.

@jorisvandenbossche
Copy link
Member

More complete docs are certainly good! Maybe adding somewhere a better explanation of the difference between both functions could also be helpfull (in reshaping.rst or in the docstring of both (see also section)).

@jreback jreback added the Docs label Apr 28, 2014
@nygeog
Copy link

nygeog commented Apr 29, 2014

Hi (I'm new) but came into a problem with the 0.13.1 pivot_table function.

Not totally sure if this is relevant to this discussion... but I lifted my question from http://stackoverflow.com/questions/23366016/pandas-0-13-1-pivot-table-pivot-error-not-in-0-12-0-should-and-how-i-go

So I have two lines of code below.

One that works successfully with Python 2.7.5 and Pandas 0.12.0

dfp = pd.pivot_table(df, values=pivYears, rows=['partid'],cols=['finestflag_OV'], aggfunc=np.sum)
And this one that does not work successfully with Python 2.7.6 and Pandas 0.13.1. I'm getting error refering to

malloc: *** mach_vm_map …. error code = 3
here's the code:

dfp = pd.pivot_table(df, values=pivYears, index=['partid'],columns=['finestflag_OV'], aggfunc=np.sum)
It could be that I am misunderstanding pivot vs. pivot_table and/or how it works in 0.13.1.

Lastly, since I've been using 0.12.0 for a while and am comfortable with it, is it possible to downgrade from 0.13.1 to 0.12.0 on my new machine? (Also, can I go back in Python versions so all my machines have the same version of Python and Pandas?)

Edits for questions: Both OS's are OS X 10.9.2.

Here's a subset of 9 rows of data in the CSV. https://github.com/nygeog/python/blob/master/pandas/pivot_sample.csv

The actual file has ~1.7 million rows. Which works fine on machine with 0.12.0.

Thanks, Danny

@jreback jreback modified the milestones: 0.15.0, 0.14.0 Apr 30, 2014
@jreback jreback modified the milestones: 0.16.0, Next Major Release Mar 3, 2015
mroeschke added a commit to mroeschke/pandas that referenced this issue Nov 14, 2016
mroeschke added a commit to mroeschke/pandas that referenced this issue Nov 16, 2016
Move pivot paragraph to pivot table section

add pivot_table reference to pivot
jorisvandenbossche pushed a commit that referenced this issue Nov 16, 2016
Move pivot paragraph to pivot table section

add pivot_table reference to pivot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Docs Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants