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.
Series.clip_lower() is used to clip values below a passed least value. A threshold value is passed as parameter and all values in series that are less than the threshold values become equal to it.
Syntax: Series.clip_lower(threshold, axis=None, inplace=False)
threshold: numeric or list like, Sets minimum threshold value and in case of list, sets separate threshold values for each value in caller series ( Given list size is same)
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 download the data set used in following example, click here.
In the following examples, the data frame used contains data of some NBA players. The image of data frame before any operations is attached below.
Example #1: Applying on series with single value
In this example, a minimum threshold value of 26 is passed as parameter to .clip_lower() method. This method is called on Age column of the data frame and the new values are stored in Age_new column. Before doing any operations, null rows are dropped using .dropna()
As shown in the Output image, the Age_new column has minimum value of 26. All vales less than 26 were increased to 26 and stored in new column.
Example #2: Applying on series with list type value
In this example, top 10 rows of Age column are extracted and stored using .head() method. After that a list of same length is created and passed to threshold parameter of .clip_lower() method to set separate threshold value for Each value in series. The returned values are stored in a new column ‘clipped_values’.
As shown in the output image, each value in series had a different threshold value according to the passed list and hence the results were returned according to each element’s separate threshold value.
- Python | pandas.map()
- Python | Pandas TimedeltaIndex.name
- Python | Pandas dataframe.ne()
- Python | Pandas dataframe.sub()
- Python | Pandas Series.sem()
- Python | Pandas dataframe.mul()
- Python | Pandas Panel.sum()
- Python | Pandas Series.div()
- Python | Pandas Series.pow()
- Python | Pandas Series.lt()
- Python | Pandas Series.le()
- Python | Pandas Series.ge()
- Python | Pandas Series.ne()
- Python | Pandas Timestamp.day
- Python | Pandas Series.sum()
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.