Exemplo n.º 1
0
with open('examples/realdata/Datagov_FY10_EDU_recp_by_State.csv') as f:
    # Skip headers
    f.next()
    f.next()
    f.next()

    rows = list(csv.reader(f))

# Trim cruft off end
rows = rows[:-2]

table = Table(rows, COLUMN_TYPES, COLUMN_NAMES, cast=True)

print 'Total of all states: %i' % table.columns['total'].sum()

sort_by_total_desc = table.sort_by('total', reverse=True)

top_five = sort_by_total_desc.rows[0:5]

for i, row in enumerate(top_five):
    print '# %i: %s %i' % (i, row['state'], row['total'])

last_place = sort_by_total_desc.rows[-1]

print 'Lowest state: %(state)s %(total)i' % (last_place)

stdev = table.columns['total'].stdev()

print 'Standard deviation of totals: %.2f' % stdev