Emulate underscore.js

filter

agate’s Table.where() functions exactly like Underscore’s filter.

new_table = table.where(lambda row: row['state'] == 'Texas')

reject

To simulate Underscore’s reject, simply negate the return value of the function you pass into agate’s Table.where().

new_table = table.where(lambda row: not (row['state'] == 'Texas'))

find

agate’s Table.find() works exactly like Undrescore’s find.

row = table.find(lambda row: row['state'].startswith('T'))

any

agate’s columns have an Column.any() method that functions like Underscore’s any.

true_or_false = table.columns['salaries'].any(lambda d: d > 100000)

You can also use Table.where() to filter to columns that pass the truth test.

all

agate’s columns have an Column.all() method that functions like Underscore’s all.

true_or_false = table.columns['salaries'].all(lambda d: d > 100000)

You can also use Table.where() to filter to columns that pass the truth test.