Import agate, python based data analysis


In [1]:
import agate

In [2]:
wells97 = agate.Table.from_csv('wells1997.csv')
wells02 = agate.Table.from_csv('wells2002.csv')
wells07 = agate.Table.from_csv('wells2007.csv')
wells12 = agate.Table.from_csv('wells2012.csv')
def upperCase(row):
    return row['Countyname'].upper()
clean_well97 = wells97.compute([
        ('clean_County', agate.Formula(agate.Text(), upperCase))
]).select(['clean_County', 'Wells'])
clean_well02 = wells02.compute([
        ('clean_County', agate.Formula(agate.Text(), upperCase))
]).select(['clean_County', 'Wells'])
clean_well07 = wells07.compute([
        ('clean_County', agate.Formula(agate.Text(), upperCase))
]).select(['clean_County', 'Wells'])
clean_well12 = wells12.compute([
        ('clean_County', agate.Formula(agate.Text(), upperCase))
]).select(['clean_County', 'Wells'])

In [3]:
print(clean_well97)


|---------------+---------------|
|  column_names | column_types  |
|---------------+---------------|
|  clean_County | Text          |
|  Wells        | Number        |
|---------------+---------------|


In [4]:
acres97 = agate.Table.from_csv('irrigatedAcres1997.csv')
acres02 = agate.Table.from_csv('irrigatedAcres2002.csv')
acres07 = agate.Table.from_csv('irrigatedAcres2007.csv')
acres12 = agate.Table.from_csv('irrigatedAcres2012.csv')

In [5]:
print(acres97)
acres97.print_table(10)


|-----------------+---------------|
|  column_names   | column_types  |
|-----------------+---------------|
|  Year           | Date          |
|  County         | Text          |
|  IrrigatedAcres | Number        |
|-----------------+---------------|

|-------------+---------+-----------------|
|        Year | County  | IrrigatedAcres  |
|-------------+---------+-----------------|
|  1997-01-01 | BUFFALO |        213,778  |
|  1997-01-01 | CUSTER  |        197,726  |
|  1997-01-01 | DAWSON  |        222,075  |
|  1997-01-01 | GREELEY |         57,413  |
|  1997-01-01 | HALL    |        181,222  |
|  1997-01-01 | HOWARD  |        111,342  |
|  1997-01-01 | SHERMAN |         59,487  |
|  1997-01-01 | VALLEY  |         73,340  |
|  1997-01-01 | BUTLER  |         97,543  |
|  1997-01-01 | COLFAX  |         53,059  |
|         ... | ...     |            ...  |
|-------------+---------+-----------------|

In [6]:
total97 = clean_well97.join(acres97, 'clean_County', 'County', inner=True)
print(len(total97.rows))
total97.to_csv('wells_acres97.csv')

total02 = clean_well02.join(acres02, 'clean_County', 'County', inner=True)
print(len(total02.rows))
total02.to_csv('wells_acres02.csv')

total07 = clean_well07.join(acres07, 'clean_County', 'County', inner=True)
print(len(total07.rows))
total07.to_csv('wells_acres07.csv')

total12 = clean_well12.join(acres12, 'clean_County', 'County', inner=True)
print(len(total12.rows))
total12.to_csv('wells_acres12.csv')


91
93
93
93

In [ ]: