pyspark.pandas.Series.clip

Series.clip(lower: Union[float, int] = None, upper: Union[float, int] = None, inplace: bool = False) → pyspark.pandas.series.Series

Trim values at input threshold(s).

Assigns values outside boundary to boundary values.

Parameters
lowerfloat or int, default None

Minimum threshold value. All values below this threshold will be set to it.

upperfloat or int, default None

Maximum threshold value. All values above this threshold will be set to it.

inplacebool, default False

if True, perform operation in-place

Returns
Series

Series with the values outside the clip boundaries replaced

Notes

One difference between this implementation and pandas is that running pd.Series([‘a’, ‘b’]).clip(0, 1) will crash with “TypeError: ‘<=’ not supported between instances of ‘str’ and ‘int’” while ps.Series([‘a’, ‘b’]).clip(0, 1) will output the original Series, simply ignoring the incompatible types.

Examples

>>> psser = ps.Series([0, 2, 4])
>>> psser
0    0
1    2
2    4
dtype: int64
>>> psser.clip(1, 3)
0    1
1    2
2    3
dtype: int64

Clip can be performed in-place.

>>> psser.clip(2, 3, inplace=True)
>>> psser
0    2
1    2
2    3
dtype: int64