-
Notifications
You must be signed in to change notification settings - Fork 217
/
Plot_AQI.py
163 lines (143 loc) · 4.69 KB
/
Plot_AQI.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
162
163
import pandas as pd
import matplotlib.pyplot as plt
def avg_data_2013():
temp_i=0
average=[]
for rows in pd.read_csv('Data/AQI/aqi2013.csv',chunksize=24):
add_var=0
avg=0.0
data=[]
df=pd.DataFrame(data=rows)
for index,row in df.iterrows():
data.append(row['PM2.5'])
for i in data:
if type(i) is float or type(i) is int:
add_var=add_var+i
elif type(i) is str:
if i!='NoData' and i!='PwrFail' and i!='---' and i!='InVld':
temp=float(i)
add_var=add_var+temp
avg=add_var/24
temp_i=temp_i+1
average.append(avg)
return average
def avg_data_2014():
temp_i=0
average=[]
for rows in pd.read_csv('Data/AQI/aqi2014.csv',chunksize=24):
add_var=0
avg=0.0
data=[]
df=pd.DataFrame(data=rows)
for index,row in df.iterrows():
data.append(row['PM2.5'])
for i in data:
if type(i) is float or type(i) is int:
add_var=add_var+i
elif type(i) is str:
if i!='NoData' and i!='PwrFail' and i!='---' and i!='InVld':
temp=float(i)
add_var=add_var+temp
avg=add_var/24
temp_i=temp_i+1
average.append(avg)
return average
def avg_data_2015():
temp_i=0
average=[]
for rows in pd.read_csv('Data/AQI/aqi2015.csv',chunksize=24):
add_var=0
avg=0.0
data=[]
df=pd.DataFrame(data=rows)
for index,row in df.iterrows():
data.append(row['PM2.5'])
for i in data:
if type(i) is float or type(i) is int:
add_var=add_var+i
elif type(i) is str:
if i!='NoData' and i!='PwrFail' and i!='---' and i!='InVld':
temp=float(i)
add_var=add_var+temp
avg=add_var/24
temp_i=temp_i+1
average.append(avg)
return average
def avg_data_2016():
temp_i=0
average=[]
for rows in pd.read_csv('Data/AQI/aqi2016.csv',chunksize=24):
add_var=0
avg=0.0
data=[]
df=pd.DataFrame(data=rows)
for index,row in df.iterrows():
data.append(row['PM2.5'])
for i in data:
if type(i) is float or type(i) is int:
add_var=add_var+i
elif type(i) is str:
if i!='NoData' and i!='PwrFail' and i!='---' and i!='InVld':
temp=float(i)
add_var=add_var+temp
avg=add_var/24
temp_i=temp_i+1
average.append(avg)
return average
def avg_data_2017():
temp_i=0
average=[]
for rows in pd.read_csv('Data/AQI/aqi2017.csv',chunksize=24):
add_var=0
avg=0.0
data=[]
df=pd.DataFrame(data=rows)
for index,row in df.iterrows():
data.append(row['PM2.5'])
for i in data:
if type(i) is float or type(i) is int:
add_var=add_var+i
elif type(i) is str:
if i!='NoData' and i!='PwrFail' and i!='---' and i!='InVld':
temp=float(i)
add_var=add_var+temp
avg=add_var/24
temp_i=temp_i+1
average.append(avg)
return average
def avg_data_2018():
temp_i=0
average=[]
for rows in pd.read_csv('Data/AQI/aqi2018.csv',chunksize=24):
add_var=0
avg=0.0
data=[]
df=pd.DataFrame(data=rows)
for index,row in df.iterrows():
data.append(row['PM2.5'])
for i in data:
if type(i) is float or type(i) is int:
add_var=add_var+i
elif type(i) is str:
if i!='NoData' and i!='PwrFail' and i!='---' and i!='InVld':
temp=float(i)
add_var=add_var+temp
avg=add_var/24
temp_i=temp_i+1
average.append(avg)
return average
if __name__=="__main__":
lst2013=avg_data_2013()
lst2014=avg_data_2014()
lst2015=avg_data_2015()
lst2016=avg_data_2016()
lst2017=avg_data_2017()
lst2018=avg_data_2018()
plt.plot(range(0,365),lst2013,label="2013 data")
plt.plot(range(0,364),lst2014,label="2014 data")
plt.plot(range(0,365),lst2015,label="2015 data")
plt.plot(range(0,121),lst2016,label="2016 data")
plt.xlabel('Day')
plt.ylabel('PM 2.5')
plt.legend(loc='upper right')
plt.show()