Python | Pandas dataframe.clip_lower()
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.
dataframe.clip_lower() is used to trim values at specified input threshold. We use this function to trim all the values below the threshold of the input value.
Syntax: DataFrame.clip_lower(threshold, axis=None, inplace=False)
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() function to trim values of a data frame below a given threshold value.
Now trim all the values below 2 to 2.
Example #2: Use
clip_lower() function to clips values in a dataframe with specific value for each cell of the dataframe.
For this purpose, we can use a numpy array, but the shape of array must be same as that of the dataframe.
Now apply these limits on the dataframe
Each cell value has been trimmed based on the corresponding lower limit applied.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course