@@ -151,6 +151,15 @@ unstacks the **last level**:
151151 stacked.unstack(1 )
152152 stacked.unstack(0 )
153153
154+ .. _reshaping.unstack_by_name :
155+
156+ If the indexes have names, you can use the level names instead of specifying
157+ the level numbers:
158+
159+ .. ipython :: python
160+
161+ stacked.unstack(' second' )
162+
154163 Notice that the ``stack `` and ``unstack `` methods implicitly sort the index
155164levels involved. Hence a call to ``stack `` and then ``unstack ``, or viceversa,
156165will result in a **sorted ** copy of the original DataFrame or Series:
@@ -165,15 +174,6 @@ will result in a **sorted** copy of the original DataFrame or Series:
165174 while the above code will raise a ``TypeError `` if the call to ``sort `` is
166175removed.
167176
168- .. _reshaping.unstack_by_name :
169-
170- If the indexes have names, you can use the level names instead of specifying
171- the level numbers:
172-
173- .. ipython :: python
174-
175- stacked.unstack(' second' )
176-
177177.. _reshaping.stack_multiple :
178178
179179Multiple Levels
@@ -218,6 +218,8 @@ calling ``sortlevel``, of course). Here is a more complex example:
218218 columns = MultiIndex.from_tuples([(' A' , ' cat' ), (' B' , ' dog' ),
219219 (' B' , ' cat' ), (' A' , ' dog' )],
220220 names = [' exp' , ' animal' ])
221+ index = MultiIndex.from_product([(' bar' , ' baz' , ' foo' , ' qux' ), (' one' , ' two' )],
222+ names = [' first' , ' second' ])
221223 df = DataFrame(randn(8 , 4 ), index = index, columns = columns)
222224 df2 = df.ix[[0 , 1 , 2 , 4 , 5 , 7 ]]
223225 df2
0 commit comments