Change language

Python | Pandas Series.clip ()

|

Python 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)

Parameters:
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. 

example
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.

# pandas module import

import pandas as pd 

 
# regex module import

import re

 
# create data frame

data = pd.read_csv ( " https://media.python.engineering/wp-content/uploads/nba.csv "

 
# deleting null values ​​to avoid errors

data.dropna (inplace = True

 
# lower range value

lower = 22

  
# upper range value

upper = 25

 
# passing values ​​to a new column

data [ "New Age" ] = data [ "Age" ]. clip (lower = lower, upper = upper)

 
# display
data

Output:
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.

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

News


Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method