-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdata_prepare.py
51 lines (47 loc) · 1.34 KB
/
data_prepare.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
# pylint: disable=C0103
""" Mapping the AQI to corresponding satellite data"""
import csv
import re
import numpy as np
def out(file):
"""read the datasets from csv files"""
with open(file, 'r') as f:
c = csv.reader(f, dialect='excel')
s = 0
count = 2014000
output = []
next(c, None)
for row in c:
if row[1] == "2014":
if row[4] == "23":
output.append([count, s / 24])
s = 0
count += 1
if row[5] == "NA":
continue
s += int(row[5])
return np.array(output[39:])
def inp(file):
"""Read the datasets from csv files"""
with open(file, 'r') as f:
band = []
next(f, None)
for line in f.readlines():
# data treatment code here
wordList = re.sub("[,]", " ", line).split()
ret = []
for word in wordList:
word = float(word)
ret.append(word)
band.append(ret)
return np.array(band)
def matching(a, b):
"""filtering data"""
temp_a = a
temp_b = b
count = 0
while len(temp_b) != len(temp_a):
if temp_b[count, 0] != temp_a[count, 0]:
temp_b = np.delete(temp_b, count, axis=0)
count += 1
return temp_a, temp_b