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**:
151
151
stacked.unstack(1 )
152
152
stacked.unstack(0 )
153
153
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
+
154
168
.. _reshaping.unstack_by_name :
155
169
156
170
If 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