pandas 1.4.2

ParametersReturns
clip(self: 'NDFrameT', lower=None, upper=None, axis: 'Axis | None' = None, inplace: 'bool_t' = False, *args, **kwargs) -> 'NDFrameT | None'

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.

Parameters

lower : float or array-like, default None

Minimum threshold value. All values below this threshold will be set to it. A missing threshold (e.g :None:None:`NA`) will not clip the value.

upper : float or array-like, default None

Maximum threshold value. All values above this threshold will be set to it. A missing threshold (e.g :None:None:`NA`) will not clip the value.

axis : int or str axis name, optional

Align object with lower and upper along the given axis.

inplace : bool, default False

Whether to perform the operation in place on the data.

*args, **kwargs :

Additional keywords have no effect but might be accepted for compatibility with numpy.

Returns

Series or DataFrame or None

Same type as calling object with the values outside the clip boundaries replaced or None if inplace=True .

Trim values at input threshold(s).

See Also

DataFrame.clip

Trim values at input threshold in dataframe.

Series.clip

Trim values at input threshold in series.

numpy.clip

Clip (limit) the values in an array.

Examples

This example is valid syntax, but we were not able to check execution
>>> data = {'col_0': [9, -3, 0, -1, 5], 'col_1': [-2, -7, 6, 8, -5]}
... df = pd.DataFrame(data)
... df col_0 col_1 0 9 -2 1 -3 -7 2 0 6 3 -1 8 4 5 -5

Clips per column using lower and upper thresholds:

This example is valid syntax, but we were not able to check execution
>>> df.clip(-4, 6)
   col_0  col_1
0      6     -2
1     -3     -4
2      0      6
3     -1      6
4      5     -4

Clips using specific lower and upper thresholds per column element:

This example is valid syntax, but we were not able to check execution
>>> t = pd.Series([2, -4, -1, 6, 3])
... t 0 2 1 -4 2 -1 3 6 4 3 dtype: int64
This example is valid syntax, but we were not able to check execution
>>> df.clip(t, t + 4, axis=0)
   col_0  col_1
0      6      2
1     -3     -4
2      0      3
3      6      8
4      5      3

Clips using specific lower threshold per column element, with missing values:

This example is valid syntax, but we were not able to check execution
>>> t = pd.Series([2, -4, np.NaN, 6, 3])
... t 0 2.0 1 -4.0 2 NaN 3 6.0 4 3.0 dtype: float64
This example is valid syntax, but we were not able to check execution
>>> df.clip(t, axis=0)
col_0  col_1
0      9      2
1     -3     -4
2      0      6
3      6      8
4      5      3
See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/generic.py#7422
type: <class 'function'>
Commit: