Pandas: Series - clip() function

Trim values at input in Pandas

The clip() function is used to 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.


Series.clip(self, lower=None, upper=None, axis=None, inplace=False, *args, **kwargs)
Pandas Series clip image


Name Description Type/Default Value Required / Optional
lower Minimum threshold value. All values below this threshold will be set to it. float or array_like
Default Value: None
upper Maximum threshold value. All values above this threshold will be set to it. float or array_like
Default Value : None
axis Align object with lower and upper along the given axis. int or str axis name Optional
inplace Whether to perform the operation in place on the data. bool
Default Value : False
*args, **kwargs Additional keywords have no effect but might be accepted for compatibility with numpy. Required

Returns: Series or DataFrame
Same type as calling object with the values outside the clip boundaries replaced.


Download the Pandas Series Notebooks from here.

Previous: Boolean Series in Pandas
Next: Compute correlation