cudf.Series.clip#

Series.clip(lower=None, upper=None, inplace=False, axis=1)#

Trim values at input threshold(s).

Assigns values outside boundary to boundary values. Thresholds can be singular values or array like, and in the latter case the clipping is performed element-wise in the specified axis. Currently only axis=1 is supported.

Parameters:
lowerscalar or array_like, default None

Minimum threshold value. All values below this threshold will be set to it. If it is None, there will be no clipping based on lower. In case of Series/Index, lower is expected to be a scalar or an array of size 1.

upperscalar or array_like, default None

Maximum threshold value. All values below this threshold will be set to it. If it is None, there will be no clipping based on upper. In case of Series, upper is expected to be a scalar or an array of size 1.

inplacebool, default False
Returns:
Clipped DataFrame/Series/Index/MultiIndex

Examples

>>> import cudf
>>> df = cudf.DataFrame({"a":[1, 2, 3, 4], "b":['a', 'b', 'c', 'd']})
>>> df.clip(lower=[2, 'b'], upper=[3, 'c'])
   a  b
0  2  b
1  2  b
2  3  c
3  3  c
>>> df.clip(lower=None, upper=[3, 'c'])
   a  b
0  1  a
1  2  b
2  3  c
3  3  c
>>> df.clip(lower=[2, 'b'], upper=None)
   a  b
0  2  b
1  2  b
2  3  c
3  4  d
>>> df.clip(lower=2, upper=3, inplace=True)
>>> df
   a  b
0  2  2
1  2  3
2  3  3
3  3  3
>>> import cudf
>>> sr = cudf.Series([1, 2, 3, 4])
>>> sr.clip(lower=2, upper=3)
0    2
1    2
2    3
3    3
dtype: int64
>>> sr.clip(lower=None, upper=3)
0    1
1    2
2    3
3    3
dtype: int64
>>> sr.clip(lower=2, upper=None, inplace=True)
>>> sr
0    2
1    2
2    3
3    4
dtype: int64