Need to import agate before starting


In [23]:
import agate

Create agate Table from Leaking tanks csv file


In [24]:
spills = agate.Table.from_csv('fliteredlustclean.csv')

Check out column names & types from salaries table


In [25]:
print(spills)


|--------------------------------------+---------------|
|  column_names                        | column_types  |
|--------------------------------------+---------------|
|  SPILLNO-------                      | Text          |
|  S                                   | Text          |
|  OWNCO--------------------           | Text          |
|  OWNSTREET-----------                | Text          |
|  OWNCITY-------------                | Text          |
|  OS                                  | Text          |
|  OZIP                                | Text          |
|  TY                                  | Number        |
|  DIDATE----                          | Date          |
|  SPLOC     ------------------------- | Text          |
|  SPCITY-------------------           | Text          |
|  SPCOUN-------------------           | Text          |
|  MATERIAL----------------------      | Text          |
|  SFM_ID--                            | Text          |
|  FAC_NAME-----------------           | Text          |
|--------------------------------------+---------------|

Let's group by owner


In [26]:
by_owner = spills.group_by('OWNCO--------------------')

Let's see owners totals


In [27]:
owner_totals = by_owner.aggregate([
        ('count', agate.Length())
    ])

Let's find the worst offenders


In [28]:
sorted_totals = owner_totals.order_by('count', reverse=True)

Print the top 20 offenders


In [29]:
sorted_totals.print_table(max_rows=20)


|----------------------------+--------|
|  OWNCO-------------------- | count  |
|----------------------------+--------|
|                            |   109  |
|  UNKNOWN                   |    63  |
|  BURLINGTON NORTHERN & SFR |    14  |
|  ORPHAN UST                |    11  |
|  UPRR                      |     8  |
|  BENSON 66 SERVICE INC     |     8  |
|  WHITEHEAD OIL CO          |     7  |
|  BOSSELMAN INC             |     6  |
|  OFFUTT A F B              |     6  |
|  BNSF RAILWAY CO           |     6  |
|  CITY OF OMAHA             |     5  |
|  BENSON 66                 |     5  |
|  ARMY CORPS OF ENGINEERS   |     5  |
|  CASEYS GENERAL STORES     |     4  |
|  RITEWAY OIL & GAS CO INC  |     4  |
|  ORPHAN TANKS              |     4  |
|  NEBR DEPT OF ROADS        |     4  |
|  CITY OF LINCOLN           |     3  |
|  CENTRAL VALLEY AG COOP    |     3  |
|  MILDER OIL                |     3  |
|  ...                       |   ...  |
|----------------------------+--------|

In [ ]: