w3resource

Pandas DataFrame: clip() function

DataFrame - clip() function

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.

Syntax:

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

Parameters:

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
Required
upper    Maximum threshold value. All values above this threshold will be set to it. float or array_like
Default Value: None
Required
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
Required
*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.

Example:


Download the Pandas DataFrame Notebooks from here.

Previous: DataFrame - any() function
Next: DataFrame - corr() function



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/pandas/dataframe/dataframe-clip.php