%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import math
# Data downloaded from: http://www.ncdc.noaa.gov/cdo-web/search
csv_file = "co_springs_1-1-2010_8-8-2013.csv"
data = open(csv_file, "r").readlines()
column_headings = data[0]
print column_headings
STATION,DATE,TMAX,TMIN,TOBS
data[1]
'GHCND:USR0000CFTC,20100128,-39,-72,-9999\n'
date_and_max_temp = [(row.split(',')[1], row.split(',')[2]) for row in data[1:]]
june_data = [(i[0], int(i[1])) for i in date_and_max_temp if i[0][4:6] == '06'] # and int(i[0][6:8]) < 7]
def fahrenheit(celsius):
return celsius * (9.0/5) + 32
june_data_in_f = [fahrenheit(i[1] * 0.10) for i in june_data]
_ = plt.hist(june_data_in_f, bins=16)
print "Average Max temperature for June in Colorado Springs:", sum(june_data_in_f) / len(june_data_in_f)
Average Max temperature for June in Colorado Springs: 82.0148837209
len([i for i in june_data_in_f if i < 75]) * 1.0 / len(june_data_in_f)
0.19856887298747763