@@ -1173,14 +1173,15 @@ def from_product(cls, iterables, sortorder=None, names=None):
1173
1173
labels = cartesian_product (labels )
1174
1174
return MultiIndex (levels , labels , sortorder = sortorder , names = names )
1175
1175
1176
- def sort_monotonic (self ):
1176
+ def sort_levels_monotonic (self ):
1177
1177
"""
1178
1178
.. versionadded:: 0.20.0
1179
1179
1180
1180
This is an *internal* function.
1181
1181
1182
1182
create a new MultiIndex from the current to monotonically sorted
1183
- items IN the levels
1183
+ items IN the levels. This does not actually make the entire MultiIndex
1184
+ monotonic, JUST the levels.
1184
1185
1185
1186
The resulting MultiIndex will have the same outward
1186
1187
appearance, meaning the same .values and ordering. It will also
@@ -1190,6 +1191,19 @@ def sort_monotonic(self):
1190
1191
-------
1191
1192
MultiIndex
1192
1193
1194
+ Examples
1195
+ --------
1196
+
1197
+ >>> i = pd.MultiIndex(levels=[['a', 'b'], ['bb', 'aa']],
1198
+ labels=[[0, 0, 1, 1], [0, 1, 0, 1]])
1199
+ >>> i
1200
+ MultiIndex(levels=[['a', 'b'], ['bb', 'aa']],
1201
+ labels=[[0, 0, 1, 1], [0, 1, 0, 1]])
1202
+
1203
+ >>> i.sort_monotonic()
1204
+ MultiIndex(levels=[['a', 'b'], ['aa', 'bb']],
1205
+ labels=[[0, 0, 1, 1], [1, 0, 1, 0]])
1206
+
1193
1207
"""
1194
1208
1195
1209
if self .is_lexsorted () and self .is_monotonic :
@@ -1237,7 +1251,7 @@ def remove_unused_levels(self):
1237
1251
1238
1252
Examples
1239
1253
--------
1240
- >>> i = MultiIndex.from_product([range(2), list('ab')])
1254
+ >>> i = pd. MultiIndex.from_product([range(2), list('ab')])
1241
1255
MultiIndex(levels=[[0, 1], ['a', 'b']],
1242
1256
labels=[[0, 0, 1, 1], [0, 1, 0, 1]])
1243
1257
0 commit comments