File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed
Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -151,6 +151,20 @@ unstacks the **last level**:
151151 stacked.unstack(1 )
152152 stacked.unstack(0 )
153153
154+ Notice that the ``stack `` and ``unstack `` methods implicitly sort the index
155+ levels involved. Hence a call to ``stack `` and then ``unstack ``, or viceversa,
156+ will result in a **sorted ** copy of the original DataFrame or Series:
157+
158+ .. ipython :: python
159+
160+ index = MultiIndex.from_product([[2 ,1 ], [' a' , ' b' ]])
161+ df = DataFrame(randn(4 ), index = index, columns = [' A' ])
162+ df
163+ all (df.unstack().stack() == df.sort())
164+
165+ while the above code will raise a ``TypeError `` if the call to ``sort `` is
166+ removed.
167+
154168.. _reshaping.unstack_by_name :
155169
156170If the indexes have names, you can use the level names instead of specifying
You can’t perform that action at this time.
0 commit comments