pandas 1.4.2

ParametersReturns
get_loc(self, key, method=None, tolerance=None)

Parameters

key : label
method : {None, 'pad'/'ffill', 'backfill'/'bfill', 'nearest'}, optional
  • default: exact matches only.

  • pad / ffill: find the PREVIOUS index value if no exact match.

  • backfill / bfill: use NEXT index value if no exact match

  • nearest: use the NEAREST index value if no exact match. Tied distances are broken by preferring the larger index value.

tolerance : int or float, optional

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

Returns

loc : int if unique index, slice if monotonic index, else mask

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

Examples

This example is valid syntax, but we were not able to check execution
>>> unique_index = pd.Index(list('abc'))
... unique_index.get_loc('b') 1
This example is valid syntax, but we were not able to check execution
>>> monotonic_index = pd.Index(list('abbc'))
... monotonic_index.get_loc('b') slice(1, 3, None)
This example is valid syntax, but we were not able to check execution
>>> non_monotonic_index = pd.Index(list('abcb'))
... non_monotonic_index.get_loc('b') array([False, True, False, True])
See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/indexes/range.py#379
type: <class 'function'>
Commit: