Skip to main content
Version: Python

where

The where method filters rows of data from the source table.

note

The engine will address filters in series, consistent with the ordering of arguments. It is best practice to place filters related to partitioning and grouping columns first, as significant data volumes can then be excluded. Additionally, match filters are highly optimized and should usually come before conditional filters.

Syntax

table.where(filters=[filterCriteria...])

Parameters

ParameterTypeDescription
filtersarray

Formulas for filtering as a list of Strings.

Filters can be:

  • A match filter.
  • A conditional filter. This may be a custom boolean function.

Returns

A new table with only the rows meeting the filter criteria in the column(s) of the source table.

Examples

The following example returns rows where Color is blue.

from deephaven import new_table
from deephaven.column import string_col, int_col, double_col
from deephaven.constants import NULL_INT

source = new_table([
string_col("Letter", ["A", "C", "F", "B", "E", "D", "A"]),
int_col("Number", [NULL_INT, 2, 1, NULL_INT, 4, 5, 3]),
string_col("Color", ["red", "blue", "orange", "purple", "yellow", "pink", "blue"]),
int_col("Code", [12, 14, 11, NULL_INT, 16, 14, NULL_INT]),
])


result = source.where(filters=["Color = `blue`"])

The following example returns rows where Number is greater than 3.

from deephaven import new_table
from deephaven.column import string_col, int_col, double_col
from deephaven.constants import NULL_INT
source = new_table([
string_col("Letter", ["A", "C", "F", "B", "E", "D", "A"]),
int_col("Number", [NULL_INT, 2, 1, NULL_INT, 4, 5, 3]),
string_col("Color", ["red", "blue", "orange", "purple", "yellow", "pink", "blue"]),
int_col("Code", [12, 14, 11, NULL_INT, 16, 14, NULL_INT]),

])

result = source.where(filters=["Number > 3"])

The following returns rows where Color is blue and Number is greater than 3.

from deephaven import new_table
from deephaven.column import string_col, int_col, double_col
from deephaven.constants import NULL_INT

source = new_table([
string_col("Letter", ["A", "C", "F", "B", "E", "D", "A"]),
int_col("Number", [NULL_INT, 2, 1, NULL_INT, 4, 5, 3]),
string_col("Color", ["red", "blue", "orange", "purple", "yellow", "pink", "blue"]),
int_col("Code", [12, 14, 11, NULL_INT, 16, 14, NULL_INT]),
])
result = source.where(filters=["Color = `blue`", "Number > 3"])

The following returns rows where Color is blue or Number is greater than 3.

from deephaven import new_table
from deephaven.column import string_col, int_col, double_col
from deephaven.constants import NULL_INT

source = new_table([
string_col("Letter", ["A", "C", "F", "B", "E", "D", "A"]),
int_col("Number", [NULL_INT, 2, 1, NULL_INT, 4, 5, 3]),
string_col("Color", ["red", "blue", "orange", "purple", "yellow", "pink", "blue"]),
int_col("Code", [12, 14, 11, NULL_INT, 16, 14, NULL_INT]),
])


result = source.where_one_of(filters=["Color = `blue`", "Number > 3"])

The following shows how to apply a custom function as a filter. Take note that the function call must be explicitly cast to a (boolean).

from deephaven import new_table
from deephaven.column import int_col
def my_filter(int_):
return int_ <= 4
source = new_table([
int_col("IntegerColumn", [1, 2, 3, 4, 5, 6, 7, 8])

])

result_filtered = source.where(filters=["(boolean)my_filter(IntegerColumn)"])
result_not_filtered = source.where(filters=["!((boolean)my_filter(IntegerColumn))"])