pandas.api.extensions.ExtensionArray.searchsorted#
- ExtensionArray.searchsorted(value, side='left', sorter=None)[源代码]#
查找应插入元素以维持顺序的索引。
Find the indices into a sorted array self (a) such that, if the corresponding elements in value were inserted before the indices, the order of self would be preserved.
假设 self 是已排序的:
side
返回的索引 i 满足
left
self[i-1] < value <= self[i]right
self[i-1] <= value < self[i]- Parameters:
- value类数组(array-like)、列表或标量
要插入到 self 中的值。
- 侧{‘left’, ‘right’},可选
如果是 ‘left’,则返回找到的第一个合适位置的索引。如果是 ‘right’,则返回最后一个合适位置的索引。如果没有合适的索引,则返回 0 或 N(其中 N 是 self 的长度)。
- sorter一维类数组,可选
可选的整数索引数组,用于将数组 a 排序成升序。它们通常是 argsort 的结果。
- Returns:
- 整数数组或整数
如果 value 是类数组,则返回插入点数组。如果 value 是标量,则返回单个整数。
参见
numpy.searchsortedNumPy 的类似方法。
Examples
>>> arr = pd.array([1, 2, 3, 5]) >>> arr.searchsorted([4]) array([3])