Skip to content

Commit 2108301

Browse files
committed
Add example in reshaping.rst
1 parent b1db902 commit 2108301

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

doc/source/user_guide/reshaping.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,19 @@ You can then select subsets from the pivoted ``DataFrame``:
9090
Note that this returns a view on the underlying data in the case where the data
9191
are homogeneously-typed.
9292

93+
Now :meth:`DataFrame.pivot` method also supports multiple columns as indexes.
94+
95+
.. ipython:: python
96+
97+
df1 = pd.DataFrame({'variable1': ['A', 'A', 'A', 'A', 'B', 'B', 'B', 'B'],
98+
'variable2': ['a', 'a', 'b', 'b', 'a', 'a', 'b', 'b'],
99+
'variable3': ['C', 'D', 'C', 'D', 'C', 'D', 'C', 'D'],
100+
'value': np.arange(8)})
101+
df1
102+
103+
df1.pivot(index=['variable1', 'variable2'], columns='variable3',
104+
values='value')
105+
93106
.. note::
94107
:func:`~pandas.pivot` will error with a ``ValueError: Index contains duplicate
95108
entries, cannot reshape`` if the index/column pair is not unique. In this

0 commit comments

Comments
 (0)