@@ -151,6 +151,15 @@ unstacks the **last level**:
151
151
stacked.unstack(1 )
152
152
stacked.unstack(0 )
153
153
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
+
154
163
Notice that the ``stack `` and ``unstack `` methods implicitly sort the index
155
164
levels involved. Hence a call to ``stack `` and then ``unstack ``, or viceversa,
156
165
will 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:
165
174
while the above code will raise a ``TypeError `` if the call to ``sort `` is
166
175
removed.
167
176
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
-
177
177
.. _reshaping.stack_multiple :
178
178
179
179
Multiple Levels
@@ -218,6 +218,8 @@ calling ``sortlevel``, of course). Here is a more complex example:
218
218
columns = MultiIndex.from_tuples([(' A' , ' cat' ), (' B' , ' dog' ),
219
219
(' B' , ' cat' ), (' A' , ' dog' )],
220
220
names = [' exp' , ' animal' ])
221
+ index = MultiIndex.from_product([(' bar' , ' baz' , ' foo' , ' qux' ), (' one' , ' two' )],
222
+ names = [' first' , ' second' ])
221
223
df = DataFrame(randn(8 , 4 ), index = index, columns = columns)
222
224
df2 = df.ix[[0 , 1 , 2 , 4 , 5 , 7 ]]
223
225
df2
0 commit comments