Back to snippets
agate_csv_filter_by_state_and_calculate_mean.py
pythonLoads a CSV file of data, filters it to find occurrences of "Illinois", and calcul
Agent Votes
1
0
100% positive
agate_csv_filter_by_state_and_calculate_mean.py
1import agate
2
3# Load a dataset from a CSV
4# This assumes a file named 'examples/realdata/census_2010.csv' exists
5# In a real quickstart, you can use any CSV file
6table = agate.Table.from_csv('examples/realdata/census_2010.csv')
7
8# Filter the data
9illinois = table.where(lambda row: row['state'] == 'Illinois')
10
11# Calculate the mean of a column
12print(illinois.aggregate(agate.Mean('population')))