-
Notifications
You must be signed in to change notification settings - Fork 1
/
1_Step.py
135 lines (126 loc) · 3.79 KB
/
1_Step.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
#!/user/bin/env python3
# -*- coding: utf-8 -*-
'''
作者:Zhixing Tu
时间:2019/11/25 10:49 下午
文件:1_Step.py
IDE:PyCharm
'''
import csv
def function(filename):
with open('./data/PRSA_Data_' + filename + '.csv')as f:
f_csv = csv.reader(f)
ct = 0
year = 0
month = 0
day = 1
Date = ''
PM25 = 0
PM10 = 0
SO2 = 0
NO2 = 0
CO = 0
O3 = 0
count = 0
for row in f_csv:
if ct == 0:
ct = 1
continue
Day = int(row[3])
if Day == day:
count += 1
a = row[5]
b = row[6]
c = row[7]
d = row[8]
e = row[9]
f = row[10]
if a == 'NA':
a = 0
PM25 += a
else:
PM25 += round(float(a))
if b == 'NA':
b = 0
PM10 += b
else:
PM10 += round(float(b))
if c == 'NA':
c = 0
SO2 += c
else:
SO2 += round(float(c))
if d == 'NA':
d = 0
NO2 += d
else:
NO2 += round(float(d))
if e == 'NA':
e = 0
CO += e
else:
CO += round(float(e))
if f == 'NA':
f = 0
O3 += f
else:
O3 += round(float(f))
year = int(row[1])
month = int(row[2])
else:
PM25 = round(PM25 / count)
PM10 = round(PM10 / count)
SO2 = round(SO2 / count)
NO2 = round(NO2 / count)
CO = round(CO / count)
O3 = round(O3 / count)
Date = str(year) + "-" + str(month) + "-" + str(day)
with open('./data/' + filename + '/' + filename + '_' + str(year) + '.csv', 'a+',
encoding='utf-8-sig') as f:
f.write(Date + ',' + str(PM25) + ',' + str(PM10) + ',' + str(SO2) + ',' + str(NO2) + ',' + str(
CO) + ',' + str(O3) + '\n')
count = 1
a = row[5]
b = row[6]
c = row[7]
d = row[8]
e = row[9]
f = row[10]
if a == 'NA':
a = 0
PM25 = a
else:
PM25 = round(float(a))
if b == 'NA':
b = 0
PM10 = b
else:
PM10 = round(float(b))
if c == 'NA':
c = 0
SO2 = c
else:
SO2 = round(float(c))
if d == 'NA':
d = 0
NO2 = d
else:
NO2 = round(float(d))
if e == 'NA':
e = 0
CO = e
else:
CO = round(float(e))
if f == 'NA':
f = 0
O3 = f
else:
O3 = round(float(f))
year = int(row[1])
month = int(row[2])
day = int(row[3])
if __name__ == '__main__':
Cities = ["Aotizhongxin", "Changping", "Dingling", "Dongsi", "Guanyuan",
"Gucheng", "Huairou", "Nongzhanguan", "Shunyi", "Tiantan", "Wanliu", "Wanshouxigong"]
for i in Cities:
function(str(i))