Created
June 5, 2015 15:14
-
-
Save Mengyuz/e91117b1c9b6a296ff72 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import pandas | |
import matplotlib.pyplot as plt | |
def entries_histogram(turnstile_weather): | |
''' | |
Before we perform any analysis, it might be useful to take a | |
look at the data we're hoping to analyze. More specifically, let's | |
examine the hourly entries in our NYC subway data and determine what | |
distribution the data follows. This data is stored in a dataframe | |
called turnstile_weather under the ['ENTRIESn_hourly'] column. | |
Let's plot two histograms on the same axes to show hourly | |
entries when raining vs. when not raining. Here's an example on how | |
to plot histograms with pandas and matplotlib: | |
turnstile_weather['column_to_graph'].hist() | |
Your histograph may look similar to bar graph in the instructor notes below. | |
You can read a bit about using matplotlib and pandas to plot histograms here: | |
http://pandas.pydata.org/pandas-docs/stable/visualization.html#histograms | |
You can see the information contained within the turnstile weather data here: | |
https://www.dropbox.com/s/meyki2wl9xfa7yk/turnstile_data_master_with_weather.csv | |
''' | |
x = turnstile_weather["ENTRIESn_hourly"] | |
y1 = turnstile_weather["ENTRIESn_hourly"][turnstile_weather["rain"] == 1] # your code here to plot a historgram for hourly entries when it is raining | |
y2 = turnstile_weather["ENTRIESn_hourly"][turnstile_weather["rain"] == 0] # your code here to plot a historgram for hourly entries when it is not raining | |
plt.figure() | |
x.hist(bins=50) | |
y1.hist(bins=50) | |
y2.hist(bins=50) | |
return plt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adding few features ->
x = turnstile_weather['ENTRIESn_hourly']
y1 = turnstile_weather['ENTRIESn_hourly'][turnstile_weather['rain'] == 0]
y2 = turnstile_weather['ENTRIESn_hourly'][turnstile_weather['rain'] == 1]
plt.figure()
x.hist(bins=50)
y1.hist(bins=50, color='blue', label='no rain')
y2.hist(bins=50, color='green', label='rain')
plt.legend()
plt.xlim(0,6000)
return plt