pandas.Index.get_loc — pandas 1.0.1 documentation (original) (raw)

Index. get_loc(self, key, method=None, tolerance=None)[source]

Get integer location, slice or boolean mask for requested label.

Parameters

keylabel

method{None, ‘pad’/’ffill’, ‘backfill’/’bfill’, ‘nearest’}, optional

toleranceint or float, optional

Maximum distance from index value for inexact matches. The value of the index at the matching location most satisfy the equationabs(index[loc] - key) <= tolerance.

New in version 0.21.0: (list-like tolerance)

Returns

locint if unique index, slice if monotonic index, else mask

Examples

unique_index = pd.Index(list('abc')) unique_index.get_loc('b') 1

monotonic_index = pd.Index(list('abbc')) monotonic_index.get_loc('b') slice(1, 3, None)

non_monotonic_index = pd.Index(list('abcb')) non_monotonic_index.get_loc('b') array([False, True, False, True], dtype=bool)