Initial analysis of data post cleaning


In [83]:
import pickle
import pandas as pd
from datetime import datetime, timedelta
import matplotlib.pyplot as plt
import matplotlib
matplotlib.style.use('ggplot')
%matplotlib inline

In [71]:
print(plt.style.available)


['bmh', 'classic', 'dark_background', 'fivethirtyeight', 'ggplot', 'grayscale', 'seaborn-bright', 'seaborn-colorblind', 'seaborn-dark-palette', 'seaborn-dark', 'seaborn-darkgrid', 'seaborn-deep', 'seaborn-muted', 'seaborn-notebook', 'seaborn-paper', 'seaborn-pastel', 'seaborn-poster', 'seaborn-talk', 'seaborn-ticks', 'seaborn-white', 'seaborn-whitegrid', 'seaborn']

In [121]:
metro_delays = pickle.load( open( "metro_delays.p", "rb" ) )
bikeshare_rides = pickle.load( open( "bikeshare_rides.p", "rb" ) )
bikes_close = pickle.load( open( "bikes_close.p", "rb" ) )

In [122]:
print(type(metro_delays))
print(type(bikeshare_rides))
print(type(bikes_close))


<class 'pandas.core.frame.DataFrame'>
<class 'pandas.core.frame.DataFrame'>
<class 'dict'>

What is the date range of my bikeshare data?


In [123]:
print(bikeshare_rides.index.min())
print(bikeshare_rides.index.max())


2016-07-01 00:00:00
2016-09-30 23:59:00

Limit metro_delays to the time period for which I have bike data and to those delays > 30 minutes


In [124]:
metro_delays = metro_delays[str(bikeshare_rides.index.min()) : str(bikeshare_rides.index.max())]
metro_delays = metro_delays[metro_delays['Delay'] >= 30]

In [125]:
metro_delays


Out[125]:
Date Incident Line Direction Cause Delay time_stamp
Time
2016-09-23 16:00:00 9/23/2016 A Vienna-bound Orange Line train at Potomac A... Orange Vienna a brake problem 38.0 9/23/2016 4:00 pm
2016-09-23 17:06:00 9/23/2016 A Largo Town Center-bound Blue Line train at ... Blue Largo Town Center NaN 75.0 9/23/2016 5:06 pm
2016-09-22 06:04:00 9/22/2016 A Vienna-bound Orange Line train at New Carro... Orange Vienna a brake problem 36.0 9/22/2016 6:04 am
2016-09-21 21:49:00 9/21/2016 A Shady Grove-bound Red Line train at Judicia... Red Shady Grove signal problem 33.0 9/21/2016 9:49 pm
2016-09-17 07:00:00 9/17/2016 A Vienna-bound Orange Line train at New Carro... Orange Vienna a 3rd rail power problem 32.0 9/17/2016 7:00 am
2016-09-14 05:10:00 9/14/2016 Green Line service was temporarily suspended ... Green NaN a person struck by a train outside Suitland st... 30.0 9/14/2016 5:10 am
2016-09-13 22:04:00 9/13/2016 A Shady Grove-bound Red Line train at Farragu... Red Shady Grove a signal problem 41.0 9/13/2016 10:04 pm
2016-09-11 23:43:00 9/11/2016 A Vienna-bound Orange Line train at Landover ... Orange Vienna striking a deer 33.0 9/11/2016 11:43 pm
2016-09-07 22:29:00 9/7/2016 A Glenmont-bound Red Line train at NoMa-Galla... Red Glenmont a brake problem 30.0 9/7/2016 10:29 pm
2016-09-06 05:09:00 9/6/2016 A Largo Town Center-bound Blue Line train at ... Blue Largo Town Center a track problem 35.0 9/6/2016 5:09 am
2016-09-04 14:16:00 9/4/2016 A Vienna-bound Orange Line train at McPherson... Orange Vienna a signal problem 42.0 9/4/2016 2:16 pm
2016-09-02 10:24:00 9/2/2016 A Largo Town Center-bound Blue Line train at ... Blue Largo Town Center a signal problem 37.0 9/2/2016 10:24 am
2016-09-01 05:28:00 9/1/2016 Trains service was temporarily suspended betw... Blue NaN a switch malfunction 30.0 9/1/2016 5:28 am
2016-09-01 17:34:00 9/1/2016 Rhode Island Avenue station was temporarily c... NaN NaN falling debris 30.0 9/1/2016 5:34 pm
2016-08-31 09:54:00 8/31/2016 A Glenmont-bound Red Line train at Silver Spr... Red Glenmont a brake problem 31.0 8/31/2016 9:54 am
2016-08-31 09:54:00 8/31/2016 A Glenmont-bound Red Line train at Silver Spr... Red Glenmont a brake problem 31.0 8/31/2016 9:54 am
2016-08-29 10:19:00 8/29/2016 A Largo Town Center-bound Blue Line train at ... Blue Largo Town Center a track problem 56.0 8/29/2016 10:19 am
2016-08-26 05:00:00 8/26/2016 A Vienna-bound Orange Line train at New Carro... Orange Vienna unscheduled track work 31.0 8/26/2016 5:00 am
2016-08-16 15:16:00 8/16/2016 A Glenmont-bound Red Line train at Woodley Pa... Red Glenmont NaN 30.0 8/16/2016 3:16 pm
2016-08-15 08:24:00 8/15/2016 A Greenbelt-bound Yellow Line train at Georgi... Yellow Greenbelt a signal problem 33.0 8/15/2016 8:24 am
2016-08-08 05:20:00 8/8/2016 A Vienna-bound Orange Line train at West Fall... Orange Vienna a signal problem 37.0 8/8/2016 5:20 am
2016-08-06 07:32:00 8/6/2016 A Glenmont-bound Red Line train at Twinbrook ... Red Glenmont an equipment problem 33.0 8/6/2016 7:32 am
2016-07-31 21:18:00 7/31/2016 A New Carrollton-bound Orange Line train at D... Orange New Carrollton-bound Orange Line train at Dunn... a brake problem 39.0 7/31/2016 9:18 pm
2016-07-29 07:33:00 7/29/2016 A Silver Spring-bound Red Line train at Grosv... Red Silver Spring a brake problem 39.0 7/29/2016 7:33 am
2016-07-28 19:42:00 7/28/2016 A Branch Avenue-bound Green Line train at Col... Green Branch Avenue-bound Green Line train at Columb... a brake problem 42.0 7/28/2016 7:42 pm
2016-07-27 14:40:00 7/27/2016 A Huntington-bound no-passenger train outside... Yellow Huntington-bound no-passenger train outside Br... a brake problem 44.0 7/27/2016 2:40 pm
2016-07-27 14:44:00 7/27/2016 A Franconia-Springfield-bound Blue Line train... Blue Franconia-Springfield an operational problem 44.0 7/27/2016 2:44 pm
2016-07-26 09:15:00 7/26/2016 A Largo Town Center-bound Blue Line train at ... Blue Largo Town Center-bound Blue Line train at Cap... a brake problem 40.0 7/26/2016 9:15 am
2016-07-25 07:09:00 7/25/2016 A Largo Town Center-bound Silver Line train a... Silver Largo Town Center a brake problem 30.0 7/25/2016 7:09 am
2016-07-20 12:50:00 7/20/2016 A Vienna-bound Orange Line train at Ballston-... Orange Vienna a brake problem 43.0 7/20/2016 12:50 pm
2016-07-18 22:30:00 7/18/2016 A Vienna-bound Orange Line train at Stadium-A... Orange Vienna due to a signal problem 33.0 7/18/2016 10:30 pm
2016-07-13 08:51:00 7/13/2016 A Greenbelt-bound Yellow Line train at Ronald... Yellow Greenbelt an operational problem 40.0 7/13/2016 8:51 am
2016-07-12 07:00:00 7/12/2016 A no-passenger Vienna-bound Orange Line train... Orange no-passenger Vienna-bound Orange Line train ou... a brake problem 30.0 7/12/2016 7:00 am
2016-07-12 10:21:00 7/12/2016 A Greenbelt-bound Yellow Line train at Ronald... Yellow Greenbelt unscheduled track maintenance 35.0 7/12/2016 10:21 am
2016-07-08 05:22:00 7/8/2016 A Glenmont-bound Red Line train at Shady Grov... Red Glenmont unscheduled track maintenance 33.0 7/8/2016 5:22 am
2016-07-05 16:49:00 7/5/2016 A Vienna-bound Orange Line train at outside C... Orange Vienna-bound Orange Line train at outside Cour... NaN 60.0 7/5/2016 4:49 pm
2016-07-05 19:15:00 7/5/2016 A Shady Grove-bound Red Line train at Glenmon... Red Shady Grove an operational problem 52.0 7/5/2016 7:15 pm
2016-07-02 12:39:00 7/2/2016 Friendship Heights station was temporarily cl... NaN NaN a report of smoke 45.0 7/2/2016 12:39 pm
2016-07-01 05:17:00 7/1/2016 A Franconia-Springfield-bound Blue Line train... Blue Franconia-Springfield a signal problem 31.0 7/1/2016 5:17 am

In [126]:
print(len(metro_delays))
print(len(metro_delays.dropna()))


39
32

Apparently 7 delays contain NaN's

How many >30min delays does each line have?


In [127]:
metro_delays.groupby('Line').count()


Out[127]:
Date Incident Direction Cause Delay time_stamp
Line
Blue 8 8 7 7 8 8
Green 2 2 1 2 2 2
Orange 12 12 12 11 12 12
Red 10 10 10 9 10 10
Silver 1 1 1 1 1 1
Yellow 4 4 4 4 4 4

Lets look a little closer at the Red line delays during the morning rush hour (6 - 9 am) (is it possible to slice by time of day?) try red_delayed.index.hour


In [108]:
red_delays = metro_delays[metro_delays['Line'] == 'Red']
red_delays


Out[108]:
Date Incident Line Direction Cause Delay time_stamp
Time
2012-12-31 10:30:00 12/31/2012 A Grosvenor-bound Red Line train at Gallery P... Red Grosvenor an equipment problem 6.0 12/31/2012 10:30 am
2012-12-31 19:38:00 12/31/2012 A Shady Grove-bound Red Line train at Fort To... Red Shady Grove a brake problem 8.0 12/31/2012 7:38 pm
2012-12-31 23:32:00 12/31/2012 A Glenmont-bound Red Line train at Dupont Cir... Red Glenmont a report of smoke 4.0 12/31/2012 11:32 pm
2012-12-30 12:24:00 12/30/2012 A Shady Grove-bound Red Line train at Takoma ... Red Shady Grove a brake problem 27.0 12/30/2012 12:24 pm
2012-12-30 12:34:00 12/30/2012 A Glenmont-bound Red Line train at Union Stat... Red Glenmont an equipment problem 6.0 12/30/2012 12:34 pm
2012-12-30 17:19:00 12/30/2012 A Silver Spring-bound Red Line train at Twinb... Red Silver Spring an equipment problem 7.0 12/30/2012 5:19 pm
2012-12-30 18:39:00 12/30/2012 A Shady Grove-bound Red Line train at Metro C... Red Shady Grove an operational problem 6.0 12/30/2012 6:39 pm
2012-12-29 10:21:00 12/29/2012 A Shady Grove-bound Red Line train at Metro C... Red Shady Grove an operational problem 6.0 12/29/2012 10:21 am
2012-12-29 14:41:00 12/29/2012 A Shady Grove-bound Red Line train at Woodley... Red Shady Grove police activity 7.0 12/29/2012 2:41 pm
2012-12-29 18:32:00 12/29/2012 A Glenmont-bound Red Line train at Gallery Pl... Red Glenmont a door problem 4.0 12/29/2012 6:32 pm
2012-12-29 19:55:00 12/29/2012 A Silver Spring-bound Red Line train at Brook... Red Silver Spring a sick customer 5.0 12/29/2012 7:55 pm
2012-12-28 08:49:00 12/28/2012 A Shady Grove-bound Red Line train at Glenmon... Red Shady Grove a signal problem 8.0 12/28/2012 8:49 am
2012-12-28 10:06:00 12/28/2012 A Silver Spring-bound Red Line train at Dupon... Red Silver Spring police activity 6.0 12/28/2012 10:06 am
2012-12-28 11:20:00 12/28/2012 A Shady Grove-bound Red Line train at Glenmon... Red Shady Grove a signal problem 6.0 12/28/2012 11:20 am
2012-12-28 14:49:00 12/28/2012 A Shady Grove-bound Red Line train at Silver ... Red Shady Grove single tracking 20.0 12/28/2012 2:49 pm
2012-12-28 16:50:00 12/28/2012 A Glenmont-bound Red Line train at Grosvenor ... Red Glenmont an equipment problem 8.0 12/28/2012 4:50 pm
2012-12-27 07:10:00 12/27/2012 A Grosvenor-bound Red Line train at Rhode Isl... Red Grosvenor an equipment problem 5.0 12/27/2012 7:10 am
2012-12-27 07:14:00 12/27/2012 A Grosvenor-bound Red Line train at Dupont Ci... Red Grosvenor NaN 5.0 12/27/2012 7:14 am
2012-12-27 08:05:00 12/27/2012 A Shady Grove-bound Red Line train at Metro C... Red Shady Grove a brake problem 3.0 12/27/2012 8:05 am
2012-12-27 17:25:00 12/27/2012 A Grosvenor-bound Red Line train at Gallery P... Red Grosvenor a woman in labor 11.0 12/27/2012 5:25 pm
2012-12-26 14:27:00 12/26/2012 A Grosvenor-bound Red Line train at Silver Sp... Red Grosvenor an operational problem 4.0 12/26/2012 2:27 pm
2012-12-26 16:36:00 12/26/2012 A Glenmont-bound Red Line train at Rockville ... Red Glenmont a brake problem 6.0 12/26/2012 4:36 pm
2012-12-26 18:41:00 12/26/2012 A Shady Grove-bound Red Line train at NoMa-Ga... Red Shady Grove a brake problem 6.0 12/26/2012 6:41 pm
2012-12-26 20:22:00 12/26/2012 A Glenmont-bound Red Line train at Takoma was... Red Glenmont expressed for schedule adherence/improved trai... NaN 12/26/2012 8:22 pm
2012-12-25 17:58:00 12/25/2012 A Glenmont-bound Red Line train at Union Stat... Red Glenmont a door problem 14.0 12/25/2012 5:58 pm
2012-12-24 16:31:00 12/24/2012 A Glenmont-bound Red Line train at Shady Grov... Red Glenmont did not operate 6.0 12/24/2012 4:31 pm
2012-12-24 16:51:00 12/24/2012 A Glenmont-bound Red Line train at Rhode Isla... Red Glenmont an equipment problem 6.0 12/24/2012 4:51 pm
2012-12-24 19:32:00 12/24/2012 A Shady Grove-bound Red Line train at Glenmon... Red Shady Grove a brake problem 5.0 12/24/2012 7:32 pm
2012-12-22 07:21:00 12/22/2012 A Glenmont-bound Red Line train was delayed 6... Red Glenmont a signal problem 6.0 12/22/2012 7:21 am
2012-12-22 20:40:00 12/22/2012 A Red Line train at Metro Center was delayed ... Red NaN police activity 8.0 12/22/2012 8:40 pm
... ... ... ... ... ... ... ...
2016-01-06 17:52:00 1/6/2016 A Shady Grove-bound Red Line train at White F... Red Shady Grove expressed for schedule adherence/improved trai... NaN 1/6/2016 5:52 pm
NaT 1/5/2016 5:00 a. m. A Shady Grove-bound Red Line train ... Red Shady Grove a signal problem 15.0 NaN
2016-01-05 05:15:00 1/5/2016 A Shady Grove-bound Red Line train at Glenmon... Red Shady Grove did not operate 19.0 1/5/2016 5:15 am
2016-01-05 07:44:00 1/5/2016 A Shady Grove-bound Red Line train at Dupont ... Red Shady Grove a brake problem 8.0 1/5/2016 7:44 am
2016-01-05 15:57:00 1/5/2016 A Silver Spring-bound Red Line train at Bethe... Red Silver Spring a door problem 5.0 1/5/2016 3:57 pm
2016-01-05 16:19:00 1/5/2016 A Glenmont-bound Red Line train at Takoma was... Red Glenmont expressed for schedule adherence/improved trai... NaN 1/5/2016 4:19 pm
2016-01-05 16:24:00 1/5/2016 A Glenmont-bound Red Line train at Forest Gle... Red Glenmont expressed for schedule adherence/improved trai... NaN 1/5/2016 4:24 pm
2016-01-05 16:28:00 1/5/2016 A Shady Grove-bound Red Line train at Medical... Red Shady Grove expressed for schedule adherence/improved trai... NaN 1/5/2016 4:28 pm
2016-01-05 16:36:00 1/5/2016 A Shady Grove-bound Red Line train at Twinbro... Red Shady Grove expressed for schedule adherence/improved trai... NaN 1/5/2016 4:36 pm
2016-01-05 17:23:00 1/5/2016 A Glenmont-bound Red Line train at Farragut N... Red Glenmont a brake problem 9.0 1/5/2016 5:23 pm
2016-01-05 21:18:00 1/5/2016 A Glenmont-bound Red Line train at Takoma was... Red Glenmont a signal problem 4.0 1/5/2016 9:18 pm
2016-01-04 07:20:00 1/4/2016 A Silver Spring-bound Red Line train at NoMa-... Red Silver Spring an operational problem 5.0 1/4/2016 7:20 am
2016-01-04 09:01:00 1/4/2016 A Glenmont-bound Red Line train at Shady Grov... Red Glenmont a door problem 5.0 1/4/2016 9:01 am
2016-01-04 09:54:00 1/4/2016 A Silver Spring-bound Red Line train at Galle... Red Silver Spring a brake problem 6.0 1/4/2016 9:54 am
2016-01-04 14:57:00 1/4/2016 A Shady Grove-bound Red Line train at Grosven... Red Shady Grove maintenance activity 23.0 1/4/2016 2:57 pm
2016-01-04 15:49:00 1/4/2016 A Shady Grove-bound Red Line train at Glenmon... Red Shady Grove an operational problem 4.0 1/4/2016 3:49 pm
2016-01-04 15:51:00 1/4/2016 A Shady Grove-bound Red Line train at Forest ... Red Shady Grove expressed for schedule adherence/improved trai... NaN 1/4/2016 3:51 pm
2016-01-04 16:08:00 1/4/2016 A Silver Spring-bound Red Line train at Brook... Red Silver Spring expressed for schedule adherence/improved trai... NaN 1/4/2016 4:08 pm
2016-01-04 16:19:00 1/4/2016 A Glenmont-bound Red Line train at Silver Spr... Red Glenmont fire department activity 12.0 1/4/2016 4:19 pm
2016-01-04 17:39:00 1/4/2016 A Glenmont-bound Red Line train at Woodley Pa... Red Glenmont expressed for schedule adherence/improved trai... NaN 1/4/2016 5:39 pm
2016-01-04 17:50:00 1/4/2016 A Glenmont-bound Red Line train at Van Ness w... Red Glenmont expressed for schedule adherence/improved trai... NaN 1/4/2016 5:50 pm
2016-01-04 18:15:00 1/4/2016 A Glenmont-bound Red Line train at Twinbrook ... Red Glenmont expressed for schedule adherence/improved trai... NaN 1/4/2016 6:15 pm
2016-01-04 18:33:00 1/4/2016 A Glenmont-bound Red Line train at Forest Gle... Red Glenmont expressed for schedule adherence/improved trai... NaN 1/4/2016 6:33 pm
2016-01-04 20:52:00 1/4/2016 A Glenmont-bound Red Line train at Rhode Isla... Red Glenmont a brake problem 9.0 1/4/2016 8:52 pm
2016-01-02 17:56:00 1/2/2016 A Silver Spring-bound Red Line train at Fort ... Red Silver Spring police activity 7.0 1/2/2016 5:56 pm
2016-01-02 19:30:00 1/2/2016 A Glenmont-bound Red Line train at Dupont Cir... Red Glenmont a brake problem 12.0 1/2/2016 7:30 pm
2016-01-02 20:36:00 1/2/2016 A Shady Grove-bound Red Line train at Van Nes... Red Shady Grove a door problem 5.0 1/2/2016 8:36 pm
2016-01-01 02:17:00 1/1/2016 A Shady Grove-bound Red Line train at Glenmon... Red Shady Grove a medical emergency 20.0 1/1/2016 2:17 am
2016-01-01 02:26:00 1/1/2016 A Glenmont-bound Red Line train at Fort Totte... Red Glenmont was offloaded and turned back for schedule adh... 8.0 1/1/2016 2:26 am
2016-01-01 08:49:00 1/1/2016 A Shady Grove-bound Red Line train at Glenmon... Red Shady Grove an operational problem 5.0 1/1/2016 8:49 am

7865 rows × 7 columns

Lets look at the Red line data for 2016-07-29 6:30 AM to 8:30 AM


In [49]:
delay_time = pd.to_datetime('2016-07-29 07:30:00')
delay_time


Out[49]:
Timestamp('2016-07-29 07:30:00')

In [90]:
delay_time.weekday_name


Out[90]:
'Friday'

In [56]:
delay_rides_all = bikeshare_rides[str(delay_time - timedelta(hours=1)) : str(delay_time + timedelta(hours=1))]
delay_rides_all


Out[56]:
Duration (ms) End date Start station number Start station End station number End station Bike number Member Type
Start date
2016-07-29 08:30:00 837882 7/29/2016 8:44 31606 Potomac & Pennsylvania Ave SE 31632 15th & F St NE W00933 Registered
2016-07-29 08:30:00 999930 7/29/2016 8:46 31008 12th & Army Navy Dr 31249 Jefferson Memorial W00653 Registered
2016-07-29 08:30:00 376885 7/29/2016 8:36 31616 3rd & H St NE 31265 5th St & Massachusetts Ave NW W21251 Registered
2016-07-29 08:30:00 2852861 7/29/2016 9:17 31700 Good Hope & Naylor Rd SE 31700 Good Hope & Naylor Rd SE W01098 Registered
2016-07-29 08:30:00 356388 7/29/2016 8:36 31611 13th & H St NE 31508 Gallaudet / 8th St & Florida Ave NE W00526 Casual
2016-07-29 08:30:00 648921 7/29/2016 8:41 31203 14th & Rhode Island Ave NW 31224 19th & L St NW W00144 Registered
2016-07-29 08:30:00 1188288 7/29/2016 8:50 31402 14th St Heights / 14th & Crittenden St NW 31285 22nd & P ST NW W00202 Registered
2016-07-29 08:30:00 401503 7/29/2016 8:37 31234 20th & O St NW / Dupont South 31275 New Hampshire Ave & 24th St NW W20889 Registered
2016-07-29 08:30:00 1083758 7/29/2016 8:48 31110 20th St & Florida Ave NW 31014 Lynn & 19th St North W20390 Registered
2016-07-29 08:30:00 198339 7/29/2016 8:33 31267 17th St & Massachusetts Ave NW 31233 17th & K St NW / Farragut Square W22849 Registered
2016-07-29 08:30:00 1333010 7/29/2016 8:52 31120 10th & Florida Ave NW 31205 21st & I St NW W22475 Registered
2016-07-29 08:30:00 5622490 7/29/2016 10:04 31601 19th & East Capitol St SE 31708 Anacostia Ave & Benning Rd NE / River Terrace W22807 Registered
2016-07-29 08:30:00 414307 7/29/2016 8:37 31099 Madison & N Henry St 31042 Market Square / King St & Royal St W22904 Registered
2016-07-29 08:30:00 865957 7/29/2016 8:45 31613 Eastern Market Metro / Pennsylvania Ave & 7th ... 31219 10th St & Constitution Ave NW W20598 Registered
2016-07-29 08:30:00 419225 7/29/2016 8:37 31267 17th St & Massachusetts Ave NW 31205 21st & I St NW W21520 Registered
2016-07-29 08:30:00 728005 7/29/2016 8:42 31245 7th & R St NW / Shaw Library 31233 17th & K St NW / Farragut Square W21879 Registered
2016-07-29 08:30:00 329008 7/29/2016 8:36 31223 Convention Center / 7th & M St NW 31241 Thomas Circle W20778 Registered
2016-07-29 08:30:00 231807 7/29/2016 8:34 31202 14th & R St NW 31111 10th & U St NW W20380 Registered
2016-07-29 08:30:00 611398 7/29/2016 8:40 31212 21st & M St NW 31238 14th & G St NW W22783 Registered
2016-07-29 08:30:00 1040867 7/29/2016 8:48 31305 Connecticut Ave & Newark St NW / Cleveland Park 31215 Georgetown Harbor / 30th St NW W01151 Registered
2016-07-29 08:30:00 407908 7/29/2016 8:37 31229 New Hampshire Ave & T St NW 31233 17th & K St NW / Farragut Square W22266 Registered
2016-07-29 08:30:00 471635 7/29/2016 8:38 31123 14th & Girard St NW 31121 Calvert St & Woodley Pl NW W21881 Casual
2016-07-29 08:30:00 304227 7/29/2016 8:36 31241 Thomas Circle 31200 Massachusetts Ave & Dupont Circle NW W21824 Registered
2016-07-29 08:30:00 129191 7/29/2016 8:33 31104 Adams Mill & Columbia Rd NW 31121 Calvert St & Woodley Pl NW W01422 Registered
2016-07-29 08:29:00 1334951 7/29/2016 8:51 31265 5th St & Massachusetts Ave NW 31014 Lynn & 19th St North W22644 Registered
2016-07-29 08:29:00 272275 7/29/2016 8:33 31203 14th & Rhode Island Ave NW 31221 18th & M St NW W20043 Registered
2016-07-29 08:29:00 275365 7/29/2016 8:33 31059 S Four Mile Run & Walter Reed Dr 31076 Shirlington Transit Center / S Quincy & Randol... W21685 Registered
2016-07-29 08:29:00 1876936 7/29/2016 9:00 31022 Clarendon Metro / Wilson Blvd & N Highland St 31022 Clarendon Metro / Wilson Blvd & N Highland St W00060 Registered
2016-07-29 08:29:00 918886 7/29/2016 8:44 31307 3000 Connecticut Ave NW / National Zoo 31227 13th St & New York Ave NW W20128 Registered
2016-07-29 08:29:00 845918 7/29/2016 8:43 31281 8th & O St NW 31639 2nd & G St NE W22835 Registered
... ... ... ... ... ... ... ... ...
2016-07-29 06:38:00 583675 7/29/2016 6:48 31629 8th & East Capitol St NE 31218 L'Enfant Plaza / 7th & C St SW W22677 Registered
2016-07-29 06:38:00 552521 7/29/2016 6:47 31201 15th & P St NW 31255 24th & N St NW W01204 Registered
2016-07-29 06:38:00 1305588 7/29/2016 7:00 31610 Eastern Market / 7th & North Carolina Ave SE 31225 C & O Canal & Wisconsin Ave NW W21382 Registered
2016-07-29 06:38:00 214107 7/29/2016 6:42 31265 5th St & Massachusetts Ave NW 31274 MLK Library/9th & G St NW W22819 Registered
2016-07-29 06:37:00 434089 7/29/2016 6:44 31116 California St & Florida Ave NW 31201 15th & P St NW W21457 Registered
2016-07-29 06:37:00 390370 7/29/2016 6:43 31627 M St & Delaware Ave NE 31519 1st & O St NW W20368 Registered
2016-07-29 06:37:00 432488 7/29/2016 6:44 31231 14th & D St NW / Ronald Reagan Building 31261 21st St & Constitution Ave NW W20275 Registered
2016-07-29 06:37:00 194865 7/29/2016 6:40 31031 15th & N Scott St 31016 Clarendon Blvd & Pierce St W21138 Registered
2016-07-29 06:37:00 587299 7/29/2016 6:47 31109 7th & T St NW 31255 24th & N St NW W01197 Registered
2016-07-29 06:36:00 1686629 7/29/2016 7:04 31602 Park Rd & Holmead Pl NW 31254 15th & K St NW W22729 Registered
2016-07-29 06:36:00 894520 7/29/2016 6:51 31610 Eastern Market / 7th & North Carolina Ave SE 31249 Jefferson Memorial W01307 Registered
2016-07-29 06:36:00 1640512 7/29/2016 7:03 31059 S Four Mile Run & Walter Reed Dr 31059 S Four Mile Run & Walter Reed Dr W21685 Registered
2016-07-29 06:36:00 1335101 7/29/2016 6:58 31271 Constitution Ave & 2nd St NW/DOL 31211 Kennedy Center W22543 Registered
2016-07-29 06:36:00 797452 7/29/2016 6:49 31401 14th St & Spring Rd NW 31280 11th & S St NW W20674 Registered
2016-07-29 06:36:00 227791 7/29/2016 6:40 31619 Lincoln Park / 13th & East Capitol St NE 31610 Eastern Market / 7th & North Carolina Ave SE W01069 Registered
2016-07-29 06:36:00 216086 7/29/2016 6:40 31619 Lincoln Park / 13th & East Capitol St NE 31610 Eastern Market / 7th & North Carolina Ave SE W22382 Registered
2016-07-29 06:35:00 206248 7/29/2016 6:38 31018 N Rhodes & 16th St N 31015 Rosslyn Metro / Wilson Blvd & Ft Myer Dr W21578 Registered
2016-07-29 06:35:00 1079907 7/29/2016 6:53 31270 8th & D St NW 31619 Lincoln Park / 13th & East Capitol St NE W21367 Registered
2016-07-29 06:34:00 1065897 7/29/2016 6:52 31102 11th & Kenyon St NW 31638 1st & H St NW W21867 Registered
2016-07-29 06:34:00 825297 7/29/2016 6:48 31631 8th & F St NE 31628 1st & K St SE W21155 Registered
2016-07-29 06:34:00 730819 7/29/2016 6:46 31511 12th & Irving St NE 31627 M St & Delaware Ave NE W22865 Registered
2016-07-29 06:34:00 599783 7/29/2016 6:44 31121 Calvert St & Woodley Pl NW 31202 14th & R St NW W21025 Registered
2016-07-29 06:34:00 490713 7/29/2016 6:43 31618 4th & East Capitol St NE 31634 3rd & Tingey St SE W21307 Registered
2016-07-29 06:32:00 1015372 7/29/2016 6:49 31008 12th & Army Navy Dr 31249 Jefferson Memorial W21405 Registered
2016-07-29 06:32:00 271203 7/29/2016 6:37 31265 5th St & Massachusetts Ave NW 31274 MLK Library/9th & G St NW W01008 Registered
2016-07-29 06:32:00 327271 7/29/2016 6:38 31099 Madison & N Henry St 31085 Mount Vernon Ave & E Nelson Ave W20599 Registered
2016-07-29 06:33:00 889324 7/29/2016 6:47 31102 11th & Kenyon St NW 31250 20th & L St NW W22891 Registered
2016-07-29 06:30:00 838817 7/29/2016 6:44 31506 1st & Rhode Island Ave NW 31234 20th & O St NW / Dupont South W20554 Registered
2016-07-29 06:30:00 1068330 7/29/2016 6:48 31637 North Capitol St & G Pl NE 31278 18th & R St NW W22755 Registered
2016-07-29 06:30:00 1621170 7/29/2016 6:57 31904 East Falls Church Metro/Sycamore St & 19th St N 31080 Lee Hwy & N Scott St W01226 Registered

1432 rows × 8 columns

1432 rides begand within +/- 1 hour of this delay

How many rides during this time were Registered vs Casual?


In [58]:
delay_rides_all.groupby('Member Type')['Member Type'].count()


Out[58]:
Member Type
Casual          66
Registered    1366
Name: Member Type, dtype: int64

How many of these were from along the red line?


In [63]:
bikes_close['RD']


Out[63]:
list

In [66]:
red_delayed = delay_rides_all[delay_rides_all['Start station'].isin(bikes_close['RD'])]
nonred_delayed = delay_rides_all[~delay_rides_all['Start station'].isin(bikes_close['RD'])]

How many of the rides during this time period originated from a station close to the red line?


In [74]:
print(len(red_delayed))
print(len(nonred_delayed))
print(red_delayed.groupby('Member Type')['Member Type'].count())


211
1221
Member Type
Casual         11
Registered    200
Name: Member Type, dtype: int64

count the number of rides at each time point so that we can look for changes before and after the delay


In [76]:
red_delayed.groupby("Start station")['Start station'].count()


Out[76]:
Start station
10th & Monroe St NE                                 2
12th & Newton St NE                                 3
13th St & New York Ave NW                           1
14th & G St NW                                      1
17th & K St NW                                      8
17th & K St NW / Farragut Square                    1
17th & Rhode Island Ave NW                          5
18th & M St NW                                      1
18th & R St NW                                     10
19th & K St NW                                      1
1st & M St NE                                      10
20th & O St NW / Dupont South                       8
2nd & G St NE                                      10
3rd & H St NW                                       2
4th & D St NW / Judiciary Square                    5
5th & F St NW                                       7
5th St & Massachusetts Ave NW                      12
6th St & Indiana Ave NW                             2
8th & H St NW                                       9
Bethesda Metro                                      2
Calvert St & Woodley Pl NW                         11
Columbus Circle / Union Station                    38
Connecticut Ave & Newark St NW / Cleveland Park     4
Connecticut Ave & Tilden St NW                      1
John McCormack Dr & Michigan Ave NE                 1
M St & Delaware Ave NE                              9
MLK Library/9th & G St NW                           4
Massachusetts Ave & Dupont Circle NW                9
Metro Center / 12th & G St NW                       5
Montgomery & East Ln                                1
Montgomery Ave & Waverly St                         1
North Capitol St & F St NW                         12
North Capitol St & G Pl NE                          4
Rhode Island Ave Metro                              2
Ripley & Bonifant St                                1
Shady Grove Metro West                              1
Silver Spring Metro/Colesville Rd & Wayne Ave       3
Van Ness Metro / UDC                                3
Yuma St & Tenley Circle NW                          1
Name: Start station, dtype: int64

In [78]:
red_delayed['count'] = 1


/Users/DDT1-Old/anaconda/lib/python3.6/site-packages/ipykernel/__main__.py:1: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  if __name__ == '__main__':

In [140]:
red_delayed['count'].resample('3T').sum().plot(kind='box')


Out[140]:
<matplotlib.axes._subplots.AxesSubplot at 0x110fac080>

In [133]:
red_delayed['count'].resample('3T').sum().plot(kind='bar')


Out[133]:
<matplotlib.axes._subplots.AxesSubplot at 0x11100c198>

how do the actual numbers compare before and after the delay?


In [115]:
# figure out the number of rides before the delay
delay_rides_before = bikeshare_rides[str(delay_time - timedelta(hours=1)) : str(delay_time)]
red_delayed_before = delay_rides_before[delay_rides_before['Start station'].isin(bikes_close['RD'])]
nonred_delayed_before = delay_rides_before[~delay_rides_before['Start station'].isin(bikes_close['RD'])]

# figure out the number of rides after the delay

delay_rides_after = bikeshare_rides[str(delay_time) : str(delay_time + timedelta(hours=1))]
red_delayed_after = delay_rides_after[delay_rides_after['Start station'].isin(bikes_close['RD'])]
nonred_delayed_after = delay_rides_after[~delay_rides_after['Start station'].isin(bikes_close['RD'])]

print('red_delayed_before', len(red_delayed_before))
print('nonred_delayed_before', len(nonred_delayed_before))
print('red_delayed_after', len(red_delayed_after))
print('nonred_delayed_after', len(nonred_delayed_after))


red_delayed_before 55
nonred_delayed_before 358
red_delayed_after 158
nonred_delayed_after 870

The after delay is 2.9 times larger than the before delay count

There is an increase after 7:30, but how do we know it is because of the delay and not just because 7:30-8:30 is more popular time to ride than 6:30-7:30?

Compare this plot to one generated for a day with no delay (2016-07-29 + 7 days)


In [95]:
nodelay_time = delay_time + timedelta(days=7)
nodelay_time


Out[95]:
Timestamp('2016-08-05 07:30:00')

Make sure there were no significant delays during rush hour on this day
there was a 6 minute delay at 7:23am


In [96]:
metro_delays['2016-08-05']


Out[96]:
Date Incident Line Direction Cause Delay time_stamp
Time
2016-08-05 06:04:00 8/5/2016 A Largo Town Center-bound Blue Line train at ... Blue Largo Town Center did not operate 8.0 8/5/2016 6:04 am
2016-08-05 06:16:00 8/5/2016 A Largo Town Center-bound Blue Line train at ... Blue Largo Town Center did not operate 8.0 8/5/2016 6:16 am
2016-08-05 06:20:00 8/5/2016 A Vienna-bound Orange Line train at New Carro... Orange Vienna did not operate 6.0 8/5/2016 6:20 am
2016-08-05 06:57:00 8/5/2016 A Branch Avenue-bound Green Line train at Gre... Green Branch Avenue did not operate 6.0 8/5/2016 6:57 am
2016-08-05 06:58:00 8/5/2016 A Vienna-bound Orange Line train at New Carro... Orange Vienna did not operate 6.0 8/5/2016 6:58 am
2016-08-05 07:00:00 8/5/2016 A Wiehle-Reston East-bound Silver Line train ... Silver Wiehle-Reston East did not operate 6.0 8/5/2016 7:00 am
2016-08-05 07:12:00 8/5/2016 A Vienna-bound Orange Line train at New Carro... Orange Vienna did not operate 6.0 8/5/2016 7:12 am
2016-08-05 07:12:00 8/5/2016 A Wiehle-Reston East-bound Silver Line train ... Silver Wiehle-Reston East did not operate 6.0 8/5/2016 7:12 am
2016-08-05 07:23:00 8/5/2016 A Glenmont-bound Red Line train at Shady Grov... Red Glenmont did not operate 6.0 8/5/2016 7:23 am
2016-08-05 07:37:00 8/5/2016 A Vienna-bound Orange Line train at West Fall... Orange Vienna did not operate 4.0 8/5/2016 7:37 am
2016-08-05 07:44:00 8/5/2016 A Franconia-Springfield-bound Yellow Line tra... Yellow Franconia-Springfield a door problem 9.0 8/5/2016 7:44 am
2016-08-05 07:47:00 8/5/2016 A Huntington-bound Yellow Line train at Hunti... Yellow Huntington did not operate 6.0 8/5/2016 7:47 am
2016-08-05 07:57:00 8/5/2016 A Greenbelt-bound Green Line train at Branch ... Green Greenbelt did not operate 6.0 8/5/2016 7:57 am
2016-08-05 09:53:00 8/5/2016 A Branch Avenue-bound Green Line train at Sui... Green Branch Avenue an equipment problem 5.0 8/5/2016 9:53 am
2016-08-05 13:17:00 8/5/2016 A Largo Town Center-bound Blue Line train at ... Blue Largo Town Center a signal problem 6.0 8/5/2016 1:17 pm
2016-08-05 13:33:00 8/5/2016 A Greenbelt-bound Green Line train at Gallery... Green Greenbelt police activity 6.0 8/5/2016 1:33 pm
2016-08-05 13:55:00 8/5/2016 A Franconia-Springfield-bound Blue Line train... Blue Franconia-Springfield a door problem 12.0 8/5/2016 1:55 pm
2016-08-05 14:27:00 8/5/2016 A Ft. Totten-bound Yellow Line train at Hunti... Yellow Ft. Totten an operational problem 8.0 8/5/2016 2:27 pm
2016-08-05 14:49:00 8/5/2016 A Largo Town Center-bound Blue Line train at ... Blue Largo Town Center an operational problem 9.0 8/5/2016 2:49 pm
2016-08-05 15:02:00 8/5/2016 A Shady Grove-bound Red Line train at NoMa-Ga... Red Shady Grove did not operate 6.0 8/5/2016 3:02 pm
2016-08-05 15:21:00 8/5/2016 A Branch Avenue-bound Green Line train at Gre... Green Branch Avenue did not operate 6.0 8/5/2016 3:21 pm
2016-08-05 15:26:00 8/5/2016 A Shady Grove-bound Red Line train at NoMa-Ga... Red Shady Grove did not operate 6.0 8/5/2016 3:26 pm
2016-08-05 15:33:00 8/5/2016 A Branch Avenue-bound Green Line train at Gre... Green Branch Avenue did not operate 6.0 8/5/2016 3:33 pm
2016-08-05 15:51:00 8/5/2016 A Branch Avenue-bound Green Line train at Gre... Green Branch Avenue did not operate 6.0 8/5/2016 3:51 pm
2016-08-05 15:53:00 8/5/2016 A New Carrollton-bound Orange Line train at V... Orange New Carrollton did not operate 6.0 8/5/2016 3:53 pm
2016-08-05 16:05:00 8/5/2016 A New Carrollton-bound Orange Line train at V... Orange New Carrollton did not operate 6.0 8/5/2016 4:05 pm
2016-08-05 16:15:00 8/5/2016 A Largo Town Center-bound Silver Line train a... Silver Largo Town Center did not operate 6.0 8/5/2016 4:15 pm
2016-08-05 16:35:00 8/5/2016 A Glenmont-bound Red Line train at Forest Gle... Red Glenmont a door problem 6.0 8/5/2016 4:35 pm
2016-08-05 17:46:00 8/5/2016 A Greenbelt-bound Green Line train at Georgia... Green Greenbelt-bound Green Line train at Georgia Av... a brake problem 21.0 8/5/2016 5:46 pm
2016-08-05 18:52:00 8/5/2016 A Wiehle-Reston East-bound Silver Line train ... Silver Wiehle-Reston East a medical emergency 7.0 8/5/2016 6:52 pm

In [97]:
nodelay_rides_all = bikeshare_rides[str(nodelay_time - timedelta(hours=1)) : str(nodelay_time + timedelta(hours=1))]
nodelay_rides_all


Out[97]:
Duration (ms) End date Start station number Start station End station number End station Bike number Member Type
Start date
2016-08-05 08:30:00 1540794 8/5/2016 8:55 31258 Lincoln Memorial 31627 M St & Delaware Ave NE W00793 Registered
2016-08-05 08:30:00 980207 8/5/2016 8:46 31267 17th St & Massachusetts Ave NW 31228 8th & H St NW W22527 Registered
2016-08-05 08:30:00 183179 8/5/2016 8:33 31109 7th & T St NW 31281 8th & O St NW W00413 Registered
2016-08-05 08:30:00 556511 8/5/2016 8:39 31512 Neal St & Trinidad Ave NE 31623 Columbus Circle / Union Station W21962 Registered
2016-08-05 08:30:00 276117 8/5/2016 8:34 32029 Offutt Ln & Chevy Chase Dr 32013 Montgomery & East Ln W21432 Registered
2016-08-05 08:30:00 1146302 8/5/2016 8:49 31306 39th & Calvert St NW / Stoddert 31279 19th & G St NW W01025 Registered
2016-08-05 08:30:00 581824 8/5/2016 8:40 31248 Smithsonian / Jefferson Dr & 12th St SW 31261 21st St & Constitution Ave NW W21531 Registered
2016-08-05 08:30:00 163929 8/5/2016 8:33 31039 Wilson Blvd & N Quincy St 31034 N Randolph St & Fairfax Dr W21644 Registered
2016-08-05 08:30:00 1219273 8/5/2016 8:50 31246 M St & Pennsylvania Ave NW 31219 10th St & Constitution Ave NW W20102 Registered
2016-08-05 08:30:00 542223 8/5/2016 8:39 31623 Columbus Circle / Union Station 31600 5th & K St NW W22741 Registered
2016-08-05 08:30:00 703108 8/5/2016 8:42 31110 20th St & Florida Ave NW 31232 7th & F St NW / National Portrait Gallery W00589 Registered
2016-08-05 08:30:00 455459 8/5/2016 8:38 31513 Rhode Island Ave & V St NE 31506 1st & Rhode Island Ave NW W22507 Registered
2016-08-05 08:30:00 505855 8/5/2016 8:39 31203 14th & Rhode Island Ave NW 31245 7th & R St NW / Shaw Library W21653 Registered
2016-08-05 08:30:00 730993 8/5/2016 8:42 31121 Calvert St & Woodley Pl NW 31224 19th & L St NW W20974 Registered
2016-08-05 08:30:00 3772100 8/5/2016 9:33 31264 6th St & Indiana Ave NW 31219 10th St & Constitution Ave NW W20153 Casual
2016-08-05 08:30:00 204643 8/5/2016 8:34 31503 Florida Ave & R St NW 31519 1st & O St NW W01311 Registered
2016-08-05 08:30:00 1093443 8/5/2016 8:48 31104 Adams Mill & Columbia Rd NW 31220 US Dept of State / Virginia Ave & 21st St NW W22824 Registered
2016-08-05 08:30:00 873070 8/5/2016 8:45 31258 Lincoln Memorial 31008 12th & Army Navy Dr W20861 Registered
2016-08-05 08:30:00 1135998 8/5/2016 8:49 31513 Rhode Island Ave & V St NE 31267 17th St & Massachusetts Ave NW W22217 Registered
2016-08-05 08:30:00 771513 8/5/2016 8:43 31111 10th & U St NW 31231 14th & D St NW / Ronald Reagan Building W01210 Registered
2016-08-05 08:30:00 625480 8/5/2016 8:41 31205 21st & I St NW 31234 20th & O St NW / Dupont South W22965 Registered
2016-08-05 08:30:00 2632784 8/5/2016 9:14 31623 Columbus Circle / Union Station 31801 Anacostia Metro W22942 Casual
2016-08-05 08:30:00 354045 8/5/2016 8:36 31069 Pershing & N George Mason Dr 31037 Ballston Metro / N Stuart & 9th St N W22247 Registered
2016-08-05 08:29:00 922428 8/5/2016 8:44 31619 Lincoln Park / 13th & East Capitol St NE 31243 Maryland & Independence Ave SW W20704 Casual
2016-08-05 08:29:00 1134407 8/5/2016 8:48 31630 15th & East Capitol St NE 31232 7th & F St NW / National Portrait Gallery W00623 Registered
2016-08-05 08:29:00 1188689 8/5/2016 8:48 31501 12th & Newton St NE 31623 Columbus Circle / Union Station W21824 Registered
2016-08-05 08:29:00 772042 8/5/2016 8:42 31222 New York Ave & 15th St NW 31267 17th St & Massachusetts Ave NW W22726 Registered
2016-08-05 08:29:00 490880 8/5/2016 8:37 31234 20th & O St NW / Dupont South 31225 C & O Canal & Wisconsin Ave NW W21108 Registered
2016-08-05 08:29:00 1114195 8/5/2016 8:48 31281 8th & O St NW 31215 Georgetown Harbor / 30th St NW W22584 Registered
2016-08-05 08:29:00 448158 8/5/2016 8:36 31048 King St Metro South 31042 Market Square / King St & Royal St W21279 Registered
... ... ... ... ... ... ... ... ...
2016-08-05 06:36:00 1033459 8/5/2016 6:53 31282 16th & R St NW 31507 1st & Washington Hospital Center NW W00169 Registered
2016-08-05 06:36:00 621286 8/5/2016 6:47 31251 12th & L St NW 31250 20th & L St NW W22412 Registered
2016-08-05 06:35:00 856046 8/5/2016 6:49 31512 Neal St & Trinidad Ave NE 31232 7th & F St NW / National Portrait Gallery W22201 Registered
2016-08-05 06:35:00 664615 8/5/2016 6:46 31220 US Dept of State / Virginia Ave & 21st St NW 31219 10th St & Constitution Ave NW W22888 Registered
2016-08-05 06:35:00 786647 8/5/2016 6:48 31207 Georgia Ave and Fairmont St NW 31233 17th & K St NW / Farragut Square W20178 Registered
2016-08-05 06:36:00 746038 8/5/2016 6:48 31619 Lincoln Park / 13th & East Capitol St NE 31217 USDA / 12th & Independence Ave SW W21123 Registered
2016-08-05 06:36:00 1118278 8/5/2016 6:54 31113 Columbia Rd & Belmont St NW 31507 1st & Washington Hospital Center NW W20887 Registered
2016-08-05 06:36:00 700573 8/5/2016 6:47 31623 Columbus Circle / Union Station 31244 4th & E St SW W21322 Registered
2016-08-05 06:34:00 261626 8/5/2016 6:38 31615 6th & H St NE 31623 Columbus Circle / Union Station W21821 Registered
2016-08-05 06:34:00 597659 8/5/2016 6:44 31611 13th & H St NE 31624 North Capitol St & F St NW W22308 Registered
2016-08-05 06:34:00 593128 8/5/2016 6:44 31118 3rd & Elm St NW 31600 5th & K St NW W21589 Registered
2016-08-05 06:34:00 1215491 8/5/2016 6:55 31231 14th & D St NW / Ronald Reagan Building 31625 3rd & G St SE W20024 Registered
2016-08-05 06:33:00 247143 8/5/2016 6:37 31115 Columbia Rd & Georgia Ave NW 31400 Georgia & New Hampshire Ave NW W20013 Registered
2016-08-05 06:33:00 204665 8/5/2016 6:36 31631 8th & F St NE 31623 Columbus Circle / Union Station W00208 Registered
2016-08-05 06:33:00 294946 8/5/2016 6:38 31280 11th & S St NW 31254 15th & K St NW W21439 Registered
2016-08-05 06:33:00 1105786 8/5/2016 6:52 31313 Connecticut Ave & Tilden St NW 31211 Kennedy Center W22720 Registered
2016-08-05 06:32:00 935290 8/5/2016 6:47 31307 3000 Connecticut Ave NW / National Zoo 31105 14th & Harvard St NW W00864 Registered
2016-08-05 06:32:00 220613 8/5/2016 6:36 31016 Clarendon Blvd & Pierce St 31077 Iwo Jima Memorial/N Meade & 14th St N W21620 Registered
2016-08-05 06:32:00 519391 8/5/2016 6:41 31111 10th & U St NW 31212 21st & M St NW W22558 Registered
2016-08-05 06:32:00 1586853 8/5/2016 6:58 31202 14th & R St NW 31308 39th & Veazey St NW W20019 Registered
2016-08-05 06:32:00 732204 8/5/2016 6:44 31119 14th & Belmont St NW 31276 15th & L St NW W22524 Registered
2016-08-05 06:32:00 1067856 8/5/2016 6:50 31630 15th & East Capitol St NE 31247 Jefferson Dr & 14th St SW W21274 Registered
2016-08-05 06:31:00 585408 8/5/2016 6:41 31213 17th & K St NW 31101 14th & V St NW W22050 Registered
2016-08-05 06:30:00 733622 8/5/2016 6:42 31245 7th & R St NW / Shaw Library 31506 1st & Rhode Island Ave NW W20375 Casual
2016-08-05 06:30:00 550900 8/5/2016 6:39 31280 11th & S St NW 31212 21st & M St NW W22324 Registered
2016-08-05 06:30:00 789918 8/5/2016 6:43 31245 7th & R St NW / Shaw Library 31506 1st & Rhode Island Ave NW W01078 Casual
2016-08-05 06:30:00 1830336 8/5/2016 7:00 31310 Connecticut & Nebraska Ave NW 32028 Norfolk & Rugby Ave W00510 Registered
2016-08-05 06:30:00 233967 8/5/2016 6:34 31600 5th & K St NW 31228 8th & H St NW W21807 Registered
2016-08-05 06:30:00 168462 8/5/2016 6:33 31212 21st & M St NW 31221 18th & M St NW W01026 Registered
2016-08-05 06:30:00 1083295 8/5/2016 6:48 31008 12th & Army Navy Dr 31249 Jefferson Memorial W22635 Registered

1575 rows × 8 columns


In [98]:
red_nondelayed = nodelay_rides_all[nodelay_rides_all['Start station'].isin(bikes_close['RD'])]
nonred_nondelayed = nodelay_rides_all[~nodelay_rides_all['Start station'].isin(bikes_close['RD'])]

In [99]:
print(len(red_nondelayed))
print(len(nonred_nondelayed))
print(red_nondelayed.groupby('Member Type')['Member Type'].count())


246
1329
Member Type
Casual         17
Registered    229
Name: Member Type, dtype: int64

In [100]:
red_nondelayed['count'] = 1


/Users/DDT1-Old/anaconda/lib/python3.6/site-packages/ipykernel/__main__.py:1: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  if __name__ == '__main__':

In [137]:
red_nondelayed['count'].resample('3T').sum().plot(kind ='box')


Out[137]:
<matplotlib.axes._subplots.AxesSubplot at 0x116e34f98>

In [136]:
red_nondelayed['count'].resample('3T').sum().plot(kind ='bar')


Out[136]:
<matplotlib.axes._subplots.AxesSubplot at 0x110c9acf8>

There is not an obvious difference based on the presence of a delay. Perhaps there is a larger 'change' on the day with the delay where as the day with no delay is just a gradual increase.


In [117]:
# figure out the number of rides before the delay
nodelay_rides_before = bikeshare_rides[str(nodelay_time - timedelta(hours=1)) : str(nodelay_time)]
red_nondelayed_before = nodelay_rides_before[nodelay_rides_before['Start station'].isin(bikes_close['RD'])]
nonred_nondelayed_before = nodelay_rides_before[~nodelay_rides_before['Start station'].isin(bikes_close['RD'])]

# figure out the number of rides after the delay

nodelay_rides_after = bikeshare_rides[str(nodelay_time) : str(nodelay_time + timedelta(hours=1))]
red_nondelayed_after = nodelay_rides_after[nodelay_rides_after['Start station'].isin(bikes_close['RD'])]
nonred_nondelayed_after = nodelay_rides_after[~nodelay_rides_after['Start station'].isin(bikes_close['RD'])]

print('red_nondelayed_before', len(red_nondelayed_before))
print('nonred_nondelayed_before', len(nonred_nondelayed_before))
print('red_nondelayed_after', len(red_nondelayed_after))
print('nonred_nondelayed_after', len(nonred_nondelayed_after))


red_nondelayed_before 74
nonred_nondelayed_before 432
red_nondelayed_after 174
nonred_nondelayed_after 908

red rides after delay time is 2.4 times larger than before delay time on non-delay day

Check a second delay on a different line


In [128]:
orange_delays = metro_delays[metro_delays['Line'] == 'Orange']
orange_delays


Out[128]:
Date Incident Line Direction Cause Delay time_stamp
Time
2016-09-23 16:00:00 9/23/2016 A Vienna-bound Orange Line train at Potomac A... Orange Vienna a brake problem 38.0 9/23/2016 4:00 pm
2016-09-22 06:04:00 9/22/2016 A Vienna-bound Orange Line train at New Carro... Orange Vienna a brake problem 36.0 9/22/2016 6:04 am
2016-09-17 07:00:00 9/17/2016 A Vienna-bound Orange Line train at New Carro... Orange Vienna a 3rd rail power problem 32.0 9/17/2016 7:00 am
2016-09-11 23:43:00 9/11/2016 A Vienna-bound Orange Line train at Landover ... Orange Vienna striking a deer 33.0 9/11/2016 11:43 pm
2016-09-04 14:16:00 9/4/2016 A Vienna-bound Orange Line train at McPherson... Orange Vienna a signal problem 42.0 9/4/2016 2:16 pm
2016-08-26 05:00:00 8/26/2016 A Vienna-bound Orange Line train at New Carro... Orange Vienna unscheduled track work 31.0 8/26/2016 5:00 am
2016-08-08 05:20:00 8/8/2016 A Vienna-bound Orange Line train at West Fall... Orange Vienna a signal problem 37.0 8/8/2016 5:20 am
2016-07-31 21:18:00 7/31/2016 A New Carrollton-bound Orange Line train at D... Orange New Carrollton-bound Orange Line train at Dunn... a brake problem 39.0 7/31/2016 9:18 pm
2016-07-20 12:50:00 7/20/2016 A Vienna-bound Orange Line train at Ballston-... Orange Vienna a brake problem 43.0 7/20/2016 12:50 pm
2016-07-18 22:30:00 7/18/2016 A Vienna-bound Orange Line train at Stadium-A... Orange Vienna due to a signal problem 33.0 7/18/2016 10:30 pm
2016-07-12 07:00:00 7/12/2016 A no-passenger Vienna-bound Orange Line train... Orange no-passenger Vienna-bound Orange Line train ou... a brake problem 30.0 7/12/2016 7:00 am
2016-07-05 16:49:00 7/5/2016 A Vienna-bound Orange Line train at outside C... Orange Vienna-bound Orange Line train at outside Cour... NaN 60.0 7/5/2016 4:49 pm

In [131]:
pd.to_datetime('2016-07-12 07:00:00').weekday_name


Out[131]:
'Tuesday'

In [ ]: