Skip to content

LazyColumn.between

between

between(
    left: Any,
    right: Any,
    inclusive: Literal[
        "both", "neither", "left", "right"
    ] = "both",
) -> LazyColumn

Returns boolean values indicating whether each element is between two values, with optional inclusiveness.

Similar to pandas.Series.between. The inclusive parameter can be: - "both": includes lower (left) and upper (right) bounds. - "neither": excludes both bounds. - "left": includes only the lower bound (left). - "right": includes only the upper bound (right).

Parameters:

Name Type Description Default
left Any

Lower bound value.

required
right Any

Upper bound value.

required
inclusive Literal['both', 'neither', 'left', 'right']

Defines whether bounds should be included or excluded. Defaults to "both".

'both'

Returns:

Name Type Description
LazyColumn LazyColumn

A new LazyColumn of boolean values where True indicates that the value is between the specified bounds and False otherwise.

Raises:

Type Description
ValueError

If the inclusive parameter is given an invalid value.

Examples:

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

# Between 3 and 8 (inclusive of both bounds)
df["my_column_to_test"].between(3, 8)
# [False, True, True, True, False]

# Excluding both bounds
df["my_column_to_test"].between(3, 8, inclusive="neither")
# [False, False, True, False, False]

# Including only the lower bound
df["my_column_to_test"].between(3, 8, inclusive="left")
# [False, True, True, False, False]

# Including only the upper bound
df["my_column_to_test"].between(3, 8, inclusive="right")
# [False, False, True, True, False]