Change language

Python | Pandas dataframe.clip_lower ()

|

Pandas dataframe.clip_lower() is used to trim values ​​at a given input threshold. We use this function to trim all values ​​below the input threshold.

Syntax: DataFrame.clip_lower (threshold, axis = None, inplace = False)

Parameters:
threshold: numeric or array-like
float : every value is compared to threshold .
array-like : The shape of threshold should match the object it’s compared to. When self is a Series, threshold should be the length. When self is a DataFrame, threshold should 2-D and the same shape as self for axis = None, or 1-D and the same length as the axis being compared.
axis: Align self with threshold along the given axis.
inplace: Whether to perform the operation in place on the data.

Returns: clipped: same type as input

Example # 1: Use clip_lower () to trim dataframe values ​​below a given threshold.

Now trim all values ​​below 2 to 2.

# import pandas as pd

import pandas as pd

  
# Create a data frame using a dictionary

df = pd.DataFrame ({ "A" : [ - 5 , 8 , 12 , - 9 , 5 , 3 ],

"B" : [ - 1 , - 4 , 6 , 4 , 11 , 3 ], 

  "C" : [ 11 , 4 , - 8 , 7 , 3 , - 2 ]})

 
# Print data frame for rendering
df

# Trim all values ​​below 2

  df.clip_lower ( 2 )

Output:

Example # 2: Use clip_lower () to clip_lower () values ​​in the data frame with a specific value for each cell of the data frame.

For this purpose we can use an empty array, but the shape of the array must be the same as that of the information frame.

# import pandas as pd

import pandas as pd

 
# Create a data frame using a dictionary

 

df = pd.DataFrame ({ "A " : [ - 5 , 8 , 12 , - 9 , 5 , 3 ], 

"B" : [ - 1 , - 4 , 6 , 4 , 11 3 ],

  "C" : [ 11 , 4 , - 8 , 7 , 3 , - 2 ]})

 
# lower limit for each individual column element.

limit = np.array ([[ 1 , 2 , 3 ], [ 10 , 12 , 3 ], [ 1 , 4 , 3 ],

  [ 1 , 2 , 3 ], [ 1 , 2 , 3 ], [ 1 , 2 , 3 ]])

  
# Print lower_limit
limit

Now apply these restrictions to the data frame.

# apply a different limit
# for each cell in the data frame
df.clip_lower (limit)

Output:

Each cell value has been truncated based on the corresponding lower limit.

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