Series.clip() is used for
Series.clip() values below and above for passed Least and Max values. This method is used when performing operations such as signal processing. As we know, there are only two values in a digital signal: high or low. Pandas
Series.clip () can be used to restrict a value to a specific range.
Syntax: Series.clip (lower = None, upper = None, axis = None, inplace = False)
lower: Sets Least value of range. Any values below this are made equal to lower.
upper: Sets Max value of range. Any values above this are made equal to upper.
axis: 0 or ’index’ to apply method by rows and 1 or ’columns’ to apply by columns
inplace: Make changes in the caller series itself. (Overwrite with new values)
Return type: Series with updated values
To load the dataset used in the following example, click here.
In the following examples, the data frame used contains data for some NBA players. An image of the data frame before any operations is attached below.
In this example, the
.clip () is called on the Age data column. A minimum value of 22 is passed to the lower parameter and 25 to the upper parameter. The returned streak is then saved in a new column "New Age". Before doing any
.dropna () operations, the lines were
.dropna () with
.dropna () to avoid errors. P >
As shown in the output image, the New Age column has a minimum value of 22 and a maximum value of 25. All values are limited to this range. Values below 22 were made equal to 22, and values above 25 were made equal to 25.