-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhw1.py
71 lines (61 loc) · 1.95 KB
/
hw1.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
# Part. 1
#=======================================
# Import module
# csv -- fileIO operation
import csv
#=======================================
# Part. 2
#=======================================
# Read cwb weather data
cwb_filename = '106061123.csv'
data = []
header = []
with open(cwb_filename) as csvfile:
mycsv = csv.DictReader(csvfile)
header = mycsv.fieldnames
for row in mycsv:
data.append(row)
#=======================================
# Part. 3
#=======================================
# Analyze data depend on your group and store it to target_data like:
# Retrive all data points which station id is "C0X260" as a list.
# target_data = list(filter(lambda item: item['station_id'] == 'C0X260', data))
i = 0
while i in range(len(data)):
if data[i]["WDSD"] == "-99.000" or data[i]["WDSD"] == "-999.000":
del data[i]
else:
i += 1
header = ["C0A880", "C0F9A0", "C0G640", "C0R190", "C0X260"]
my_list = [[] for i in range(5)]
for row in data:
if row["station_id"] == header[0]:
my_list[0].append(float(row["WDSD"]))
if row["station_id"] == header[1]:
my_list[1].append(float(row["WDSD"]))
if row["station_id"] == header[2]:
my_list[2].append(float(row["WDSD"]))
if row["station_id"] == header[3]:
my_list[3].append(float(row["WDSD"]))
if row["station_id"] == header[4]:
my_list[4].append(float(row["WDSD"]))
data.clear()
data = [[]for i in range(5)]
for i in range(5):
if len(my_list[i]) >1:
my_list[i].sort()
my_list[i] = my_list[i][len(my_list[i]) - 1] - my_list[i][0]
data[i].append(header[i])
data[i].append(my_list[i])
else:
data[i].append(header[i])
data[i].append('None')
# Retrive ten data points from the beginning.
target_data = data[:5]
#=======================================
# Part. 4
#=======================================
# Print result
print(target_data)
#========================================