pyspark.pandas.Series.searchsorted#

Series.searchsorted(value, side='left')[source]#

Find indices where elements should be inserted to maintain order.

Find the indices into a sorted Series self such that, if the corresponding elements in value were inserted before the indices, the order of self would be preserved.

New in version 3.4.0.

Parameters
valuescalar

Values to insert into self.

side{‘left’, ‘right’}, optional

If ‘left’, the index of the first suitable location found is given. If ‘right’, return the last such index. If there is no suitable index, return either 0 or N (where N is the length of self).

Returns
int

insertion point

Notes

The Series must be monotonically sorted, otherwise wrong locations will likely be returned.

Examples

>>> ser = ps.Series([1, 2, 2, 3])
>>> ser.searchsorted(0)
0
>>> ser.searchsorted(1)
0
>>> ser.searchsorted(2)
1
>>> ser.searchsorted(5)
4
>>> ser.searchsorted(0, side="right")
0
>>> ser.searchsorted(1, side="right")
1
>>> ser.searchsorted(2, side="right")
3
>>> ser.searchsorted(5, side="right")
4