@@ -6110,53 +6110,79 @@ def clip(self, lower=None, upper=None, axis=None, inplace=False,
6110
6110
"""
6111
6111
Trim values at input threshold(s).
6112
6112
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
+
6113
6117
Parameters
6114
6118
----------
6115
6119
lower : float or array_like, default None
6120
+ Minimum threshold value. All values below this
6121
+ threshold will be set to it.
6116
6122
upper : float or array_like, default None
6123
+ Maximum threshold value. All values above this
6124
+ threshold will be set to it.
6117
6125
axis : int or string axis name, optional
6118
6126
Align object with lower and upper along the given axis.
6119
6127
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).
6122
6139
6123
6140
Returns
6124
6141
-------
6125
- clipped : Series
6142
+ Series or DataFrame
6143
+ Same type as calling object with the values outside the
6144
+ clip boundaries replaced
6126
6145
6127
6146
Examples
6128
6147
--------
6148
+ >>> data = {'col_0': [9, -3, 0, -1, 5], 'col_1': [-2, -7, 6, 8, -5]}
6149
+ >>> df = pd.DataFrame(data)
6129
6150
>>> 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])
6145
6171
>>> 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
6152
6178
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
6160
6186
"""
6161
6187
if isinstance (self , ABCPanel ):
6162
6188
raise NotImplementedError ("clip is not supported yet for panels" )
0 commit comments