Skip to content

DOC: Explain pivot vs. pivot_table (#6950) #14650

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

Merged
merged 1 commit into from
Nov 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/source/reshaping.rst
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ Pivot tables

.. _reshaping.pivot:

While ``pivot`` provides general purpose pivoting of DataFrames with various
data types (strings, numerics, etc.), Pandas also provides the ``pivot_table``
function for pivoting with aggregation of numeric data.

The function ``pandas.pivot_table`` can be used to create spreadsheet-style pivot
tables. See the :ref:`cookbook<cookbook.pivot>` for some advanced strategies

Expand Down
5 changes: 5 additions & 0 deletions pandas/core/reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,11 @@ def pivot_simple(index, columns, values):
Returns
-------
DataFrame

See also
--------
DataFrame.pivot_table : generalization of pivot that can handle
duplicate values for one index/column pair
"""
if (len(index) != len(columns)) or (len(columns) != len(values)):
raise AssertionError('Length of index, columns, and values must be the'
Expand Down
5 changes: 5 additions & 0 deletions pandas/tools/pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ def pivot_table(data, values=None, index=None, columns=None, aggfunc='mean',
Returns
-------
table : DataFrame

See also
--------
DataFrame.pivot : pivot without aggregation that can handle
non-numeric data
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a similar reference in pivot to pivot_table ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pivot docstring already references pivot_table (here)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes, that's good. But not yet the pd.pivot one, and that is apparently located here: https://github.com/pandas-dev/pandas/blob/master/pandas/core/reshape.py#L339

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thank you for bringing that to my attention. I'll push that change later tonight.

"""
index = _convert_by(index)
columns = _convert_by(columns)
Expand Down