-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.py
161 lines (129 loc) · 5.38 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
# Import San Francisco Bay Area Weather data from CSV file
data = pd.read_csv('weather.csv')
# Make variables some friendlier names for users
old_names = ['Max TemperatureF', 'Min TemperatureF', 'Mean TemperatureF', 'Max Dew PointF', 'MeanDew PointF',
'Min DewpointF', 'Max Humidity',
' Mean Humidity', ' Min Humidity', ' Max Sea Level PressureIn', ' Mean Sea Level PressureIn',
' Min Sea Level PressureIn', ' Max VisibilityMiles', ' Mean VisibilityMiles',
' Min VisibilityMiles', ' Max Wind SpeedMPH', ' Mean Wind SpeedMPH', ' Max Gust SpeedMPH', 'PrecipitationIn',
' CloudCover', ' WindDirDegrees', ' Events']
new_names = ['maxTemp', 'minTemp', 'meanTemp', 'maxDew', 'meanDew', 'minDew', 'maxHum', 'meanHum', 'minHum', 'maxPress',
'minPress', 'meanPress', 'maxVis', 'meanVis',
'minVis', 'maxWind', 'meanWind', 'maxGust', 'preIn', 'cloud', 'WindDir', 'events']
data.rename(columns=dict(zip(old_names, new_names)), inplace=True)
# Delete unused column in CSV File
del data['preIn']
# Remove the bad samples in temperature
data = data[(data['maxTemp'] <= 110) & (data['minTemp'] >= 25)]
# List unique values on example column using drop_duplicates(We can also use unique())
df2 = pd.DataFrame(data, columns=['ZIP'])
u = df2.drop_duplicates(['ZIP'])
# Get data for cities
# 94107 -> San Francisco
# 94063 -> San Mateo
# 94301 -> Santa Clara
# 94041 -> Mountain View
# 95113 -> San Jose
zipcodes = [94107, 94063, 94301, 94041, 95113]
# Day of months: start September, end August
x = [30, 61, 91, 122, 153, 182, 213, 243, 274, 304, 335, 366]
labels = ['September','October','November','December','January','February','March','April','May','June','July','August']
# Plots of Mean temperature in Fahrenheit scale
plt.figure()
for zcode in zipcodes:
local = data.loc[data['ZIP'] == zcode]
df1 = pd.DataFrame(local, columns=['meanTemp'])
plt.plot(df1.as_matrix(), '-', label=str(zcode))
plt.xticks(x,labels,rotation='vertical',fontsize=12)
plt.grid(True)
plt.xlabel('Month')
plt.ylabel('Temperature in Fahrenheit scale', fontsize=15)
plt.title('Fahrenheit Mean Temperature on Bay Area Cities',fontsize=20)
plt.legend(["San Francisco", "San Mateo","Santa Clara", "Mountain View","San Jose"])
plt.show()
# Plot compare Mean Wind and Max Gust
plt.figure()
for zcode in zipcodes:
mw = data.loc[data['ZIP'] == zcode]
df3 = pd.DataFrame(mw, columns=['meanWin', 'maxGust'])
plt.plot(df3.as_matrix(),'-', label=str(zcode))
plt.xticks(x,labels,rotation='vertical', fontsize=12)
plt.grid(True)
plt.xlabel('Month')
plt.ylabel('MPH', fontsize=15)
plt.title('Mean Wind and Max Gust', fontsize=20)
plt.legend(["Mean Wind","Max Gust"])
plt.show()
# Plot mean temperature with mean humidity for San Francisco
sf = data.loc[data['ZIP'] == 94107]
plt.figure()
df4 = pd.DataFrame(sf, columns=['meanTemp','meanHum'])
plt.plot(df4.as_matrix(), '-')
plt.grid(True)
plt.autoscale()
plt.xlabel('Month')
plt.ylabel('', fontsize=15)
plt.title('Mean Temperature and Mean Humidity for San Francisco',fontsize=18)
plt.xticks(x,labels,rotation='vertical', fontsize=12)
plt.legend(["Mean Temperature[F]", "Mean Humidity[%]"], fontsize=15)
plt.show()
# replace '' string with blank values to zero in CSV file
data.fillna(0, inplace=True)
# Histogram of Mean Temperature in All cities in Bay Area
plot_hist = plt.hist(data['meanTemp'], bins=10)
plt.xlabel('Temperature [F]', fontsize=15)
plt.ylabel('Amount', fontsize=15)
plt.title('Mean Temperature on San Francisco Bay Area', fontsize=20)
plt.show()
# Plot Area compare Cloud Level and Event such as rain, rain-thunderstorm, fog or fog-rain example for San Francisco
data['events'].replace(['Rain','Rain-Thunderstorm','Fog','Fog-Rain'],[1,1,0,1],inplace=True)
sf = data.loc[data['ZIP'] == 94107]
df7 = pd.DataFrame(sf, columns=['cloud','events'])
df7.plot.area(stacked=False)
plt.xlabel('Month')
plt.ylabel('Cloud Level', fontsize=18)
plt.title('Cloud Level with Events: Rain, Storm, Fog etc.',fontsize=20)
plt.xticks(x,labels,rotation='vertical', fontsize=12)
plt.legend(["Cloud","Rain: 1-yes, 0-no"])
plt.show()
# Plot of min, max and mean pressure for San Francisco
sf = data.loc[data['ZIP'] == 94107]
plt.figure()
df8 = pd.DataFrame(sf, columns=['minPress','meanPress','maxPress'])
plt.plot(df8.as_matrix(), '-')
plt.grid(True)
plt.autoscale()
plt.xlabel('Month')
plt.ylabel('inHg', fontsize=18)
plt.title('Min, Mean and Max Pressure for San Francisco',fontsize=20)
plt.xticks(x,labels,rotation='vertical', fontsize=12)
plt.legend(["Minimum Pressure", "Mean Pressure","Maximum Pressure"])
plt.show()
"""
# Plot of Rain and humidity
plt.figure()
df9 = pd.DataFrame(sf, columns=['events','meanHum'])
plt.plot(df9, '-')
plt.xlabel('Month')
plt.ylabel('')
plt.title('Plot compare Events such as Rain, Fog etc. with mean Humidity', fontsize=20)
plt.xticks(x,labels,rotation='vertical', fontsize=12)
plt.legend(["Rain?", "Mean Humidity"])
plt.show()
# Area Plot compare Cloud Lever and Visibility
df10 = pd.DataFrame(sf, columns=['cloud','minVis'])
df10.plot.area(stacked=False)
plt.xlabel('Month')
plt.ylabel('')
plt.title('Plot compare Cloud Level and Mean Visibility', fontsize=20)
plt.xticks(x,labels,rotation='vertical', fontsize=12)
plt.legend(["Cloud Lever","Mean Visibility"])
plt.show()
"""
# Print all data from CSV file
print(data)