Created
September 13, 2017 12:44
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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