dataframe.clip_upper() is used to trim values at a specified input threshold. We use this function to trim all values above the input threshold to the specified input.
Syntax: DataFrame.clip_upper (threshold, axis = None, inplace = False)
threshold: float 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 object 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_upper () to trim dataframe values above a given threshold.
Example # 2: Use
clip_upper () to
clip_upper () 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.
Now apply these restrictions to the data frame.
Each cell value has been cropped based on the corresponding upper applied limit.