Import agate, python based data analysis
In [1]:
import agate
In [33]:
date = agate.Date()
tester = agate.TypeTester(force = {
'Year': date,
}, limit=100)
acres = agate.Table.from_csv('irrigatedAcres97-12.csv', column_types=tester)
In [34]:
print(acres)
In [35]:
acres.print_table(1)
In [36]:
irrigated_acres = acres.where(lambda row: row['Year'].year == 2012)
print(len(irrigated_acres.rows))
The years in the array were chosen due to the USDA ag census was conducted on those dates. Therefore, this program loops through each year in the array, finds the irrigation acres in that year, and chooses the total field in the Domain column. Finally, the counties' total irrigated acres are exported in a csv file. Two counties were removed from the 1997 data because they had no total value for that year.
In [42]:
years = [1997, 2002, 2007, 2012]
for year in years:
print("Begin {0} irrigated acres analysis".format(year))
irrigated_acres = acres.where(lambda row: row['Year'].year == year)
totals = irrigated_acres.where(lambda row: row['Domain'] == 'TOTAL')
clean_totals = totals.where(lambda row: row['Value'] != '(D)')
print("Number of counties included {0}".format(len(clean_totals.rows)))
print_table = clean_totals.select(['Year', 'County', 'Value'])
irrigation_counts = print_table.rename(column_names = ['Year','County', 'IrrigatedAcres'])
print_table.print_table(10)
irrigation_counts.to_csv('irrigatedAcres{0}.csv'.format(year))
In [ ]: