In [2]:
from __future__ import absolute_import, division, print_function, unicode_literals

import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline

In [4]:
csos = pd.read_csv('data/merged_cso_data.csv')
csos.head()


Out[4]:
Outfall Structure Outfall Location Tide Gate # Waterway Reach Plant Open date/time Close date/time Gate Open Period
0 DS-N05 Forest Glen Ave (S), West of Cicero TG1 NBCR Upper (NSC Confluence) Stickney 2016-04-01 17:54:00 2016-04-01 23:07:00 0 days 05:13:48.000000000
1 DS-N08 Mango Ave ext. (Leonard & Miltmore) (W) TG1 NBCR Upper (NSC Confluence) Stickney 2016-04-01 17:53:00 2016-04-01 19:42:00 0 days 01:48:55.000000000
2 DS-N10B Imlay St & Milwaukee (W) TG1 NBCR Upper (NSC Confluence) Stickney 2016-04-01 18:10:00 2016-04-01 18:26:00 0 days 00:16:08.000000000
3 DS-N08 Mango Ave ext. (Leonard & Miltmore) (W) TG1 NBCR Upper (NSC Confluence) Stickney 2016-04-01 17:53:00 2016-04-01 19:42:00 0 days 01:48:55.000000000
4 DS-N05 Forest Glen Ave (S), West of Cicero TG1 NBCR Upper (NSC Confluence) Stickney 2016-04-01 17:54:00 2016-04-01 23:07:00 0 days 05:13:48.000000000

In [7]:
csos['Open date/time'] = pd.to_datetime(csos['Open date/time'])
csos['Close date/time'] = pd.to_datetime(csos['Close date/time'])
csos.dtypes


Out[7]:
Outfall Structure            object
Outfall Location             object
Tide Gate #                  object
Waterway Reach               object
Plant                        object
Open date/time       datetime64[ns]
Close date/time      datetime64[ns]
Gate Open Period             object
dtype: object

In [9]:
csos['Duration'] = csos['Close date/time'] - csos['Open date/time']
csos.head()


Out[9]:
Outfall Structure Outfall Location Tide Gate # Waterway Reach Plant Open date/time Close date/time Gate Open Period Duration
0 DS-N05 Forest Glen Ave (S), West of Cicero TG1 NBCR Upper (NSC Confluence) Stickney 2016-04-01 17:54:00 2016-04-01 23:07:00 0 days 05:13:48.000000000 05:13:00
1 DS-N08 Mango Ave ext. (Leonard & Miltmore) (W) TG1 NBCR Upper (NSC Confluence) Stickney 2016-04-01 17:53:00 2016-04-01 19:42:00 0 days 01:48:55.000000000 01:49:00
2 DS-N10B Imlay St & Milwaukee (W) TG1 NBCR Upper (NSC Confluence) Stickney 2016-04-01 18:10:00 2016-04-01 18:26:00 0 days 00:16:08.000000000 00:16:00
3 DS-N08 Mango Ave ext. (Leonard & Miltmore) (W) TG1 NBCR Upper (NSC Confluence) Stickney 2016-04-01 17:53:00 2016-04-01 19:42:00 0 days 01:48:55.000000000 01:49:00
4 DS-N05 Forest Glen Ave (S), West of Cicero TG1 NBCR Upper (NSC Confluence) Stickney 2016-04-01 17:54:00 2016-04-01 23:07:00 0 days 05:13:48.000000000 05:13:00

In [29]:
outfall_cumulative = pd.DataFrame(csos.groupby(by=['Outfall Structure'])['Duration'].sum().sort_values(ascending=False))
outfall_cumulative.dtypes


Out[29]:
Duration    timedelta64[ns]
dtype: object

In [30]:
outfall_cumulative['Duration_mins'] = outfall_cumulative['Duration'].days
outfall_total_duration.update(outfall_total_duration.days)


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-30-f1f6a3c59c16> in <module>()
----> 1 outfall_cumulative['Duration_mins'] = outfall_cumulative['Duration'].days
      2 outfall_total_duration.update(outfall_total_duration.days)

d:\data_science_projects\chicagorain\virtualenvs\nyear-venv\lib\site-packages\pandas\core\generic.py in __getattr__(self, name)
   2670             if name in self._info_axis:
   2671                 return self[name]
-> 2672             return object.__getattribute__(self, name)
   2673 
   2674     def __setattr__(self, name, value):

AttributeError: 'Series' object has no attribute 'days'

In [26]:
outfall_total_duration[0].days


Out[26]:
87

In [ ]: