Assignment 2
Assignment 2
Before working on this assignment please read these instructions fully. In the submission area, you will
notice that you can click the link to Preview the Grading for each step of the assignment. This is the criteria
that will be used for peer grading. Please familiarize yourself with the criteria before beginning the
assignment.
1. Read the documentation and familiarize yourself with the dataset, then write some python code
which returns a line graph of the record high and record low temperatures by day of the year over
the period 2005-2014. The area between the record high and record low temperatures for each day
should be shaded.
2. Overlay a scatter of the 2015 data for any points (highs and lows) for which the ten year record
(2005-2014) record high or record low was broken in 2015.
3. Watch out for leap days (i.e. February 29th), it is reasonable to remove these points from the
dataset for the purpose of this visualization.
4. Make the visual nice! Leverage principles from the first module in this course when developing your
solution. Consider issues such as legends, labels, and chart junk.
The data you have been given is near Ann Arbor, Michigan, United States, and the stations the data
comes from are shown on the map below.
In [1]:
df = pd.read_csv('data/C2A2_data/BinSize_d{}.csv'.format(binsize))
lons = station_locations_by_hash['LONGITUDE'].tolist()
lats = station_locations_by_hash['LATITUDE'].tolist()
plt.figure(figsize=(8,8))
return mplleaflet.display()
leaflet_plot_stations(400,'fb441e62df2d58994928907a91895ec62c2c42e6cd075c2700843
b89')
Out[1]:
+
-
df = pd.read_csv('data/C2A2_data/BinnedCsvs_d400/fb441e62df2d58994928907a91895ec
62c2c42e6cd075c2700843b89.csv')
df.sort_values('Date')
df['Data_Value'] = df['Data_Value'] * 0.1
df['Year'] = df['Date'].apply(lambda x: x[:4])
df['Date(M-D)'] = df['Date'].apply(lambda x: x[-5:])
df = df[df['Date(M-D)'] != '02-29']
df_2005_2014 = df[~(df['Year'] == '2015')]
df_2015 = df[df['Year'] == '2015']
df_2005_2014.head()
Out[8]:
In [18]:
import numpy as np
max_2004_2015 = df_2005_2014.groupby('Date(M-D)').agg({'Data_Value':np.max})
min_2004_2015 = df_2005_2014.groupby('Date(M-D)').agg({'Data_Value':np.min})
max_2015 = df_2015.groupby('Date(M-D)').agg({'Data_Value':np.max})
min_2015 = df_2015.groupby('Date(M-D)').agg({'Data_Value':np.min})
In [19]:
max_2004_2015.head()
Out[19]:
Data_Value
Date(M-D)
01-01 15.6
01-02 13.9
01-03 13.3
01-04 10.6
01-05 12.8
In [17]:
Out[17]:
In [25]:
%matplotlib inline
plt.figure(figsize=(16,10))
plt.xlabel('Day', fontsize=20)
plt.ylabel('Temperature', fontsize=20)
plt.title('Temperature Record During 2005-2014 Broken in 2015', fontsize=25)
<matplotlib.collections.PolyCollection at 0x7fe04195c748>
In [ ]:
In [ ]: