Skip to main content

DB_Table.filter

filtercolumnfilter on_problems

Group: Selections
Aliases: filter rows, where

Documentation

Selects only the rows of this table that correspond to True values of filter.

Arguments

  • column: The column to use for filtering. Can be a column name, index or the Column object itself.
  • filter: The filter to apply to the column. It can either be an instance of Filter_Condition or a predicate taking a cell value and returning a boolean value indicating whether the corresponding row should be kept or not.
  • on_problems: Specifies how to handle if a non-fatal problem occurs, attaching a warning by default.

Examples

Get people older than 30.

      people.filter "Age" (Greater 30)

Filter people between 30 and 40.

      people.filter "Age" (Between 30 40)

Select rows where more than 50% of the stock is sold.

      table.filter "sold_stock" (Greater (table.at "total_stock" / 2))

Select people celebrating a jubilee.

      people.filter "age" (age -> (age%10 == 0))

Errors

  • If a column name cannot be found, a No_Such_Column dataflow error is raised.
  • If a column index is invalid, an Index_Out_Of_Bounds dataflow error is raised.
  • If the column is an invalid type for the filter, an Invalid_Value_Type dataflow error is raised.
  • Additionally, the following problems may be reported according to the on_problems setting:
    • If filtering by equality on a floating-point column, a Floating_Point_Equality.