Table.filter
filtercolumnfilter on_problems
Group: Selections
Aliases: filter rows, where
Documentation
Filter is used to select data from a table using a condition. The rows that meet the condition will remain after the filter. Filters can compare columns, compare against static values, or compare against an argument from another component.
action: This can be set toKeep, which keeps all rows which meet the condition. It can also be set toRemove, which will instead only keep the rows that do not meet the condition. For example,[people] Is Nullwould keep all the rows where the columnpeoplehad a Null value. Changing this toRemovewould remove all of the rows wherepeoplehad a Null value, leaving only the records that are not null. -on_problems: specified how to report any issues encountered during the operation.
Arguments
column: The column our condition is tested against. This can be a column name, the column's index or an expression.filter: The filter to apply to the column. It can either be an instance ofFilter_Conditionor a predicate taking a cell value and returning a boolean value indicating whether the corresponding row should be kept or not.
Returns
- Returns a Table of all of the rows that met the specified condition.
Examples
Filter where an Age is Greater than 30.
table1 = Table.new [['Name', ['John', 'Paul', 'Ringo']], ['Age', [25, 35, 40]]]
filter1 = table1.filter 'Age' (..Greater 30)
Returns a Table
| Name | Age |
|---|---|
| Paul | 35 |
| Ringo | 40 |
Filter where an Age is Between 30 and 39.
table1 = Table.new [['Name', ['John', 'Paul', 'Ringo']], ['Age', [25, 35, 40]]]
filter1 = table1.filter 'Age' (..Between 30 39)
Returns a Table
| Name | Age |
|---|---|
| Paul | 35 |
Select rows where more than 50% of the stock is sold.
table2 = Table.new [['Name', ['John', 'Paul']], ['sold_stock', [20, 30]], ['total_stock', [50, 50]]]
filter3= table2.filter 'sold_stock' (..Greater (expr '[total_stock]/2'))
Returns a Table
| Name | sold_stock | total_stock |
|---|---|---|
| Paul | 30 | 50 |
Select people celebrating a jubilee.
table3 = Table.new [['Name', ['John', 'Paul', 'Ringo']], ['Age', [25, 35, 40]]]
filter4 = table3.filter (expr '[Age] % 10 = 0') ..Is_True
Returns a Table
| Name | Age |
|---|---|
| Ringo | 40 |
Errors
- If a column name cannot be found, a
No_Such_Columndataflow error is raised. - If a column index is invalid, an
Index_Out_Of_Boundsdataflow error is raised. - If the column is an invalid type for the filter, an
Invalid_Value_Typedataflow error is raised. - Additionally, the following problems may be reported according to the
on_problemssetting:- If filtering by equality on a floating-point column, a
Floating_Point_Equalitywill warn the user that comparing floats is imprecise, so results may be inconsistent.
- If filtering by equality on a floating-point column, a
Remarks
Nothing Equality
When comparing Nothing values, filter follows the ANSI SQL conventions
that Nothing == Nothing results in a Nothing. This includes both
Equal and Is_In conditions. If you want to filter out Nothing use
Is_Not_Nothing condition (or Is_Nothing to filter out non-Nothing).