Python | Панды dataframe.clip_lower ()
Python - отличный язык для анализа данных, в первую очередь из-за фантастической экосистемы пакетов Python, ориентированных на данные. Pandas - один из таких пакетов, который значительно упрощает импорт и анализ данных.
Pandas 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)
Parameters:
threshold : numeric or array-likefloat: 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.
# importing pandas as pdimport pandas as pd # Creating a dataframe using dictionarydf = pd.DataFrame({"A":[-5, 8, 12, -9, 5, 3], "B":[-1, -4, 6, 4, 11, 3], "C":[11, 4, -8, 7, 3, -2]}) # Printing the data frame for visualizationdf |

Now trim all the values below 2 to 2.
# Clip all values below 2df.clip_lower(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.
# importing pandas as pdimport pandas as pd # Creating a dataframe using 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_limitlimit |

Now apply these limits on the dataframe
# applying different limit value # for each cell in the dataframedf.clip_lower(limit) |
Выход :
Значение каждой ячейки было обрезано на основе соответствующего нижнего предела.
Внимание компьютерщик! Укрепите свои основы с помощью базового курса программирования Python и изучите основы.
Для начала подготовьтесь к собеседованию. Расширьте свои концепции структур данных с помощью курса Python DS. А чтобы начать свое путешествие по машинному обучению, присоединяйтесь к курсу Машинное обучение - базовый уровень.