Skip to content

Commit

Permalink
Use Table.format more in tutorial.
Browse files Browse the repository at this point in the history
  • Loading branch information
onyxfish committed Aug 29, 2015
1 parent a5c4567 commit 07ff7ed
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
40 changes: 24 additions & 16 deletions docs/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -341,16 +341,20 @@ This takes our original :class:`.Table` and groups it into a :class:`.TableSet`,
sorted_totals = totals.order_by('count', reverse=True)
for row in sorted_totals.rows[:5]:
print('%(group)s: %(count)i' % row)
print(sorted_totals.format(max_rows=5))
::
TX: 212
NY: 202
CA: 154
IL: 153
MI: 60
|--------+--------|
| group | count |
|--------+--------|
| TX | 212 |
| NY | 202 |
| CA | 154 |
| IL | 153 |
| MI | 60 |
| ... | ... |
|--------+--------|
Unsurpringly, the results appear roughly proportional to population.
Expand All @@ -374,18 +378,22 @@ This is a much more complicated question that's going to pull together a lot of
sorted_medians = medians.order_by('median_years_in_prison', reverse=True)
for row in sorted_medians.rows[:5]:
print('%(group)s: %(median_years_in_prison)i' % row)
print(sorted_medians.format(max_rows=5))
::
DC: 27
NE: 20
ID: 19
VT: 18
LA: 16
DC? Nebraska? Idaho? What accounts for these states having the longest times in prison before exoneration? I have no idea and the data won't tell us. At this point you probably need to make some phone calls.
|--------+-------+-------------------------|
| group | count | median_years_in_prison |
|--------+-------+-------------------------|
| DC | 15 | 27 |
| NE | 9 | 20 |
| ID | 2 | 19 |
| VT | 1 | 18 |
| LA | 45 | 16 |
| ... | ... | ... |
|--------+-------+-------------------------|
DC? Nebraska? What accounts for these states having the longest times in prison before exoneration? I have no idea. Given that the group sizes are small, it would probably be wise to look for outliers.
As with :meth:`.Table.aggregate` and :meth:`.Table.compute`, the :meth:`.TableSet.aggregate`: method takes a list of aggregations to perform. You can aggregate as many columns as you like in a single step and they will all appear in the output table.
Expand Down
7 changes: 2 additions & 5 deletions exonerations.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ def load_data(data):
# Create the table
data['exonerations'] = agate.Table(reader, columns)

print(data['exonerations'].format(3, 3))

def confessions(data):
num_false_confessions = data['exonerations'].columns['false_confession'].aggregate(agate.Count(True))

Expand Down Expand Up @@ -74,8 +72,7 @@ def states(data):

sorted_medians = medians.order_by('median_years_in_prison', reverse=True)

for row in sorted_medians.rows[:5]:
print('%(group)s: %(median_years_in_prison)i' % row)
print(sorted_medians.format(max_rows=5))


analysis = agate.Analysis(load_data)
Expand All @@ -86,4 +83,4 @@ def states(data):
years_analysis = analysis.then(years_in_prison)
years_analysis.then(states)

analysis.run(refresh=True)
analysis.run()

0 comments on commit 07ff7ed

Please sign in to comment.