@@ -1925,7 +1925,9 @@ def get_slice_bound(self, label, side, kind):
1925
1925
def slice_locs (self , start = None , end = None , step = None , kind = None ):
1926
1926
"""
1927
1927
For an ordered MultiIndex, compute the slice locations for input
1928
- labels. They can be tuples representing partial levels, e.g. for a
1928
+ labels.
1929
+
1930
+ The input labels can be tuples representing partial levels, e.g. for a
1929
1931
MultiIndex with 3 levels, you can pass a single value (corresponding to
1930
1932
the first level), or a 1-, 2-, or 3-tuple.
1931
1933
@@ -1945,7 +1947,32 @@ def slice_locs(self, start=None, end=None, step=None, kind=None):
1945
1947
1946
1948
Notes
1947
1949
-----
1948
- This function assumes that the data is sorted by the first level
1950
+ This method only works if the MultiIndex is properly lex-sorted. So,
1951
+ if only the first 2 levels of a 3-level MultiIndex are lexsorted,
1952
+ you can only pass two levels to ``.slice_locs``.
1953
+
1954
+ Examples
1955
+ --------
1956
+ >>> mi = pd.MultiIndex.from_arrays([list('abbd'), list('deff')],
1957
+ ... names=['A', 'B'])
1958
+
1959
+ Get the slice locations from the beginning of 'b' in the first level
1960
+ until the end of the multiindex:
1961
+
1962
+ >>> mi.slice_locs(start='b')
1963
+ (1, 4)
1964
+
1965
+ Like above, but stop at the end of 'b' in the first level and 'f' in
1966
+ the second level:
1967
+
1968
+ >>> mi.slice_locs(start='b', end=('b', 'f'))
1969
+ (1, 3)
1970
+
1971
+ See Also
1972
+ --------
1973
+ MultiIndex.get_loc : Get location for a label or a tuple of labels.
1974
+ MultiIndex.get_locs : Get location for a label/slice/list/mask or a
1975
+ sequence of such.
1949
1976
"""
1950
1977
# This function adds nothing to its parent implementation (the magic
1951
1978
# happens in get_slice_bound method), but it adds meaningful doc.
@@ -2016,6 +2043,8 @@ def get_loc(self, key, method=None):
2016
2043
See also
2017
2044
--------
2018
2045
Index.get_loc : get_loc method for (single-level) index.
2046
+ MultiIndex.slice_locs : Get slice location given start label(s) and
2047
+ end label(s).
2019
2048
MultiIndex.get_locs : Get location for a label/slice/list/mask or a
2020
2049
sequence of such.
2021
2050
"""
@@ -2369,6 +2398,8 @@ def get_locs(self, seq):
2369
2398
See also
2370
2399
--------
2371
2400
MultiIndex.get_loc : Get location for a label or a tuple of labels.
2401
+ MultiIndex.slice_locs : Get slice location given start label(s) and
2402
+ end label(s).
2372
2403
"""
2373
2404
2374
2405
# must be lexsorted to at least as many levels
0 commit comments