Skip to content

LazyColumn.clip

clip

clip(lower: Any = None, upper: Any = None) -> LazyColumn

Trim values at specified thresholds.

Parameters:

Name Type Description Default
lower Any

Minimum threshold value. All values below this will be set to this value. If None, no lower threshold will be applied. Defaults to None.

None
upper Any

Maximum threshold value. All values above this will be set to this value. If None, no upper threshold will be applied. Defaults to None.

None

Returns:

Name Type Description
LazyColumn LazyColumn

A new LazyColumn with values trimmed to specified thresholds.

Examples:

print(df.head())
#    col1  my_column_to_test
# 0     1                  2
# 1     2                  3
# 2     3                  5
# 3     4                  8
# 4     5                 10

# Clip values between 3 and 7
df["my_column_to_test"].clip(3, 7)
# [3, 3, 5, 7, 7]

# Clip only lower values at 4
df["my_column_to_test"].clip(lower=4)
# [4, 4, 5, 8, 10]

# Clip only upper values at 6
df["my_column_to_test"].clip(upper=6)
# [2, 3, 5, 6, 6]