Dual Personalities of CitiBike

Travel Patterns of Bike commuters on weekdays & on weekends

In [1]:
import numpy as np
import matplotlib.pyplot as plt
import folium
import pandas as pd
from IPython.display import display
from PIL import Image

CitiBike in New York City

In [2]:
#citibike data Octobor, 2019
df= pd.read_csv("201910-citibike-tripdata.csv")
In [3]:
df.head()
Out[3]:
tripduration starttime stoptime start station id start station name start station latitude start station longitude end station id end station name end station latitude end station longitude bikeid usertype birth year gender
0 527 2019-10-01 00:00:05.6180 2019-10-01 00:08:52.9430 3746 6 Ave & Broome St 40.724308 -74.004730 223 W 13 St & 7 Ave 40.737815 -73.999947 41750 Subscriber 1993 1
1 174 2019-10-01 00:00:15.8750 2019-10-01 00:03:10.1680 3301 Columbus Ave & W 95 St 40.791956 -73.968087 3283 W 89 St & Columbus Ave 40.788221 -73.970416 18264 Subscriber 1992 1
2 759 2019-10-01 00:00:19.8240 2019-10-01 00:12:59.7070 161 LaGuardia Pl & W 3 St 40.729170 -73.998102 174 E 25 St & 1 Ave 40.738177 -73.977387 25525 Subscriber 1995 1
3 615 2019-10-01 00:00:21.0680 2019-10-01 00:10:36.6790 254 W 11 St & 6 Ave 40.735324 -73.998004 477 W 41 St & 8 Ave 40.756405 -73.990026 30186 Subscriber 1992 1
4 761 2019-10-01 00:00:26.3800 2019-10-01 00:13:08.3130 161 LaGuardia Pl & W 3 St 40.729170 -73.998102 174 E 25 St & 1 Ave 40.738177 -73.977387 25597 Subscriber 1992 1
In [4]:
df.dtypes
Out[4]:
tripduration                 int64
starttime                   object
stoptime                    object
start station id             int64
start station name          object
start station latitude     float64
start station longitude    float64
end station id               int64
end station name            object
end station latitude       float64
end station longitude      float64
bikeid                       int64
usertype                    object
birth year                   int64
gender                       int64
dtype: object
In [5]:
#focus on date and time 
#convert [string] to [datetime]
from datetime import datetime
df['stoptime_dt']= pd.to_datetime(df['stoptime'])
df['starttime_dt']=pd.to_datetime(df['starttime'])
In [6]:
df.head()
Out[6]:
tripduration starttime stoptime start station id start station name start station latitude start station longitude end station id end station name end station latitude end station longitude bikeid usertype birth year gender stoptime_dt starttime_dt
0 527 2019-10-01 00:00:05.6180 2019-10-01 00:08:52.9430 3746 6 Ave & Broome St 40.724308 -74.004730 223 W 13 St & 7 Ave 40.737815 -73.999947 41750 Subscriber 1993 1 2019-10-01 00:08:52.943 2019-10-01 00:00:05.618
1 174 2019-10-01 00:00:15.8750 2019-10-01 00:03:10.1680 3301 Columbus Ave & W 95 St 40.791956 -73.968087 3283 W 89 St & Columbus Ave 40.788221 -73.970416 18264 Subscriber 1992 1 2019-10-01 00:03:10.168 2019-10-01 00:00:15.875
2 759 2019-10-01 00:00:19.8240 2019-10-01 00:12:59.7070 161 LaGuardia Pl & W 3 St 40.729170 -73.998102 174 E 25 St & 1 Ave 40.738177 -73.977387 25525 Subscriber 1995 1 2019-10-01 00:12:59.707 2019-10-01 00:00:19.824
3 615 2019-10-01 00:00:21.0680 2019-10-01 00:10:36.6790 254 W 11 St & 6 Ave 40.735324 -73.998004 477 W 41 St & 8 Ave 40.756405 -73.990026 30186 Subscriber 1992 1 2019-10-01 00:10:36.679 2019-10-01 00:00:21.068
4 761 2019-10-01 00:00:26.3800 2019-10-01 00:13:08.3130 161 LaGuardia Pl & W 3 St 40.729170 -73.998102 174 E 25 St & 1 Ave 40.738177 -73.977387 25597 Subscriber 1992 1 2019-10-01 00:13:08.313 2019-10-01 00:00:26.380

Question: On weekday, is rush-hour commute for the most part and probably from home to work? On weekend, is the riding pattern longer, more casual?

Hypothesis: People always use Citi Bike to commute to work, and cycle to relax on weekends.

In [7]:
# get the day of week
#df['weekday'] = df [].dt.weekday
# Datetime: from time (stoptime) to days of the week; 
df['weekday'] = df['stoptime_dt'].dt.weekday
df.head()
Out[7]:
tripduration starttime stoptime start station id start station name start station latitude start station longitude end station id end station name end station latitude end station longitude bikeid usertype birth year gender stoptime_dt starttime_dt weekday
0 527 2019-10-01 00:00:05.6180 2019-10-01 00:08:52.9430 3746 6 Ave & Broome St 40.724308 -74.004730 223 W 13 St & 7 Ave 40.737815 -73.999947 41750 Subscriber 1993 1 2019-10-01 00:08:52.943 2019-10-01 00:00:05.618 1
1 174 2019-10-01 00:00:15.8750 2019-10-01 00:03:10.1680 3301 Columbus Ave & W 95 St 40.791956 -73.968087 3283 W 89 St & Columbus Ave 40.788221 -73.970416 18264 Subscriber 1992 1 2019-10-01 00:03:10.168 2019-10-01 00:00:15.875 1
2 759 2019-10-01 00:00:19.8240 2019-10-01 00:12:59.7070 161 LaGuardia Pl & W 3 St 40.729170 -73.998102 174 E 25 St & 1 Ave 40.738177 -73.977387 25525 Subscriber 1995 1 2019-10-01 00:12:59.707 2019-10-01 00:00:19.824 1
3 615 2019-10-01 00:00:21.0680 2019-10-01 00:10:36.6790 254 W 11 St & 6 Ave 40.735324 -73.998004 477 W 41 St & 8 Ave 40.756405 -73.990026 30186 Subscriber 1992 1 2019-10-01 00:10:36.679 2019-10-01 00:00:21.068 1
4 761 2019-10-01 00:00:26.3800 2019-10-01 00:13:08.3130 161 LaGuardia Pl & W 3 St 40.729170 -73.998102 174 E 25 St & 1 Ave 40.738177 -73.977387 25597 Subscriber 1992 1 2019-10-01 00:13:08.313 2019-10-01 00:00:26.380 1
In [8]:
# Datetime Library: M = 0; T = 1; W = 2; TH = 3; F = 4; Sat = 5; SUN = 6
# convert [int64] to [string]
df['weekday'] = df['weekday'].apply(str)
df['weekday'].dtypes
Out[8]:
dtype('O')
In [9]:
# df.groupby().size; to calculate which day in a week is the busiest riding day
weekday = df.groupby('weekday').size()
p = weekday.plot(kind='barh', figsize=(6, 5), color='#a4afb0', width=0.6, grid = True)
p.set_xlabel("Total Number of Riders", labelpad=20, size=14)
p.set_ylabel("Weekday", labelpad=20,size=14)
Out[9]:
Text(0, 0.5, 'Weekday')

More people using Citi Bike on weekdays than on weekends. Max: Tuesday; Min: Sunday I'll use Tuesday and Sunday as sample to prove my hypothesis.

(1) Weekday Rush Hour: 08:00 - 10:00 am

In [10]:
#get hh:mm from 'stoptime_dt'
df['hh'] = df['stoptime_dt'].dt.strftime('%H')
df.head()
Out[10]:
tripduration starttime stoptime start station id start station name start station latitude start station longitude end station id end station name end station latitude end station longitude bikeid usertype birth year gender stoptime_dt starttime_dt weekday hh
0 527 2019-10-01 00:00:05.6180 2019-10-01 00:08:52.9430 3746 6 Ave & Broome St 40.724308 -74.004730 223 W 13 St & 7 Ave 40.737815 -73.999947 41750 Subscriber 1993 1 2019-10-01 00:08:52.943 2019-10-01 00:00:05.618 1 00
1 174 2019-10-01 00:00:15.8750 2019-10-01 00:03:10.1680 3301 Columbus Ave & W 95 St 40.791956 -73.968087 3283 W 89 St & Columbus Ave 40.788221 -73.970416 18264 Subscriber 1992 1 2019-10-01 00:03:10.168 2019-10-01 00:00:15.875 1 00
2 759 2019-10-01 00:00:19.8240 2019-10-01 00:12:59.7070 161 LaGuardia Pl & W 3 St 40.729170 -73.998102 174 E 25 St & 1 Ave 40.738177 -73.977387 25525 Subscriber 1995 1 2019-10-01 00:12:59.707 2019-10-01 00:00:19.824 1 00
3 615 2019-10-01 00:00:21.0680 2019-10-01 00:10:36.6790 254 W 11 St & 6 Ave 40.735324 -73.998004 477 W 41 St & 8 Ave 40.756405 -73.990026 30186 Subscriber 1992 1 2019-10-01 00:10:36.679 2019-10-01 00:00:21.068 1 00
4 761 2019-10-01 00:00:26.3800 2019-10-01 00:13:08.3130 161 LaGuardia Pl & W 3 St 40.729170 -73.998102 174 E 25 St & 1 Ave 40.738177 -73.977387 25597 Subscriber 1992 1 2019-10-01 00:13:08.313 2019-10-01 00:00:26.380 1 00
In [11]:
#select riders from 8-10 am on Tuesday(weekdays)
df[(df['weekday']== '1') & (df['hh'].isin(['08','09']))]
Out[11]:
tripduration starttime stoptime start station id start station name start station latitude start station longitude end station id end station name end station latitude end station longitude bikeid usertype birth year gender stoptime_dt starttime_dt weekday hh
2729 7152 2019-10-01 06:30:35.5570 2019-10-01 08:29:47.7280 422 W 59 St & 10 Ave 40.770513 -73.988038 520 W 52 St & 5 Ave 40.759923 -73.976485 41551 Subscriber 1994 2 2019-10-01 08:29:47.728 2019-10-01 06:30:35.557 1 08
3489 5731 2019-10-01 06:47:47.9430 2019-10-01 08:23:19.5090 3287 W 87 St & West End Ave 40.789622 -73.977570 3287 W 87 St & West End Ave 40.789622 -73.977570 41904 Subscriber 1957 1 2019-10-01 08:23:19.509 2019-10-01 06:47:47.943 1 08
3589 8336 2019-10-01 06:49:20.5670 2019-10-01 09:08:17.3110 3687 E 33 St & 1 Ave 40.743227 -73.974498 3687 E 33 St & 1 Ave 40.743227 -73.974498 18049 Customer 1987 2 2019-10-01 09:08:17.311 2019-10-01 06:49:20.567 1 09
5047 2753 2019-10-01 07:14:59.8410 2019-10-01 08:00:52.9180 3047 Halsey St & Tompkins Ave 40.682369 -73.944118 359 E 47 St & Park Ave 40.755103 -73.974987 24911 Subscriber 1989 1 2019-10-01 08:00:52.918 2019-10-01 07:14:59.841 1 08
5134 2854 2019-10-01 07:16:10.2820 2019-10-01 08:03:44.5910 503 E 20 St & Park Ave 40.738274 -73.987520 3567 11 St & 35 Ave 40.762744 -73.939114 38238 Customer 1969 0 2019-10-01 08:03:44.591 2019-10-01 07:16:10.282 1 08
5528 3035 2019-10-01 07:21:36.1810 2019-10-01 08:12:11.5750 516 E 47 St & 1 Ave 40.752069 -73.967844 477 W 41 St & 8 Ave 40.756405 -73.990026 15163 Subscriber 1956 1 2019-10-01 08:12:11.575 2019-10-01 07:21:36.181 1 08
5542 2898 2019-10-01 07:21:50.4270 2019-10-01 08:10:08.9920 473 Rivington St & Chrystie St 40.721101 -73.991925 250 Lafayette St & Jersey St 40.724561 -73.995653 35307 Subscriber 1983 1 2019-10-01 08:10:08.992 2019-10-01 07:21:50.427 1 08
5615 5485 2019-10-01 07:23:03.7440 2019-10-01 08:54:29.2230 3686 Gansevoort St & Hudson St 40.739448 -74.005070 3686 Gansevoort St & Hudson St 40.739448 -74.005070 40799 Subscriber 1961 1 2019-10-01 08:54:29.223 2019-10-01 07:23:03.744 1 08
5662 2277 2019-10-01 07:23:53.0620 2019-10-01 08:01:50.5130 3498 Pleasant Ave & E 120 St 40.797477 -73.931185 164 E 47 St & 2 Ave 40.753231 -73.970325 41729 Subscriber 1969 2 2019-10-01 08:01:50.513 2019-10-01 07:23:53.062 1 08
5688 3165 2019-10-01 07:24:12.5110 2019-10-01 08:16:58.1210 2008 Little West St & 1 Pl 40.705693 -74.016777 2008 Little West St & 1 Pl 40.705693 -74.016777 38143 Customer 1991 2 2019-10-01 08:16:58.121 2019-10-01 07:24:12.511 1 08
5690 2290 2019-10-01 07:24:15.9470 2019-10-01 08:02:26.1180 485 W 37 St & 5 Ave 40.750380 -73.983390 3495 E 114 St & 1 Ave 40.794566 -73.936254 17217 Subscriber 1987 1 2019-10-01 08:02:26.118 2019-10-01 07:24:15.947 1 08
5734 2340 2019-10-01 07:25:01.3200 2019-10-01 08:04:02.2070 3508 St Nicholas Ave & Manhattan Ave 40.809725 -73.953149 490 8 Ave & W 33 St 40.751551 -73.993934 40579 Subscriber 1975 1 2019-10-01 08:04:02.207 2019-10-01 07:25:01.320 1 08
5781 2158 2019-10-01 07:25:39.6240 2019-10-01 08:01:38.1090 494 W 26 St & 8 Ave 40.747348 -73.997236 351 Front St & Maiden Ln 40.705310 -74.006126 41357 Subscriber 1996 2 2019-10-01 08:01:38.109 2019-10-01 07:25:39.624 1 08
5783 2277 2019-10-01 07:25:41.7810 2019-10-01 08:03:38.9670 380 W 4 St & 7 Ave S 40.734011 -74.002939 3169 Riverside Dr & W 82 St 40.787209 -73.981281 31011 Subscriber 1985 2 2019-10-01 08:03:38.967 2019-10-01 07:25:41.781 1 08
5794 2388 2019-10-01 07:25:53.5340 2019-10-01 08:05:41.9000 3553 Frederick Douglass Blvd & W 112 St 40.801694 -73.957145 3553 Frederick Douglass Blvd & W 112 St 40.801694 -73.957145 38843 Subscriber 1962 2 2019-10-01 08:05:41.900 2019-10-01 07:25:53.534 1 08
5840 2091 2019-10-01 07:26:34.3160 2019-10-01 08:01:25.8960 3443 W 52 St & 6 Ave 40.761330 -73.979820 468 Broadway & W 56 St 40.765265 -73.981923 41481 Subscriber 1968 1 2019-10-01 08:01:25.896 2019-10-01 07:26:34.316 1 08
5866 2492 2019-10-01 07:26:55.0490 2019-10-01 08:08:27.6550 3409 Bergen St & Smith St 40.686744 -73.990632 3647 48 Ave & 30 Pl 40.741283 -73.937259 39219 Subscriber 1995 2 2019-10-01 08:08:27.655 2019-10-01 07:26:55.049 1 08
5875 2035 2019-10-01 07:27:04.4540 2019-10-01 08:01:00.3020 3321 Clinton St & Union St 40.683116 -73.997853 458 11 Ave & W 27 St 40.751396 -74.005226 29066 Subscriber 1973 1 2019-10-01 08:01:00.302 2019-10-01 07:27:04.454 1 08
5876 2005 2019-10-01 07:27:05.0810 2019-10-01 08:00:30.0930 3301 Columbus Ave & W 95 St 40.791956 -73.968087 455 1 Ave & E 44 St 40.750020 -73.969053 16143 Subscriber 1968 2 2019-10-01 08:00:30.093 2019-10-01 07:27:05.081 1 08
5884 2411 2019-10-01 07:27:12.0170 2019-10-01 08:07:23.7710 3303 Butler St & Court St 40.684989 -73.994403 455 1 Ave & E 44 St 40.750020 -73.969053 29799 Subscriber 1970 1 2019-10-01 08:07:23.771 2019-10-01 07:27:12.017 1 08
5905 2251 2019-10-01 07:27:23.4080 2019-10-01 08:04:54.8920 3255 8 Ave & W 31 St 40.750585 -73.994685 360 William St & Pine St 40.707179 -74.008873 39338 Subscriber 1962 1 2019-10-01 08:04:54.892 2019-10-01 07:27:23.408 1 08
5908 2130 2019-10-01 07:27:25.0200 2019-10-01 08:02:55.9180 3534 Frederick Douglass Blvd & W 117 St 40.805159 -73.954692 3129 Queens Plaza North & Crescent St 40.751102 -73.940737 41327 Subscriber 1992 2 2019-10-01 08:02:55.918 2019-10-01 07:27:25.020 1 08
5970 2274 2019-10-01 07:28:08.7140 2019-10-01 08:06:02.9260 3290 E 89 St & York Ave 40.777945 -73.946041 3360 Amsterdam Ave & W 79 St 40.782939 -73.978652 32234 Subscriber 1970 1 2019-10-01 08:06:02.926 2019-10-01 07:28:08.714 1 08
5993 1916 2019-10-01 07:28:28.3460 2019-10-01 08:00:25.2920 427 Bus Slip & State St 40.701907 -74.013942 516 E 47 St & 1 Ave 40.752069 -73.967844 26386 Subscriber 1959 2 2019-10-01 08:00:25.292 2019-10-01 07:28:28.346 1 08
6016 1985 2019-10-01 07:28:49.4720 2019-10-01 08:01:54.6600 3255 8 Ave & W 31 St 40.750585 -73.994685 530 11 Ave & W 59 St 40.771497 -73.990460 41957 Subscriber 1971 1 2019-10-01 08:01:54.660 2019-10-01 07:28:49.472 1 08
6037 2283 2019-10-01 07:29:03.4140 2019-10-01 08:07:07.3550 490 8 Ave & W 33 St 40.751551 -73.993934 3141 1 Ave & E 68 St 40.765005 -73.958185 34953 Subscriber 1987 2 2019-10-01 08:07:07.355 2019-10-01 07:29:03.414 1 08
6044 2168 2019-10-01 07:29:10.6520 2019-10-01 08:05:19.6050 343 Clinton Ave & Flushing Ave 40.697940 -73.969868 3128 21 St & 43 Ave 40.750525 -73.945948 27729 Subscriber 1993 1 2019-10-01 08:05:19.605 2019-10-01 07:29:10.652 1 08
6049 2885 2019-10-01 07:29:14.0420 2019-10-01 08:17:19.8760 3728 Pierrepont St & Monroe Pl 40.695357 -73.993440 500 Broadway & W 51 St 40.762288 -73.983362 28208 Subscriber 1972 1 2019-10-01 08:17:19.876 2019-10-01 07:29:14.042 1 08
6059 2303 2019-10-01 07:29:20.7760 2019-10-01 08:07:44.7040 289 Monroe St & Classon Ave 40.684568 -73.958811 116 W 17 St & 8 Ave 40.741776 -74.001497 41632 Subscriber 1981 2 2019-10-01 08:07:44.704 2019-10-01 07:29:20.776 1 08
6085 1853 2019-10-01 07:29:40.8270 2019-10-01 08:00:34.1460 3295 Central Park W & W 96 St 40.791270 -73.964839 3641 Broadway & W 25 St 40.742869 -73.989186 41697 Subscriber 1969 2 2019-10-01 08:00:34.146 2019-10-01 07:29:40.827 1 08
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
1941773 209 2019-10-29 09:53:53.8520 2019-10-29 09:57:23.1400 3087 Metropolitan Ave & Meeker Ave 40.714133 -73.952344 3093 N 6 St & Bedford Ave 40.717452 -73.958509 25237 Subscriber 1993 1 2019-10-29 09:57:23.140 2019-10-29 09:53:53.852 1 09
1941777 201 2019-10-29 09:54:00.8040 2019-10-29 09:57:22.2280 3788 E 12 St & 4 Av 40.732690 -73.989740 496 E 16 St & 5 Ave 40.737262 -73.992390 30309 Subscriber 1992 1 2019-10-29 09:57:22.228 2019-10-29 09:54:00.804 1 09
1941785 165 2019-10-29 09:54:06.6050 2019-10-29 09:56:51.9540 485 W 37 St & 5 Ave 40.750380 -73.983390 526 E 33 St & 5 Ave 40.747659 -73.984907 14988 Subscriber 1986 1 2019-10-29 09:56:51.954 2019-10-29 09:54:06.605 1 09
1941786 311 2019-10-29 09:54:09.5650 2019-10-29 09:59:21.4500 437 Macon St & Nostrand Ave 40.680983 -73.950048 3241 Monroe St & Tompkins Ave 40.686203 -73.944694 40732 Subscriber 1985 2 2019-10-29 09:59:21.450 2019-10-29 09:54:09.565 1 09
1941791 84 2019-10-29 09:54:12.8890 2019-10-29 09:55:37.1550 3399 7 St & 3 Ave 40.672603 -73.989830 3403 4 Ave & 9 St 40.670513 -73.988766 32604 Subscriber 1981 1 2019-10-29 09:55:37.155 2019-10-29 09:54:12.889 1 09
1941793 204 2019-10-29 09:54:14.6220 2019-10-29 09:57:39.4020 3424 E 106 St & Lexington Ave 40.791976 -73.945993 3379 E 103 St & Lexington Ave 40.790305 -73.947558 15442 Subscriber 1970 2 2019-10-29 09:57:39.402 2019-10-29 09:54:14.622 1 09
1941797 309 2019-10-29 09:54:16.7790 2019-10-29 09:59:26.4590 312 Allen St & Stanton St 40.722055 -73.989111 504 1 Ave & E 16 St 40.732219 -73.981656 35066 Subscriber 1985 1 2019-10-29 09:59:26.459 2019-10-29 09:54:16.779 1 09
1941805 313 2019-10-29 09:54:19.6660 2019-10-29 09:59:33.4210 483 E 12 St & 3 Ave 40.732233 -73.988900 432 E 7 St & Avenue A 40.726218 -73.983799 14762 Subscriber 2000 1 2019-10-29 09:59:33.421 2019-10-29 09:54:19.666 1 09
1941811 258 2019-10-29 09:54:28.9950 2019-10-29 09:58:47.2810 489 10 Ave & W 28 St 40.750664 -74.001768 3255 8 Ave & W 31 St 40.750585 -73.994685 40049 Subscriber 1989 1 2019-10-29 09:58:47.281 2019-10-29 09:54:28.995 1 09
1941812 235 2019-10-29 09:54:29.2930 2019-10-29 09:58:25.1370 533 Broadway & W 38 St 40.752996 -73.987216 3235 E 41 St & Madison Ave 40.752165 -73.979922 32782 Subscriber 1988 1 2019-10-29 09:58:25.137 2019-10-29 09:54:29.293 1 09
1941815 151 2019-10-29 09:54:30.8900 2019-10-29 09:57:02.0180 3817 Withers St & Kingsland Ave 40.717730 -73.940510 3086 Graham Ave & Conselyea St 40.715143 -73.944507 29789 Subscriber 2000 1 2019-10-29 09:57:02.018 2019-10-29 09:54:30.890 1 09
1941824 291 2019-10-29 09:54:43.1310 2019-10-29 09:59:34.4220 3361 Carroll St & 6 Ave 40.674089 -73.978728 3373 3 St & 3 Ave 40.675071 -73.987752 35290 Subscriber 1960 2 2019-10-29 09:59:34.422 2019-10-29 09:54:43.131 1 09
1941829 234 2019-10-29 09:54:50.8790 2019-10-29 09:58:45.6130 3108 Nassau Ave & Russell St 40.725570 -73.944340 3668 Leonard St & Nassau Ave 40.723957 -73.949844 32495 Subscriber 1968 2 2019-10-29 09:58:45.613 2019-10-29 09:54:50.879 1 09
1941839 132 2019-10-29 09:55:02.6810 2019-10-29 09:57:15.6770 335 Washington Pl & Broadway 40.729039 -73.994046 252 MacDougal St & Washington Sq 40.732264 -73.998522 34846 Subscriber 1980 2 2019-10-29 09:57:15.677 2019-10-29 09:55:02.681 1 09
1941841 210 2019-10-29 09:55:05.1280 2019-10-29 09:58:35.2240 513 W 56 St & 10 Ave 40.768254 -73.988639 468 Broadway & W 56 St 40.765265 -73.981923 33044 Subscriber 1985 1 2019-10-29 09:58:35.224 2019-10-29 09:55:05.128 1 09
1941849 216 2019-10-29 09:55:12.1130 2019-10-29 09:58:48.7230 3440 Fulton St & Adams St 40.692418 -73.989495 321 Cadman Plaza E & Red Cross Pl 40.699918 -73.989718 40475 Subscriber 1985 2 2019-10-29 09:58:48.723 2019-10-29 09:55:12.113 1 09
1941853 89 2019-10-29 09:55:14.7200 2019-10-29 09:56:43.9810 3536 W 116 St & Broadway 40.808200 -73.964100 3623 W 120 St & Claremont Ave 40.810949 -73.963400 40940 Subscriber 1992 2 2019-10-29 09:56:43.981 2019-10-29 09:55:14.720 1 09
1941860 160 2019-10-29 09:55:24.0100 2019-10-29 09:58:04.4940 3140 1 Ave & E 78 St 40.771404 -73.953517 3725 2 Ave & E 72 St 40.768762 -73.958408 41638 Subscriber 1985 1 2019-10-29 09:58:04.494 2019-10-29 09:55:24.010 1 09
1941867 265 2019-10-29 09:55:31.0380 2019-10-29 09:59:56.9680 264 Maiden Ln & Pearl St 40.707065 -74.007319 304 Broadway & Battery Pl 40.704633 -74.013617 19977 Subscriber 1990 2 2019-10-29 09:59:56.968 2019-10-29 09:55:31.038 1 09
1941873 251 2019-10-29 09:55:38.7790 2019-10-29 09:59:50.3140 508 W 46 St & 11 Ave 40.763414 -73.996674 2021 W 45 St & 8 Ave 40.759291 -73.988597 38440 Subscriber 1956 2 2019-10-29 09:59:50.314 2019-10-29 09:55:38.779 1 09
1941876 166 2019-10-29 09:55:40.1310 2019-10-29 09:58:26.8770 3349 Grand Army Plaza & Plaza St West 40.672968 -73.970880 3346 Berkeley Pl & 7 Ave 40.675147 -73.975232 28386 Subscriber 1992 1 2019-10-29 09:58:26.877 2019-10-29 09:55:40.131 1 09
1941878 253 2019-10-29 09:55:40.6320 2019-10-29 09:59:54.1770 525 W 34 St & 11 Ave 40.755942 -74.002116 459 W 20 St & 11 Ave 40.746745 -74.007756 26727 Subscriber 1991 1 2019-10-29 09:59:54.177 2019-10-29 09:55:40.632 1 09
1941886 94 2019-10-29 09:55:51.3520 2019-10-29 09:57:26.3390 3107 Bedford Ave & Nassau Ave 40.723117 -73.952123 3101 N 12 St & Bedford Ave 40.720798 -73.954847 32742 Subscriber 1976 1 2019-10-29 09:57:26.339 2019-10-29 09:55:51.352 1 09
1941892 192 2019-10-29 09:55:59.2470 2019-10-29 09:59:12.0730 3042 Fulton St & Utica Ave 40.679427 -73.929891 3046 Marcus Garvey Blvd & Macon St 40.682601 -73.938037 27923 Subscriber 1990 1 2019-10-29 09:59:12.073 2019-10-29 09:55:59.247 1 09
1941897 150 2019-10-29 09:56:08.6140 2019-10-29 09:58:39.1260 446 W 24 St & 7 Ave 40.744876 -73.995299 453 W 22 St & 8 Ave 40.744751 -73.999154 38573 Subscriber 1934 2 2019-10-29 09:58:39.126 2019-10-29 09:56:08.614 1 09
1941928 192 2019-10-29 09:56:31.2380 2019-10-29 09:59:44.0990 3306 10 St & 7 Ave 40.666208 -73.981999 3365 3 St & 7 Ave 40.670384 -73.978397 30081 Subscriber 1969 2 2019-10-29 09:59:44.099 2019-10-29 09:56:31.238 1 09
1941937 144 2019-10-29 09:56:39.9200 2019-10-29 09:59:04.6470 3140 1 Ave & E 78 St 40.771404 -73.953517 3148 E 84 St & 1 Ave 40.775655 -73.950686 40765 Subscriber 1985 1 2019-10-29 09:59:04.647 2019-10-29 09:56:39.920 1 09
1941948 158 2019-10-29 09:56:52.2130 2019-10-29 09:59:30.9860 493 W 45 St & 6 Ave 40.756800 -73.982912 479 9 Ave & W 45 St 40.760193 -73.991255 38368 Subscriber 1979 1 2019-10-29 09:59:30.986 2019-10-29 09:56:52.213 1 09
1942008 118 2019-10-29 09:57:49.0950 2019-10-29 09:59:47.6460 525 W 34 St & 11 Ave 40.755942 -74.002116 458 11 Ave & W 27 St 40.751396 -74.005226 31438 Subscriber 1990 2 2019-10-29 09:59:47.646 2019-10-29 09:57:49.095 1 09
2086192 390969 2019-10-31 20:31:54.8710 2019-11-05 08:08:04.8530 3075 Division Ave & Marcy Ave 40.707087 -73.957968 3075 Division Ave & Marcy Ave 40.707087 -73.957968 20198 Customer 1969 0 2019-11-05 08:08:04.853 2019-10-31 20:31:54.871 1 08

70397 rows × 19 columns

In [12]:
df1 = df[(df['weekday']== '1') & (df['hh'].isin(['08','09']))]
df1.head()
Out[12]:
tripduration starttime stoptime start station id start station name start station latitude start station longitude end station id end station name end station latitude end station longitude bikeid usertype birth year gender stoptime_dt starttime_dt weekday hh
2729 7152 2019-10-01 06:30:35.5570 2019-10-01 08:29:47.7280 422 W 59 St & 10 Ave 40.770513 -73.988038 520 W 52 St & 5 Ave 40.759923 -73.976485 41551 Subscriber 1994 2 2019-10-01 08:29:47.728 2019-10-01 06:30:35.557 1 08
3489 5731 2019-10-01 06:47:47.9430 2019-10-01 08:23:19.5090 3287 W 87 St & West End Ave 40.789622 -73.977570 3287 W 87 St & West End Ave 40.789622 -73.977570 41904 Subscriber 1957 1 2019-10-01 08:23:19.509 2019-10-01 06:47:47.943 1 08
3589 8336 2019-10-01 06:49:20.5670 2019-10-01 09:08:17.3110 3687 E 33 St & 1 Ave 40.743227 -73.974498 3687 E 33 St & 1 Ave 40.743227 -73.974498 18049 Customer 1987 2 2019-10-01 09:08:17.311 2019-10-01 06:49:20.567 1 09
5047 2753 2019-10-01 07:14:59.8410 2019-10-01 08:00:52.9180 3047 Halsey St & Tompkins Ave 40.682369 -73.944118 359 E 47 St & Park Ave 40.755103 -73.974987 24911 Subscriber 1989 1 2019-10-01 08:00:52.918 2019-10-01 07:14:59.841 1 08
5134 2854 2019-10-01 07:16:10.2820 2019-10-01 08:03:44.5910 503 E 20 St & Park Ave 40.738274 -73.987520 3567 11 St & 35 Ave 40.762744 -73.939114 38238 Customer 1969 0 2019-10-01 08:03:44.591 2019-10-01 07:16:10.282 1 08
In [13]:
#Geodataframe 
import geopandas
from shapely.geometry import Point
import warnings
warnings.simplefilter('ignore')
In [14]:
#list(zip(df1['longitude'],df1['latitude']))
df1['endcoordinates'] = list(zip(df1['end station longitude'],df1['end station latitude']))
In [15]:
# df1['coordinates'].apply(Point)
df1['endcoordinates'] = df1['endcoordinates'].apply(Point)
In [16]:
gdf_Tuesday = geopandas.GeoDataFrame(df1, geometry='endcoordinates')
In [17]:
gdf_Tuesday.head()
Out[17]:
tripduration starttime stoptime start station id start station name start station latitude start station longitude end station id end station name end station latitude end station longitude bikeid usertype birth year gender stoptime_dt starttime_dt weekday hh endcoordinates
2729 7152 2019-10-01 06:30:35.5570 2019-10-01 08:29:47.7280 422 W 59 St & 10 Ave 40.770513 -73.988038 520 W 52 St & 5 Ave 40.759923 -73.976485 41551 Subscriber 1994 2 2019-10-01 08:29:47.728 2019-10-01 06:30:35.557 1 08 POINT (-73.97649 40.75992)
3489 5731 2019-10-01 06:47:47.9430 2019-10-01 08:23:19.5090 3287 W 87 St & West End Ave 40.789622 -73.977570 3287 W 87 St & West End Ave 40.789622 -73.977570 41904 Subscriber 1957 1 2019-10-01 08:23:19.509 2019-10-01 06:47:47.943 1 08 POINT (-73.97757 40.78962)
3589 8336 2019-10-01 06:49:20.5670 2019-10-01 09:08:17.3110 3687 E 33 St & 1 Ave 40.743227 -73.974498 3687 E 33 St & 1 Ave 40.743227 -73.974498 18049 Customer 1987 2 2019-10-01 09:08:17.311 2019-10-01 06:49:20.567 1 09 POINT (-73.97450 40.74323)
5047 2753 2019-10-01 07:14:59.8410 2019-10-01 08:00:52.9180 3047 Halsey St & Tompkins Ave 40.682369 -73.944118 359 E 47 St & Park Ave 40.755103 -73.974987 24911 Subscriber 1989 1 2019-10-01 08:00:52.918 2019-10-01 07:14:59.841 1 08 POINT (-73.97499 40.75510)
5134 2854 2019-10-01 07:16:10.2820 2019-10-01 08:03:44.5910 503 E 20 St & Park Ave 40.738274 -73.987520 3567 11 St & 35 Ave 40.762744 -73.939114 38238 Customer 1969 0 2019-10-01 08:03:44.591 2019-10-01 07:16:10.282 1 08 POINT (-73.93911 40.76274)
In [18]:
gdf_Tuesday_rushhour = gdf_Tuesday[[
    'tripduration',
    'end station id',
    'end station name',
    'stoptime_dt',
    'starttime_dt',
    'weekday',
    'hh',
    'endcoordinates',
    'usertype',
    'birth year']]
In [19]:
gdf_Tuesday_rushhour.to_csv('gdf_Tuesday_rush_hour.csv')
In [20]:
# arriving: end station
arriving = gdf_Tuesday.groupby(['end station latitude','end station longitude','end station name']).size()
arriving.head(10)
Out[20]:
end station latitude  end station longitude  end station name                             
40.655400             -74.010628             39 St & 2 Ave - Citi Bike HQ at Industry City     7
40.657089             -74.008702             2 Ave & 36 St - Citi Bike HQ at Industry City    10
40.661063             -73.979453             West Drive & Prospect Park West                  27
40.662706             -73.956912             Sterling St & Bedford Ave                         3
40.663062             -73.953875             Rogers Ave & Sterling St                          5
40.663140             -73.960569             Franklin Ave & Empire Blvd                       14
40.663779             -73.983968             14 St & 7 Ave                                    10
40.665147             -73.976376             Prospect Park West & 8 St                        18
40.665816             -73.956934             Bedford Ave & Montgomery St                       1
40.666208             -73.981999             10 St & 7 Ave                                    18
dtype: int64
In [21]:
# arriving: end station
# Which stations are the busiest stations in rush hours on weekdays? 
arriving_sort = arriving.sort_values(ascending = False)
arriving_sort.head(5)
Out[21]:
end station latitude  end station longitude  end station name     
40.740343             -73.989551             Broadway & E 22 St       1025
40.755103             -73.974987             E 47 St & Park Ave        924
40.751873             -73.977706             Pershing Square North     793
40.717548             -74.013221             West St & Chambers St     722
40.740964             -73.986022             E 24 St & Park Ave S      711
dtype: int64
In [22]:
# Top 5 busiest station at rush hour on Tuesday: 
## Broadway & E 22 St
## E 47 St & Park Ave
## Pershing Square North
## West St & Chambers St
## E 24 St & Park Ave S
In [23]:
for i in range(10):
    print(arriving_sort.keys()[i])
(40.740343200000005, -73.98955109, 'Broadway & E 22 St')
(40.75510267, -73.97498696, 'E 47 St & Park Ave')
(40.751872999999996, -73.97770600000001, 'Pershing Square North')
(40.71754834, -74.01322069, 'West St & Chambers St')
(40.74096374, -73.98602213, 'E 24 St & Park Ave S')
(40.75724567911726, -73.97805914282799, 'E 48 St & 5 Ave')
(40.764397100000004, -73.97371465, 'Grand Army Plaza & Central Park S')
(40.751396, -74.00522600000001, '11 Ave & W 27 St')
(40.75513557, -73.98658032, 'Broadway & W 41 St')
(40.72243797, -74.00566443, '6 Ave & Canal St')
In [24]:
len(arriving_sort)
Out[24]:
810
In [25]:
# plot the arriving points on map(zoom Manhattan)
# m = folium.Map() 
latitude = []
longitude = []
number = []
for i in range(len(arriving_sort)):
    lat = arriving_sort.keys()[i][0]
    long = arriving_sort.keys()[i][1]
    total = arriving_sort[i]
    latitude.append(lat)
    longitude.append(long)
    number.append(total)

m = folium.Map(location=[40.76727216, -73.99392888], tiles='cartodbpositron',zoom_start = 12)
for j in range(0,len(latitude)):
    labels = number[j]
    folium.CircleMarker(
        location = [latitude[j],longitude[j]],
        radius = number[j]/100, 
        color = '#ce6dbd', 
        fill_color='#ce6dbd',
        popup=labels).add_to(m)
In [26]:
display(m)
In [27]:
#download the map 
m.save('html_map_output_Tuesday_rushhour.html')
In [28]:
riders_Tuesday = gdf_Tuesday.groupby(['birth year']).size()
riders_Tuesday.head(10)
Out[28]:
birth year
1888    2
1889    3
1890    1
1893    8
1900    9
1901    3
1907    1
1911    3
1917    1
1921    2
dtype: int64
In [29]:
riders_Tuesday_sort = riders_Tuesday.sort_values(ascending = False)
riders_Tuesday_sort.head(10).plot(
    kind='barh', 
    figsize=(6, 5), 
    color='#de7ad0', 
    width=0.6, 
    grid = True)
Out[29]:
<matplotlib.axes._subplots.AxesSubplot at 0x23a6a778eb8>
In [30]:
# Who rides during rush hour on Tuesday?
# 1990; 1989; 1992; 
# year-old: 29; 30; 27
In [31]:
trip_T = gdf_Tuesday.groupby(['tripduration']).size()
trip_T.head(10)
Out[31]:
tripduration
61     4
62     9
63     5
64     4
65    10
66    14
67     6
68     9
69    14
70     4
dtype: int64
In [32]:
trip_T_sort = trip_T.sort_values(ascending = False)
trip_T_sort.head(5).plot(
    kind='barh', 
    figsize=(6, 5), 
    color='#de7ad0', 
    width=0.6, 
    grid = True)
Out[32]:
<matplotlib.axes._subplots.AxesSubplot at 0x23a6aa987f0>
In [33]:
# In this case, more ridings are around 5 minutes.

Summary

New York City, NY- Nov. 22, 2019 - New Yorkers are a fan of cycling. According to the survey of NYC DOT, nearly eight-hundred thousand New Yorkers (793,000) ride a bicycle regularly. Citi Bike, one of the world’s largest bike shares, has surpassed 60 million trips by June 2018 since the system launch in 2013. Recently, Citi Bike releases its riding data, totaling around 2.1 million rides from last month. Including date, time, and arriving stations, the riding data provides an opportunity to investigate where people head to at morning rush hours on weekdays and which are the busiest station during rush hours.

According to an average of the riding data provided by Citi Bike, there are approximately 68,000 trips every day. Among the month, more people use Citi Bike on Tuesday(Chart1-1). And during rush hours (from 8:00 am to10:00am, and from 5:00 pm to 7:00 pm), over 40% of people choose a bicycle as their primary mode of commuting to work(Chart 1-2). The proximity from Citi Bike station to working place is the factor that riders consider while choosing the way to work.

Key finds from the Citi Bike data analysis show the following of arriving points during rush hours on a weekday morning (Sampling: Tuesday morning, 8 am to 10 am, October 2019)

1. In the morning, people head to different directions of the city, but more people ride to Midtown Manhattan and Downtown Manhattan where there are commercial office buildings and more companies.
2. Bicycle commuters are clustered at the stations that are close to business centers in New York City (Map1-1). This pattern displays several hubs which are related to businesses where people work. Top 5 busiest station at rush hour on Tuesday: (1) Broadway & E 22 St; (2) E 47 St & Park Ave; (3) Pershing Square North; (4) West St & Chambers St; (5) E 24 St & Park Ave S. These stations are near the area of banks, financial centers. For example, big-name banking enterprises are gathering around E 47 St & Park Ave.
3. Among these people who are daily riding commuters, most of them are around 30 years old. These young people make up the dominant parts of the business world. Even though the subways are accessible from their workplaces, they are more willing to try this healthy commuting mode.

Reference:

[1] Motivate International, Inc. (n.d.). About Citi Bike: Company, History, Motivate. Retrieved from https://www.citibikenyc.com/about.
[2] NYC DOT. (2019). Cycling In The City. CYCLING IN THE CITY. Retrieved from https://www1.nyc.gov/html/dot/downloads/pdf/cycling-in-the-city.pdf
[3] Shah, V. (2018, May 25). Citi Bike 2017 Analysis. Retrieved from https://towardsdatascience.com/citi-bike-2017-analysis-efd298e6c22c.

(2) Comparison, Weekend: 08:00 - 10:00 am

Does it have similar pattern as weekday?

CitiBike in New York City

In [34]:
# Comparision, Sunday(weekday=6) 8-10 am 
df2 = df[(df['weekday']== '6') & (df['hh'].isin(['08','09']))]
df2.head()
Out[34]:
tripduration starttime stoptime start station id start station name start station latitude start station longitude end station id end station name end station latitude end station longitude bikeid usertype birth year gender stoptime_dt starttime_dt weekday hh
239013 156125 2019-10-04 12:53:05.8890 2019-10-06 08:15:11.6120 3536 W 116 St & Broadway 40.808200 -73.964100 3541 Amsterdam Ave & W 125 St 40.813358 -73.956461 29887 Customer 1969 0 2019-10-06 08:15:11.612 2019-10-04 12:53:05.889 6 08
314753 68430 2019-10-05 13:15:25.5260 2019-10-06 08:15:55.6190 3112 Milton St & Franklin St 40.729060 -73.957790 2002 Wythe Ave & Metropolitan Ave 40.716887 -73.963198 18420 Customer 1943 1 2019-10-06 08:15:55.619 2019-10-05 13:15:25.526 6 08
323706 67139 2019-10-05 14:43:50.8920 2019-10-06 09:22:50.5750 3002 South End Ave & Liberty St 40.711512 -74.015756 3173 Riverside Blvd & W 67 St 40.777507 -73.988886 30719 Customer 1969 0 2019-10-06 09:22:50.575 2019-10-05 14:43:50.892 6 09
325904 65906 2019-10-05 15:05:02.0220 2019-10-06 09:23:28.5380 358 Christopher St & Greenwich St 40.732916 -74.007114 3173 Riverside Blvd & W 67 St 40.777507 -73.988886 17053 Customer 1995 2 2019-10-06 09:23:28.538 2019-10-05 15:05:02.022 6 09
346488 48957 2019-10-05 18:43:32.8510 2019-10-06 08:19:30.5560 3407 Union St & Nevins St 40.679098 -73.987655 3407 Union St & Nevins St 40.679098 -73.987655 41518 Subscriber 1970 1 2019-10-06 08:19:30.556 2019-10-05 18:43:32.851 6 08
In [35]:
df2['endcoordinates'] = list(zip(df2['end station longitude'],df2['end station latitude']))
In [36]:
df2['endcoordinates'] = df2['endcoordinates'].apply(Point)
gdf_Smorning = geopandas.GeoDataFrame(df2, geometry='endcoordinates')
gdf_Smorning.head()
Out[36]:
tripduration starttime stoptime start station id start station name start station latitude start station longitude end station id end station name end station latitude end station longitude bikeid usertype birth year gender stoptime_dt starttime_dt weekday hh endcoordinates
239013 156125 2019-10-04 12:53:05.8890 2019-10-06 08:15:11.6120 3536 W 116 St & Broadway 40.808200 -73.964100 3541 Amsterdam Ave & W 125 St 40.813358 -73.956461 29887 Customer 1969 0 2019-10-06 08:15:11.612 2019-10-04 12:53:05.889 6 08 POINT (-73.95646 40.81336)
314753 68430 2019-10-05 13:15:25.5260 2019-10-06 08:15:55.6190 3112 Milton St & Franklin St 40.729060 -73.957790 2002 Wythe Ave & Metropolitan Ave 40.716887 -73.963198 18420 Customer 1943 1 2019-10-06 08:15:55.619 2019-10-05 13:15:25.526 6 08 POINT (-73.96320 40.71689)
323706 67139 2019-10-05 14:43:50.8920 2019-10-06 09:22:50.5750 3002 South End Ave & Liberty St 40.711512 -74.015756 3173 Riverside Blvd & W 67 St 40.777507 -73.988886 30719 Customer 1969 0 2019-10-06 09:22:50.575 2019-10-05 14:43:50.892 6 09 POINT (-73.98889 40.77751)
325904 65906 2019-10-05 15:05:02.0220 2019-10-06 09:23:28.5380 358 Christopher St & Greenwich St 40.732916 -74.007114 3173 Riverside Blvd & W 67 St 40.777507 -73.988886 17053 Customer 1995 2 2019-10-06 09:23:28.538 2019-10-05 15:05:02.022 6 09 POINT (-73.98889 40.77751)
346488 48957 2019-10-05 18:43:32.8510 2019-10-06 08:19:30.5560 3407 Union St & Nevins St 40.679098 -73.987655 3407 Union St & Nevins St 40.679098 -73.987655 41518 Subscriber 1970 1 2019-10-06 08:19:30.556 2019-10-05 18:43:32.851 6 08 POINT (-73.98765 40.67910)
In [37]:
gdf_Sunday_Morning = gdf_Smorning[[
    'end station id',
    'end station name',
    'stoptime_dt',
    'starttime_dt',
    'weekday',
    'hh',
    'endcoordinates',
    'usertype',
    'birth year']]
In [38]:
gdf_Sunday_Morning.to_csv('gdf_Sunday_Morning.csv')
In [39]:
arriving1 = gdf_Smorning.groupby(['end station latitude','end station longitude','end station name']).size()
arriving1.head(10)
Out[39]:
end station latitude  end station longitude  end station name                             
40.655400             -74.010628             39 St & 2 Ave - Citi Bike HQ at Industry City     1
40.657089             -74.008702             2 Ave & 36 St - Citi Bike HQ at Industry City     3
40.661063             -73.979453             West Drive & Prospect Park West                  11
40.662706             -73.956912             Sterling St & Bedford Ave                         1
40.663062             -73.953875             Rogers Ave & Sterling St                          1
40.663140             -73.960569             Franklin Ave & Empire Blvd                        4
40.663779             -73.983968             14 St & 7 Ave                                     5
40.664241             -73.957469             Sullivan Pl & Bedford Ave                         3
40.665147             -73.976376             Prospect Park West & 8 St                        12
40.665816             -73.956934             Bedford Ave & Montgomery St                       2
dtype: int64
In [40]:
# arriving: end station
# Which stations are the busiest stations in 8:00 - 10:00 am on Sunday? 
arriving1_sort = arriving1.sort_values(ascending = False)
arriving1_sort.head(5)
Out[40]:
end station latitude  end station longitude  end station name     
40.741740             -73.994156             W 21 St & 6 Ave          113
40.751873             -73.977706             Pershing Square North    101
40.746745             -74.007756             W 20 St & 11 Ave          81
40.769155             -73.981918             Broadway & W 60 St        70
40.737050             -73.990093             E 17 St & Broadway        67
dtype: int64
In [41]:
# Top 5 busiest station at rush hour on Tuesday: 
# W 21 St & 6 Ave
# Pershing Square North
# W 20 St & 11 Ave
# Broadway & W 60 St
# E 17 St & Broadway
## But the arriving points are not in clustered pattern as on Tuesday. 
In [42]:
for i in range(10):
    print(arriving1_sort.keys()[i])
(40.74173969, -73.99415556, 'W 21 St & 6 Ave')
(40.751872999999996, -73.97770600000001, 'Pershing Square North')
(40.746745000000004, -74.007756, 'W 20 St & 11 Ave')
(40.76915505, -73.98191841, 'Broadway & W 60 St')
(40.73704984, -73.99009296, 'E 17 St & Broadway')
(40.73020660529954, -73.99102628231049, 'Lafayette St & E 8 St')
(40.71754834, -74.01322069, 'West St & Chambers St')
(40.749156, -73.9916, 'W 31 St & 7 Ave')
(40.72903917, -73.99404649, 'Washington Pl & Broadway')
(40.73971301, -73.99456405, 'W 18 St & 6 Ave')
In [43]:
len(arriving1_sort)
Out[43]:
759
In [44]:
#plot arriving points(Sunday morning) on the map
latitude1 = []
longitude1 = []
number1 = []
for i in range(len(arriving1_sort)):
    lat1 = arriving1_sort.keys()[i][0]
    long1 = arriving1_sort.keys()[i][1]
    total1 = arriving1_sort[i]
    latitude1.append(lat1)
    longitude1.append(long1)
    number1.append(total1)
m_Smorning = folium.Map(location=[40.76727216, -73.99392888], tiles='cartodbpositron',zoom_start = 12)
for j in range(0,len(latitude1)):
    labels = number1[j]
    folium.CircleMarker(
        location = [latitude1[j],longitude1[j]],
        radius = number1[j]/100, 
        color = '#2ca02c', 
        fill_color='#2ca02c',
        popup=labels).add_to(m_Smorning)
In [45]:
display(m_Smorning)
In [46]:
# save Sunday Morning
m_Smorning.save('html_map_output_Sunday_8to10.html')
In [47]:
# No cluster on Sunday morning(8-10pm)

(3) Sunday, the whole day

Let's figure out the riding pattern on Sunday. Does it have similar pattern as weekday?

In [48]:
# Sunday whole day
# df[(df['weekday']== '6')]
df3 = df[(df['weekday']== '6')]
df3.head()
Out[48]:
tripduration starttime stoptime start station id start station name start station latitude start station longitude end station id end station name end station latitude end station longitude bikeid usertype birth year gender stoptime_dt starttime_dt weekday hh
116891 370042 2019-10-02 11:14:36.9710 2019-10-06 18:01:59.0970 3057 Kosciuszko St & Tompkins Ave 40.691283 -73.945242 3067 Broadway & Whipple St 40.701666 -73.943730 21487 Customer 1969 0 2019-10-06 18:01:59.097 2019-10-02 11:14:36.971 6 18
121062 377055 2019-10-02 12:27:27.7520 2019-10-06 21:11:43.1990 280 E 10 St & 5 Ave 40.733320 -73.995101 3064 Myrtle Ave & Lewis Ave 40.696820 -73.937569 38199 Subscriber 1968 1 2019-10-06 21:11:43.199 2019-10-02 12:27:27.752 6 21
164903 319846 2019-10-02 22:33:25.8160 2019-10-06 15:24:12.5240 3048 Putnam Ave & Nostrand Ave 40.684020 -73.949770 3789 Fulton St & Irving Pl 40.681860 -73.959432 40110 Customer 1969 0 2019-10-06 15:24:12.524 2019-10-02 22:33:25.816 6 15
226430 194309 2019-10-04 09:37:43.9210 2019-10-06 15:36:13.0380 3463 E 16 St & Irving Pl 40.735367 -73.987974 518 E 39 St & 2 Ave 40.747804 -73.973442 17911 Customer 1969 0 2019-10-06 15:36:13.038 2019-10-04 09:37:43.921 6 15
239013 156125 2019-10-04 12:53:05.8890 2019-10-06 08:15:11.6120 3536 W 116 St & Broadway 40.808200 -73.964100 3541 Amsterdam Ave & W 125 St 40.813358 -73.956461 29887 Customer 1969 0 2019-10-06 08:15:11.612 2019-10-04 12:53:05.889 6 08
In [49]:
df3['endcoordinates'] = list(zip(df3['end station longitude'],df3['end station latitude']))
In [50]:
df3['endcoordinates'] = df3['endcoordinates'].apply(Point)
gdf_Sun = geopandas.GeoDataFrame(df3, geometry='endcoordinates')
gdf_Sun.head()
Out[50]:
tripduration starttime stoptime start station id start station name start station latitude start station longitude end station id end station name end station latitude end station longitude bikeid usertype birth year gender stoptime_dt starttime_dt weekday hh endcoordinates
116891 370042 2019-10-02 11:14:36.9710 2019-10-06 18:01:59.0970 3057 Kosciuszko St & Tompkins Ave 40.691283 -73.945242 3067 Broadway & Whipple St 40.701666 -73.943730 21487 Customer 1969 0 2019-10-06 18:01:59.097 2019-10-02 11:14:36.971 6 18 POINT (-73.94373 40.70167)
121062 377055 2019-10-02 12:27:27.7520 2019-10-06 21:11:43.1990 280 E 10 St & 5 Ave 40.733320 -73.995101 3064 Myrtle Ave & Lewis Ave 40.696820 -73.937569 38199 Subscriber 1968 1 2019-10-06 21:11:43.199 2019-10-02 12:27:27.752 6 21 POINT (-73.93757 40.69682)
164903 319846 2019-10-02 22:33:25.8160 2019-10-06 15:24:12.5240 3048 Putnam Ave & Nostrand Ave 40.684020 -73.949770 3789 Fulton St & Irving Pl 40.681860 -73.959432 40110 Customer 1969 0 2019-10-06 15:24:12.524 2019-10-02 22:33:25.816 6 15 POINT (-73.95943 40.68186)
226430 194309 2019-10-04 09:37:43.9210 2019-10-06 15:36:13.0380 3463 E 16 St & Irving Pl 40.735367 -73.987974 518 E 39 St & 2 Ave 40.747804 -73.973442 17911 Customer 1969 0 2019-10-06 15:36:13.038 2019-10-04 09:37:43.921 6 15 POINT (-73.97344 40.74780)
239013 156125 2019-10-04 12:53:05.8890 2019-10-06 08:15:11.6120 3536 W 116 St & Broadway 40.808200 -73.964100 3541 Amsterdam Ave & W 125 St 40.813358 -73.956461 29887 Customer 1969 0 2019-10-06 08:15:11.612 2019-10-04 12:53:05.889 6 08 POINT (-73.95646 40.81336)
In [51]:
gdf_Sunday_whole = gdf_Sun[[
    'end station id',
    'end station name',
    'stoptime_dt',
    'starttime_dt',
    'weekday',
    'hh',
    'endcoordinates',
    'usertype',
    'birth year']]
In [52]:
gdf_Sunday_whole.to_csv('gdf_Sunday_wholeday.csv')
In [53]:
arriving2 = gdf_Sun.groupby(['end station latitude','end station longitude','end station name']).size()
arriving2.head(10)
Out[53]:
end station latitude  end station longitude  end station name                             
40.655400             -74.010628             39 St & 2 Ave - Citi Bike HQ at Industry City     30
40.657089             -74.008702             2 Ave & 36 St - Citi Bike HQ at Industry City     39
40.661063             -73.979453             West Drive & Prospect Park West                  270
40.662706             -73.956912             Sterling St & Bedford Ave                         42
40.663062             -73.953875             Rogers Ave & Sterling St                          66
40.663140             -73.960569             Franklin Ave & Empire Blvd                       206
40.663779             -73.983968             14 St & 7 Ave                                    139
40.664241             -73.957469             Sullivan Pl & Bedford Ave                         28
40.665147             -73.976376             Prospect Park West & 8 St                        176
40.665816             -73.956934             Bedford Ave & Montgomery St                       26
dtype: int64
In [54]:
#arriving: end station; Which stations are the busiest stations in rush hours on weekdays? 
arriving2_sort = arriving2.sort_values(ascending = False)
arriving2_sort.head(5)
Out[54]:
end station latitude  end station longitude  end station name      
40.741740             -73.994156             W 21 St & 6 Ave           1155
40.769155             -73.981918             Broadway & W 60 St         989
40.734546             -73.990741             Broadway & E 14 St         944
40.765909             -73.976342             Central Park S & 6 Ave     929
40.737050             -73.990093             E 17 St & Broadway         902
dtype: int64
In [55]:
# Top 5 busiest station at on Sunday: 
# W 21 St & 6 Ave
# Broadway & W 60 St 
# Broadway & E 14 St 
# Central Park S & 6 Ave
# E 17 St & Broadway
In [56]:
for i in range(10):
    print(arriving2_sort.keys()[i])
(40.74173969, -73.99415556, 'W 21 St & 6 Ave')
(40.76915505, -73.98191841, 'Broadway & W 60 St')
(40.73454567, -73.99074142, 'Broadway & E 14 St')
(40.76590936, -73.97634151, 'Central Park S & 6 Ave')
(40.73704984, -73.99009296, 'E 17 St & Broadway')
(40.71754834, -74.01322069, 'West St & Chambers St')
(40.72966729392978, -73.98067966103555, 'E 13 St & Avenue A')
(40.73020660529954, -73.99102628231049, 'Lafayette St & E 8 St')
(40.718821999999996, -73.99596, 'Grand St & Elizabeth St')
(40.73291553, -74.00711384, 'Christopher St & Greenwich St')
In [57]:
len(arriving2_sort)
Out[57]:
823
In [58]:
# plot Sunday (the whole day) arriving points on map
latitude2 = []
longitude2 = []
number2 = []
for i in range(len(arriving2_sort)):
    lat2 = arriving2_sort.keys()[i][0]
    long2 = arriving2_sort.keys()[i][1]
    total2 = arriving2_sort[i]
    latitude2.append(lat2)
    longitude2.append(long2)
    number2.append(total2)

m_Sun = folium.Map(location=[40.76727216, -73.99392888], 
                   tiles='cartodbpositron',
                   zoom_start = 12)
for j in range(0,len(latitude2)):
    labels = number2[j]
    folium.CircleMarker(location = [latitude2[j],longitude2[j]],
                        radius = number2[j]/150, 
                        color = '#2ca02c', 
                        fill_color='#2ca02c',
                        popup=labels).add_to(m_Sun)
In [59]:
display(m_Sun)
In [60]:
# save Sunday Morning
m_Sun.save('html_map_output_Sunday_wholeday.html')
In [61]:
busyhour = gdf_Sun.groupby('hh').size()
p1 = busyhour.plot(kind='barh', figsize=(12, 10), color='#2ca02c', width=0.6, grid = True)
p1.set_xlabel("Total Number of Riders", labelpad=20, size=14)
p1.set_ylabel("Hour_time of the day", labelpad=20,size=14)
Out[61]:
Text(0, 0.5, 'Hour_time of the day')
In [62]:
busyhour_sorting = busyhour.sort_values(ascending = False)
busyhour_sorting.head(5)
Out[62]:
hh
17    15859
16    15601
12    14962
18    14152
15    14056
dtype: int64
In [63]:
# 16:00 --18:00 Busiest time slots
In [64]:
riders_Sunday = gdf_Sun.groupby(['birth year']).size()
riders_Sunday.head(10)
Out[64]:
birth year
1885     8
1886     3
1887     4
1888    10
1889    12
1890    10
1893     2
1896     1
1899     1
1900    16
dtype: int64
In [65]:
riders_Sunday_sort = riders_Sunday.sort_values(ascending = False)
riders_Sunday_sort.head(10).plot(
    kind='barh', 
    figsize=(6, 5), 
    color='#2ca02c', 
    width=0.6, 
    grid = True)
Out[65]:
<matplotlib.axes._subplots.AxesSubplot at 0x23a70cf6dd8>
In [66]:
# # Who rides during the day on Sunday?
# 1969; 1990; 1992 
# year-old: 50; 29; 27
In [67]:
trip_S = gdf_Sun.groupby(['tripduration']).size()
trip_S.head(10)
Out[67]:
tripduration
61    21
62    23
63    38
64    29
65    28
66    38
67    27
68    36
69    31
70    35
dtype: int64
In [68]:
trip_S_sort = trip_S.sort_values(ascending = False)
trip_S_sort.head(5).plot(
    kind='barh', 
    figsize=(6, 5), 
    color='#2ca02c', 
    width=0.6, 
    grid = True)
Out[68]:
<matplotlib.axes._subplots.AxesSubplot at 0x23a70d6bc88>