@@ -6110,53 +6110,79 @@ def clip(self, lower=None, upper=None, axis=None, inplace=False,
61106110 """
61116111 Trim values at input threshold(s).
61126112
6113+ Assigns values outside boundary to boundary values. Thresholds
6114+ can be singular values or array like, and in the latter case
6115+ the clipping is performed element-wise in the specified axis.
6116+
61136117 Parameters
61146118 ----------
61156119 lower : float or array_like, default None
6120+ Minimum threshold value. All values below this
6121+ threshold will be set to it.
61166122 upper : float or array_like, default None
6123+ Maximum threshold value. All values above this
6124+ threshold will be set to it.
61176125 axis : int or string axis name, optional
61186126 Align object with lower and upper along the given axis.
61196127 inplace : boolean, default False
6120- Whether to perform the operation in place on the data
6121- .. versionadded:: 0.21.0
6128+ Whether to perform the operation in place on the data.
6129+
6130+ .. versionadded:: 0.21.0
6131+ *args, **kwargs
6132+ Additional keywords have no effect but might be accepted
6133+ for compatibility with numpy.
6134+
6135+ See Also
6136+ --------
6137+ clip_lower : Clip values below specified threshold(s).
6138+ clip_upper : Clip values above specified threshold(s).
61226139
61236140 Returns
61246141 -------
6125- clipped : Series
6142+ Series or DataFrame
6143+ Same type as calling object with the values outside the
6144+ clip boundaries replaced
61266145
61276146 Examples
61286147 --------
6148+ >>> data = {'col_0': [9, -3, 0, -1, 5], 'col_1': [-2, -7, 6, 8, -5]}
6149+ >>> df = pd.DataFrame(data)
61296150 >>> df
6130- 0 1
6131- 0 0.335232 -1.256177
6132- 1 -1.367855 0.746646
6133- 2 0.027753 -1.176076
6134- 3 0.230930 -0.679613
6135- 4 1.261967 0.570967
6136-
6137- >>> df.clip(-1.0, 0.5)
6138- 0 1
6139- 0 0.335232 -1.000000
6140- 1 -1.000000 0.500000
6141- 2 0.027753 -1.000000
6142- 3 0.230930 -0.679613
6143- 4 0.500000 0.500000
6144-
6151+ col_0 col_1
6152+ 0 9 -2
6153+ 1 -3 -7
6154+ 2 0 6
6155+ 3 -1 8
6156+ 4 5 -5
6157+
6158+ Clips per column using lower and upper thresholds:
6159+
6160+ >>> df.clip(-4, 6)
6161+ col_0 col_1
6162+ 0 6 -2
6163+ 1 -3 -4
6164+ 2 0 6
6165+ 3 -1 6
6166+ 4 5 -4
6167+
6168+ Clips using specific lower and upper thresholds per column element:
6169+
6170+ >>> t = pd.Series([2, -4, -1, 6, 3])
61456171 >>> t
6146- 0 -0.3
6147- 1 -0.2
6148- 2 -0. 1
6149- 3 0.0
6150- 4 0.1
6151- dtype: float64
6172+ 0 2
6173+ 1 -4
6174+ 2 -1
6175+ 3 6
6176+ 4 3
6177+ dtype: int64
61526178
6153- >>> df.clip(t, t + 1 , axis=0)
6154- 0 1
6155- 0 0.335232 -0.300000
6156- 1 -0.200000 0.746646
6157- 2 0.027753 -0.100000
6158- 3 0.230930 0.000000
6159- 4 1.100000 0.570967
6179+ >>> df.clip(t, t + 4 , axis=0)
6180+ col_0 col_1
6181+ 0 6 2
6182+ 1 -3 -4
6183+ 2 0 3
6184+ 3 6 8
6185+ 4 5 3
61606186 """
61616187 if isinstance (self , ABCPanel ):
61626188 raise NotImplementedError ("clip is not supported yet for panels" )
0 commit comments