In [1]:
import matplotlib.pyplot as plt
import pandas as pd
%matplotlib inline

Question 1

Plot the daily temperature over the course of the year. (This should probably be a line chart.) Create a bar chart that shows the average temperature and humidity by month.


In [2]:
weather = pd.read_table('daily_weather.tsv')

In [3]:
weather.head()


Out[3]:
date weekday season_code season_desc is_holiday is_work_day weather_code weather_desc temp subjective_temp humidity windspeed no_casual_riders no_reg_riders total_riders
0 2012-01-01 0 1 Spring 0 0 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.370000 0.375621 0.692500 0.192167 686 1608 2294
1 2012-01-02 1 1 Spring 1 0 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.273043 0.252304 0.381304 0.329665 244 1707 1951
2 2012-01-03 2 1 Spring 0 1 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.150000 0.126275 0.441250 0.365671 89 2147 2236
3 2012-01-04 3 1 Spring 0 1 2 Mist + Cloudy, Mist + Broken clouds, Mist + Fe... 0.107500 0.119337 0.414583 0.184700 95 2273 2368
4 2012-01-05 4 1 Spring 0 1 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.265833 0.278412 0.524167 0.129987 140 3132 3272

In [4]:
weather.temp.plot()


Out[4]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f37f2b74cd0>

Question 1.1 complete!

This is the line chart plotting each day's temperature.


In [5]:
weather['date'] = pd.to_datetime(weather['date'])

In [6]:
weather.head()


Out[6]:
date weekday season_code season_desc is_holiday is_work_day weather_code weather_desc temp subjective_temp humidity windspeed no_casual_riders no_reg_riders total_riders
0 2012-01-01 0 1 Spring 0 0 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.370000 0.375621 0.692500 0.192167 686 1608 2294
1 2012-01-02 1 1 Spring 1 0 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.273043 0.252304 0.381304 0.329665 244 1707 1951
2 2012-01-03 2 1 Spring 0 1 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.150000 0.126275 0.441250 0.365671 89 2147 2236
3 2012-01-04 3 1 Spring 0 1 2 Mist + Cloudy, Mist + Broken clouds, Mist + Fe... 0.107500 0.119337 0.414583 0.184700 95 2273 2368
4 2012-01-05 4 1 Spring 0 1 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.265833 0.278412 0.524167 0.129987 140 3132 3272

In [7]:
type(weather.date[0])


Out[7]:
pandas.tslib.Timestamp

In [8]:
weather[['temp', 'humidity']].groupby(weather.date.dt.month).mean()


Out[8]:
temp humidity
1 0.275181 0.587290
2 0.315337 0.574582
3 0.449411 0.607536
4 0.468809 0.507839
5 0.612366 0.664556
6 0.675111 0.558361
7 0.752366 0.606089
8 0.711801 0.648629
9 0.620083 0.645375
10 0.500049 0.680727
11 0.336101 0.574443
12 0.322880 0.682898

In [9]:
weather[['temp', 'humidity']].groupby(weather.date.dt.month).mean().plot(kind='bar')


Out[9]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f37f2813850>

Question 1.2 complete!

Bar chart showing temperature and humidity by month

Question 2

Use a scatterplot to show how the daily rental volume varies with temperature. Use a different series (with different colors) for each season.


In [10]:
weather.head()


Out[10]:
date weekday season_code season_desc is_holiday is_work_day weather_code weather_desc temp subjective_temp humidity windspeed no_casual_riders no_reg_riders total_riders
0 2012-01-01 0 1 Spring 0 0 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.370000 0.375621 0.692500 0.192167 686 1608 2294
1 2012-01-02 1 1 Spring 1 0 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.273043 0.252304 0.381304 0.329665 244 1707 1951
2 2012-01-03 2 1 Spring 0 1 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.150000 0.126275 0.441250 0.365671 89 2147 2236
3 2012-01-04 3 1 Spring 0 1 2 Mist + Cloudy, Mist + Broken clouds, Mist + Fe... 0.107500 0.119337 0.414583 0.184700 95 2273 2368
4 2012-01-05 4 1 Spring 0 1 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.265833 0.278412 0.524167 0.129987 140 3132 3272

In [11]:
newseasons = {'Summer': 'Spring', 'Spring': 'Winter', 'Fall': 'Summer', 'Winter': 'Fall'}
weather['season_desc'] = weather['season_desc'].map(newseasons)

In [12]:
winter_slice = weather[weather.season_desc == 'Winter'][['temp', 'total_riders']]

In [13]:
weather[weather.season_desc == 'Winter'][['temp', 'total_riders']].plot()


Out[13]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f37f269c7d0>

In [14]:
weather[weather.season_desc == 'Spring'][['temp', 'total_riders']].plot()


Out[14]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f37f257c9d0>

In [15]:
spring_slice = weather[weather.season_desc == 'Spring'][['temp', 'total_riders']]
summer_slice = weather[weather.season_desc == 'Summer'][['temp', 'total_riders']]
fall_slice = weather[weather.season_desc == 'Fall'][['temp', 'total_riders']]

In [16]:
ax = winter_slice.plot(kind='scatter', x='total_riders', y='temp', color='b', alpha=0.25)
ax = spring_slice.plot(kind='scatter', x='total_riders', y='temp', color='g', alpha=0.25, ax=ax)
ax = summer_slice.plot(kind='scatter', x='total_riders', y='temp', color='r', alpha=0.25, ax=ax)
ax = fall_slice.plot(kind='scatter', x='total_riders', y='temp', color='y', alpha=0.25, ax=ax)
plt.show()


Question 2 Complete!

Here's the plot of all four seasons.

Question 3

Create another scatterplot to show how daily rental volume varies with windspeed. As above, use a different series for each season.


In [17]:
winter_slice = weather[weather.season_desc == 'Winter'][['windspeed', 'total_riders']]
spring_slice = weather[weather.season_desc == 'Spring'][['windspeed', 'total_riders']]
summer_slice = weather[weather.season_desc == 'Summer'][['windspeed', 'total_riders']]
fall_slice = weather[weather.season_desc == 'Fall'][['windspeed', 'total_riders']]

In [18]:
ax = winter_slice.plot(kind='scatter', x='total_riders', y='windspeed', color='b', alpha=0.25)
ax = spring_slice.plot(kind='scatter', x='total_riders', y='windspeed', color='g', alpha=0.25, ax=ax)
ax = summer_slice.plot(kind='scatter', x='total_riders', y='windspeed', color='r', alpha=0.25, ax=ax)
ax = fall_slice.plot(kind='scatter', x='total_riders', y='windspeed', color='y', alpha=0.25, ax=ax)
plt.show()


Question 3 Complete!

Similar graph to Question 2, just with windspeed.

Question 4

How do the rental volumes vary with geography? Compute the average daily rentals for each station and use this as the radius for a scatterplot of each station's latitude and longitude.


In [19]:
stations = pd.read_table('stations.tsv')

In [20]:
stations.head()


Out[20]:
id station terminal_name lat long no_bikes no_empty_docks fast_food parking restaurant ... museum sculpture hostel picnic_site tour_guide attraction landmark motel guest_house gallery
0 1 20th & Bell St 31000 38.856100 -77.051200 7 4 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
1 2 18th & Eads St. 31001 38.857250 -77.053320 6 4 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
2 3 20th & Crystal Dr 31002 38.856400 -77.049200 9 6 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
3 4 15th & Crystal Dr 31003 38.860170 -77.049593 4 6 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
4 5 Aurora Hills Community Ctr/18th & Hayes St 31004 38.857866 -77.059490 5 5 0 0 0 ... 0 0 0 0 0 0 0 0 0 0

5 rows × 136 columns


In [21]:
usage = pd.read_table('usage_2012.tsv')

In [22]:
usage.head()


Out[22]:
bike_id time_start time_end duration_mins station_start station_end cust_type
0 W01412 2012-01-01 00:04:00 2012-01-01 00:11:00 7 7th & R St NW / Shaw Library 7th & T St NW Registered
1 W00524 2012-01-01 00:10:00 2012-01-01 00:29:00 19 Georgia & New Hampshire Ave NW 16th & Harvard St NW Casual
2 W00235 2012-01-01 00:10:00 2012-01-01 00:29:00 19 Georgia & New Hampshire Ave NW 16th & Harvard St NW Registered
3 W00864 2012-01-01 00:15:00 2012-01-01 00:23:00 8 14th & V St NW Park Rd & Holmead Pl NW Registered
4 W00995 2012-01-01 00:15:00 2012-01-01 00:23:00 8 11th & Kenyon St NW 7th & T St NW Registered

In [23]:
usage_station = pd.merge(usage, stations, left_on='station_start', right_on='station', how='outer')

In [24]:
usage_station.head()


Out[24]:
bike_id time_start time_end duration_mins station_start station_end cust_type id station terminal_name ... museum sculpture hostel picnic_site tour_guide attraction landmark motel guest_house gallery
0 W01412 2012-01-01 00:04:00 2012-01-01 00:11:00 7 7th & R St NW / Shaw Library 7th & T St NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 0
1 W01412 2012-01-01 00:04:00 2012-01-01 00:11:00 7 7th & R St NW / Shaw Library 7th & T St NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 0
2 W00381 2012-01-01 01:55:00 2012-01-01 02:07:00 12 7th & R St NW / Shaw Library 14th & V St NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 0
3 W00381 2012-01-01 01:55:00 2012-01-01 02:07:00 12 7th & R St NW / Shaw Library 14th & V St NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 0
4 W00453 2012-01-01 12:40:00 2012-01-01 12:50:00 10 7th & R St NW / Shaw Library 17th & Corcoran St NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 0

5 rows × 143 columns


In [25]:
usage_station.tail()


Out[25]:
bike_id time_start time_end duration_mins station_start station_end cust_type id station terminal_name ... museum sculpture hostel picnic_site tour_guide attraction landmark motel guest_house gallery
2412681 NaN NaN NaN NaN NaN NaN NaN 352 S Joyce & 16th St S 31091 ... 0 0 0 4 0 0 0 0 0 0
2412682 NaN NaN NaN NaN NaN NaN NaN 353 Union Market/6th St & Neal Pl NE 31517 ... 0 0 0 0 0 0 0 0 0 0
2412683 NaN NaN NaN NaN NaN NaN NaN 354 N Nelson St & Lee Hwy 31092 ... 0 0 0 0 0 0 0 0 0 0
2412684 NaN NaN NaN NaN NaN NaN NaN 355 21st St N & N Pierce St 31093 ... 0 0 0 0 0 0 0 0 0 0
2412685 NaN NaN NaN NaN NaN NaN NaN 356 Lee Hwy & N Kirkwood Rd 31094 ... 0 0 0 0 0 0 0 0 0 0

5 rows × 143 columns


In [26]:
usage_station


Out[26]:
bike_id time_start time_end duration_mins station_start station_end cust_type id station terminal_name ... museum sculpture hostel picnic_site tour_guide attraction landmark motel guest_house gallery
0 W01412 2012-01-01 00:04:00 2012-01-01 00:11:00 7 7th & R St NW / Shaw Library 7th & T St NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 0
1 W01412 2012-01-01 00:04:00 2012-01-01 00:11:00 7 7th & R St NW / Shaw Library 7th & T St NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 0
2 W00381 2012-01-01 01:55:00 2012-01-01 02:07:00 12 7th & R St NW / Shaw Library 14th & V St NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 0
3 W00381 2012-01-01 01:55:00 2012-01-01 02:07:00 12 7th & R St NW / Shaw Library 14th & V St NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 0
4 W00453 2012-01-01 12:40:00 2012-01-01 12:50:00 10 7th & R St NW / Shaw Library 17th & Corcoran St NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 0
5 W00237 2012-01-01 12:47:00 2012-01-01 12:57:00 10 7th & R St NW / Shaw Library 15th & P St NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 0
6 W00734 2012-01-01 12:47:00 2012-01-01 12:57:00 10 7th & R St NW / Shaw Library 15th & P St NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 0
7 W00453 2012-01-01 12:40:00 2012-01-01 12:50:00 10 7th & R St NW / Shaw Library 17th & Corcoran St NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 0
8 W00237 2012-01-01 12:47:00 2012-01-01 12:57:00 10 7th & R St NW / Shaw Library 15th & P St NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 0
9 W00734 2012-01-01 12:47:00 2012-01-01 12:57:00 10 7th & R St NW / Shaw Library 15th & P St NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 0
10 W00715 2012-01-01 12:26:00 2012-01-01 12:30:00 4 7th & R St NW / Shaw Library 14th & Rhode Island Ave NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 0
11 W00715 2012-01-01 12:26:00 2012-01-01 12:30:00 4 7th & R St NW / Shaw Library 14th & Rhode Island Ave NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 0
12 W00393 2012-01-01 13:31:00 2012-01-01 13:40:00 9 7th & R St NW / Shaw Library Metro Center / 12th & G St NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 0
13 W00393 2012-01-01 13:31:00 2012-01-01 13:40:00 9 7th & R St NW / Shaw Library Metro Center / 12th & G St NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 0
14 W00581 2012-01-01 14:29:00 2012-01-01 15:06:00 37 7th & R St NW / Shaw Library 5th & F St NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 0
15 W00581 2012-01-01 14:29:00 2012-01-01 15:06:00 37 7th & R St NW / Shaw Library 5th & F St NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 0
16 W00928 2012-01-01 15:30:00 2012-01-01 15:47:00 17 7th & R St NW / Shaw Library Adams Mill & Columbia Rd NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 0
17 W01461 2012-01-01 15:30:00 2012-01-01 15:47:00 17 7th & R St NW / Shaw Library Adams Mill & Columbia Rd NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 0
18 W00641 2012-01-01 15:10:00 2012-01-01 15:17:00 7 7th & R St NW / Shaw Library 8th & H St NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 0
19 W00641 2012-01-01 15:10:00 2012-01-01 15:17:00 7 7th & R St NW / Shaw Library 8th & H St NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 0
20 W00928 2012-01-01 15:30:00 2012-01-01 15:47:00 17 7th & R St NW / Shaw Library Adams Mill & Columbia Rd NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 0
21 W01461 2012-01-01 15:30:00 2012-01-01 15:47:00 17 7th & R St NW / Shaw Library Adams Mill & Columbia Rd NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 0
22 W00208 2012-01-01 02:33:00 2012-01-01 02:42:00 9 7th & R St NW / Shaw Library 5th & F St NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 0
23 W00208 2012-01-01 02:33:00 2012-01-01 02:42:00 9 7th & R St NW / Shaw Library 5th & F St NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 0
24 W00033 2012-01-01 02:55:00 2012-01-01 03:07:00 12 7th & R St NW / Shaw Library Georgia & New Hampshire Ave NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 0
25 W00033 2012-01-01 02:55:00 2012-01-01 03:07:00 12 7th & R St NW / Shaw Library Georgia & New Hampshire Ave NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 0
26 W00114 2012-01-01 22:03:00 2012-01-01 22:11:00 8 7th & R St NW / Shaw Library 17th & Corcoran St NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 0
27 W00114 2012-01-01 22:03:00 2012-01-01 22:11:00 8 7th & R St NW / Shaw Library 17th & Corcoran St NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 0
28 W00641 2012-01-01 09:39:00 2012-01-01 09:50:00 11 7th & R St NW / Shaw Library Massachusetts Ave & Dupont Circle NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 0
29 W00641 2012-01-01 09:39:00 2012-01-01 09:50:00 11 7th & R St NW / Shaw Library Massachusetts Ave & Dupont Circle NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 0
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
2412656 NaN NaN NaN NaN NaN NaN NaN 326 River Rd & Landy Ln 32046 ... 0 0 0 0 0 0 0 0 0 0
2412657 NaN NaN NaN NaN NaN NaN NaN 327 Rockville Metro West 32047 ... 0 0 0 0 0 0 0 0 0 0
2412658 NaN NaN NaN NaN NaN NaN NaN 328 Bethesda Metro 32048 ... 0 0 0 0 0 0 0 0 0 0
2412659 NaN NaN NaN NaN NaN NaN NaN 329 Iwo Jima Memorial/N Meade & 14th St N 31077 ... 0 0 0 0 0 0 0 0 0 0
2412660 NaN NaN NaN NaN NaN NaN NaN 330 34th & Water St NW 31314 ... 0 0 0 0 0 1 0 0 0 1
2412661 NaN NaN NaN NaN NaN NaN NaN 331 Duke St & John Carlyle St 31081 ... 0 0 0 0 0 0 1 0 0 0
2412662 NaN NaN NaN NaN NaN NaN NaN 332 Lee Hwy & N Cleveland St 31079 ... 0 0 0 0 0 0 0 0 0 0
2412663 NaN NaN NaN NaN NaN NaN NaN 333 Arlington Blvd & S George Mason Dr/NFATC 31078 ... 0 0 0 0 0 0 0 0 0 0
2412664 NaN NaN NaN NaN NaN NaN NaN 334 MLK Library/9th & G St NW 31274 ... 4 0 0 0 0 0 0 0 0 0
2412665 NaN NaN NaN NaN NaN NaN NaN 335 Lee Hwy & N Scott St 31080 ... 0 0 0 0 0 0 0 0 0 0
2412666 NaN NaN NaN NaN NaN NaN NaN 336 New Hampshire Ave & 24th St NW 31275 ... 0 0 0 0 0 0 0 0 0 0
2412667 NaN NaN NaN NaN NaN NaN NaN 337 Eisenhower Ave & Mill Race Ln 31082 ... 0 0 0 0 0 0 0 0 0 0
2412668 NaN NaN NaN NaN NaN NaN NaN 338 Potomac Greens Dr & Slaters Ln 31083 ... 0 0 0 0 0 0 0 0 0 0
2412669 NaN NaN NaN NaN NaN NaN NaN 339 Ballenger Ave & Dulaney St 31084 ... 0 0 0 0 0 1 0 0 0 0
2412670 NaN NaN NaN NaN NaN NaN NaN 340 Mount Vernon Ave & E Nelson Ave 31085 ... 0 0 0 0 0 0 0 0 0 0
2412671 NaN NaN NaN NaN NaN NaN NaN 341 Mount Vernon Ave & E Del Ray Ave 31086 ... 0 0 0 0 0 0 0 0 0 0
2412672 NaN NaN NaN NaN NaN NaN NaN 342 Monroe Ave & Leslie Ave 31087 ... 0 0 0 0 0 0 0 0 0 0
2412673 NaN NaN NaN NaN NaN NaN NaN 343 Mount Vernon Ave & Kennedy St 31088 ... 0 0 0 0 0 0 0 0 0 0
2412674 NaN NaN NaN NaN NaN NaN NaN 345 Washington Adventist U / Flower Ave & Division St 32049 ... 0 0 0 0 0 0 0 0 0 0
2412675 NaN NaN NaN NaN NaN NaN NaN 346 6th & S Ball St 31090 ... 0 0 0 0 0 0 0 0 0 0
2412676 NaN NaN NaN NaN NaN NaN NaN 347 McKinley St & Connecticut Ave NW 31315 ... 0 0 0 0 0 0 0 0 0 0
2412677 NaN NaN NaN NaN NaN NaN NaN 348 15th & L St NW 31276 ... 0 0 0 0 0 0 0 0 0 0
2412678 NaN NaN NaN NaN NaN NaN NaN 349 17th & G St NW 31277 ... 0 0 0 0 0 0 0 0 0 0
2412679 NaN NaN NaN NaN NaN NaN NaN 350 Spring St & Second Ave 32050 ... 0 0 0 0 0 0 0 0 0 0
2412680 NaN NaN NaN NaN NaN NaN NaN 351 18th & R St NW 31278 ... 1 0 0 0 0 0 0 0 0 0
2412681 NaN NaN NaN NaN NaN NaN NaN 352 S Joyce & 16th St S 31091 ... 0 0 0 4 0 0 0 0 0 0
2412682 NaN NaN NaN NaN NaN NaN NaN 353 Union Market/6th St & Neal Pl NE 31517 ... 0 0 0 0 0 0 0 0 0 0
2412683 NaN NaN NaN NaN NaN NaN NaN 354 N Nelson St & Lee Hwy 31092 ... 0 0 0 0 0 0 0 0 0 0
2412684 NaN NaN NaN NaN NaN NaN NaN 355 21st St N & N Pierce St 31093 ... 0 0 0 0 0 0 0 0 0 0
2412685 NaN NaN NaN NaN NaN NaN NaN 356 Lee Hwy & N Kirkwood Rd 31094 ... 0 0 0 0 0 0 0 0 0 0

2412686 rows × 143 columns


In [27]:
stations[stations.station == 'River Rd & Landy Ln']


Out[27]:
id station terminal_name lat long no_bikes no_empty_docks fast_food parking restaurant ... museum sculpture hostel picnic_site tour_guide attraction landmark motel guest_house gallery
316 326 River Rd & Landy Ln 32046 38.964992 -77.103381 13 6 1 0 0 ... 0 0 0 0 0 0 0 0 0 0

1 rows × 136 columns


In [28]:
usage[usage.station_end == 'River Rd & Landy Ln']


Out[28]:
bike_id time_start time_end duration_mins station_start station_end cust_type

In [29]:
usage_station['time_start'] = pd.to_datetime(usage_station['time_start'])

In [30]:
usage_station['time_end'] = pd.to_datetime(usage_station['time_end'])

In [31]:
type(usage_station.time_end[0])


Out[31]:
pandas.tslib.Timestamp

In [32]:
usage_station[['station']].groupby(usage_station.time_start.dt.dayofyear).size()


Out[32]:
1      4588
2      3900
3      4466
4      4734
5      6538
6      8182
7      9040
8      6848
9      4740
10     7184
11     4348
12     8182
13     6414
14     4982
15     4612
16     4590
17     5862
18     6740
19     6570
20     6312
21     2600
22     3950
23     4858
24     8654
25     8518
26     8120
27     6898
28     8038
29     6480
30     7230
       ... 
337    4649
338    6234
339    6606
340    5729
341    5375
342    5008
343    5582
344    3228
345    5170
346    5501
347    5319
348    5532
349    5611
350    5047
351    3786
352    4585
353    5557
354    5267
355    4128
356    3623
357    1749
358    1787
359     920
360    1013
361     441
362    2114
363    3095
364    1341
365    1796
366    2729
dtype: int64

In [33]:
rentals_per_station = usage_station[['station', 'lat', 'long']].groupby('station').size()

In [34]:
usage_station['total_rentals'] = usage_station.groupby('station').size()

In [35]:
usage_station.head()


Out[35]:
bike_id time_start time_end duration_mins station_start station_end cust_type id station terminal_name ... sculpture hostel picnic_site tour_guide attraction landmark motel guest_house gallery total_rentals
0 W01412 2012-01-01 00:04:00 2012-01-01 00:11:00 7 7th & R St NW / Shaw Library 7th & T St NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 NaN
1 W01412 2012-01-01 00:04:00 2012-01-01 00:11:00 7 7th & R St NW / Shaw Library 7th & T St NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 NaN
2 W00381 2012-01-01 01:55:00 2012-01-01 02:07:00 12 7th & R St NW / Shaw Library 14th & V St NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 NaN
3 W00381 2012-01-01 01:55:00 2012-01-01 02:07:00 12 7th & R St NW / Shaw Library 14th & V St NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 NaN
4 W00453 2012-01-01 12:40:00 2012-01-01 12:50:00 10 7th & R St NW / Shaw Library 17th & Corcoran St NW Registered 145 7th & R St NW / Shaw Library 31245 ... 0 0 0 0 0 0 0 0 0 NaN

5 rows × 144 columns


In [36]:
rentals_per_station


Out[36]:
station
10th & E St NW                                                6328
10th & Florida Ave NW                                            1
10th & Monroe St NE                                           3813
10th & U St NW                                               26075
10th St & Constitution Ave NW                                20413
11th & F St NW                                                   1
11th & H St NE                                               12878
11th & K St NW                                                   1
11th & Kenyon St NW                                          22625
11th & M St NW                                                   1
12th & Army Navy Dr                                           3727
12th & Irving St NE                                              1
12th & L St NW                                                8512
12th & Newton St NE                                           1301
12th & U St NW                                                   1
13th & D St NE                                               19039
13th & H St NE                                               15652
13th St & Eastern Ave                                            1
13th St & New York Ave NW                                    19704
14th & Belmont St NW                                             1
14th & D St NW / Ronald Reagan Building                      19031
14th & D St SE                                               12146
14th & G St NW                                               19734
14th & Harvard St NW                                         26006
14th & R St NW                                               24942
14th & Rhode Island Ave NW                                   31762
14th & Upshur St NW                                              1
14th & V St NW                                               40242
14th St & Colorado Ave NW                                        1
14th St & New York Ave NW                                        1
                                                             ...  
Shady Grove Metro West                                           1
Shirlington Transit Center / S Quincy & Randolph St              1
Silver Spring Metro/Colesville Rd & Wayne Ave                    1
Smithsonian / Jefferson Dr & 12th St SW                      17447
Spring St & Second Ave                                           1
TJ Cmty Ctr / 2nd St & S Old Glebe Rd                            1
Taft St & E Gude Dr                                              1
Takoma Metro                                                     1
Tenleytown / Wisconsin Ave & Albemarle St NW                 10241
Thomas Circle                                                40101
Traville Gateway Dr & Gudelsky Dr                                1
US Dept of State / Virginia Ave & 21st St NW                 17974
USDA / 12th & Independence Ave SW                            20853
Union Market/6th St & Neal Pl NE                                 1
Utah St & 11th St N                                            744
Van Ness Metro / UDC                                          8973
Veterans Pl & Pershing Dr                                        1
Virginia Square Metro / N Monroe St & 9th St N                4714
Walter Reed Community Center / Walter Reed Dr & 16th St S        1
Ward Circle / American University                             6285
Washington & Independence Ave SW/HHS                             1
Washington Adventist U / Flower Ave & Division St                1
Washington Blvd & 10th St N                                   1122
Washington Blvd & 7th St N                                     799
Washington Blvd & Walter Reed Dr                                 1
Wilson Blvd & Franklin Rd                                     3684
Wilson Blvd & N Edgewood St                                   2884
Wilson Blvd & N Oakland St                                    1887
Wilson Blvd & N Uhle St                                          1
Wisconsin Ave & O St NW                                          1
dtype: int64

In [37]:
rentals_per_station[0]


Out[37]:
6328

In [38]:
def get_average(x):
    return x/366

In [39]:
daily_rentals = rentals_per_station.apply(get_average)

In [40]:
type(daily_rentals)


Out[40]:
pandas.core.series.Series

In [41]:
loc_slice = stations[['station', 'lat', 'long']]

In [42]:
type(loc_slice)


Out[42]:
pandas.core.frame.DataFrame

In [43]:
loc_slice


Out[43]:
station lat long
0 20th & Bell St 38.856100 -77.051200
1 18th & Eads St. 38.857250 -77.053320
2 20th & Crystal Dr 38.856400 -77.049200
3 15th & Crystal Dr 38.860170 -77.049593
4 Aurora Hills Community Ctr/18th & Hayes St 38.857866 -77.059490
5 Pentagon City Metro / 12th & S Hayes St 38.862303 -77.059936
6 S Joyce & Army Navy Dr 38.863700 -77.063300
7 Crystal City Metro / 18th & Bell St 38.857300 -77.051100
8 12th & Army Navy Dr 38.862900 -77.052800
9 27th & Crystal Dr 38.848441 -77.051516
10 S Glebe & Potomac Ave 38.842600 -77.050200
11 23rd & Crystal Dr 38.853300 -77.049800
12 26th & S Clark St 38.850688 -77.051520
13 19th St & Pennsylvania Ave NW 38.900300 -77.042900
14 14th & V St NW 38.917600 -77.032100
15 11th & Kenyon St NW 38.929464 -77.027822
16 16th & Harvard St NW 38.926088 -77.036536
17 Adams Mill & Columbia Rd NW 38.922925 -77.042581
18 14th & Harvard St NW 38.926800 -77.032200
19 Calvert & Biltmore St NW 38.923203 -77.047637
20 Lamont & Mt Pleasant NW 38.931900 -77.038800
21 4th & M St SW 38.876700 -77.017800
22 15th & P St NW 38.909850 -77.034438
23 14th & R St NW 38.912682 -77.031681
24 14th & Rhode Island Ave NW 38.908600 -77.032300
25 20th & E St NW 38.896300 -77.045000
26 21st & I St NW 38.900800 -77.047000
27 Georgia & New Hampshire Ave NW 38.936043 -77.024649
28 14th St & Spring Rd NW 38.937500 -77.032800
29 John McCormack Dr & Michigan Ave NE 38.934600 -76.995500
... ... ... ...
317 Rockville Metro West 39.084379 -77.146866
318 Bethesda Metro 38.984691 -77.094537
319 Iwo Jima Memorial/N Meade & 14th St N 38.889920 -77.071301
320 34th & Water St NW 38.903582 -77.067786
321 Duke St & John Carlyle St 38.804378 -77.060866
322 Lee Hwy & N Cleveland St 38.894941 -77.091690
323 Arlington Blvd & S George Mason Dr/NFATC 38.869442 -77.104503
324 MLK Library/9th & G St NW 38.898404 -77.024281
325 Lee Hwy & N Scott St 38.897612 -77.080851
326 New Hampshire Ave & 24th St NW 38.901755 -77.051084
327 Eisenhower Ave & Mill Race Ln 38.801111 -77.068952
328 Potomac Greens Dr & Slaters Ln 38.821750 -77.047494
329 Ballenger Ave & Dulaney St 38.802677 -77.063562
330 Mount Vernon Ave & E Nelson Ave 38.820064 -77.057619
331 Mount Vernon Ave & E Del Ray Ave 38.825950 -77.058541
332 Monroe Ave & Leslie Ave 38.820932 -77.053096
333 Mount Vernon Ave & Kennedy St 38.833077 -77.059821
334 Court House Metro / 15th & N Uhle St 38.890612 -77.084801
335 Washington Adventist U / Flower Ave & Division St 38.986743 -77.000035
336 6th & S Ball St 38.864702 -77.048672
337 McKinley St & Connecticut Ave NW 38.964970 -77.075946
338 15th & L St NW 38.903810 -77.034931
339 17th & G St NW 38.898410 -77.039624
340 Spring St & Second Ave 38.997653 -77.034499
341 18th & R St NW 38.912648 -77.041834
342 S Joyce & 16th St S 38.859254 -77.063275
343 Union Market/6th St & Neal Pl NE 38.908008 -76.996985
344 N Nelson St & Lee Hwy 38.895929 -77.105246
345 21st St N & N Pierce St 38.898984 -77.078317
346 Lee Hwy & N Kirkwood Rd 38.895377 -77.097130

347 rows × 3 columns


In [44]:
result = pd.concat([usage['station_start']], axis=0, keys=['station'])

In [45]:
counts = result['station'].value_counts()

In [49]:
from pandas import DataFrame

In [50]:
c = DataFrame(daily_rentals.index, columns=['station'])

In [51]:
c['daily_rentals'] = daily_rentals.values

In [52]:
m = pd.merge(loc_slice, c, on='station')

In [53]:
plt.scatter(m['long'], m['lat'], c='b', label='Location' ,s=(m['daily_rentals']), alpha=.1)
plt.legend(loc='lower right')
plt.xlabel('Longitude')
plt.ylabel('Latitude')
plt.show()


Question 4 complete!

We found the average by grouping the data by day, calculating the size and then applying a divide by 366 calculation to get the average. Then we merged the average along with the data from stations that include lat and long so we could plot it.


In [ ]: