Skip to content

Instantly share code, notes, and snippets.

@critmcdonald
Created September 13, 2017 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save critmcdonald/68ce21cdb49639a5749d2bab71f0f3ea to your computer and use it in GitHub Desktop.
Save critmcdonald/68ce21cdb49639a5749d2bab71f0f3ea to your computer and use it in GitHub Desktop.
I thought you couldn't filter a normalized table in agate, but this example works
import agate
column_names = ['letter', 'number', 'state', 'city']
column_types = [agate.Text(), agate.Number(), agate.Text(), agate.Text()]
rows = [
('a', 1, 'TX', 'Austin'),
('b', 2, 'NY', 'Buffalo'),
('c', None, 'CA', 'Los Angeles')
]
# making tables
table = agate.Table(rows, column_names, column_types)
print('Normal table print:\n')
table.print_table()
print('\nFiltered table print: \n')
table.where(lambda row: row['state'] == "TX").print_table()
normalized = table.normalize(['state', 'city'], ['letter', 'number'])
print('\nnormalized table: \n')
normalized.print_table()
print('\nfiltered normalized table:\n')
normalized.where(lambda row: row['state'] == 'TX').print_table()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment