-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataPrepare.py
119 lines (103 loc) · 3.34 KB
/
DataPrepare.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
import time
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
class AllData:
def AllData(self):
self.ConfirmedData = []
self.DeathData = []
self.RecoverData = []
self.AreaName = []
class Data:
def Data(self):
self.ConfirmedData = 0
self.DeathData = 0
self.RecoverData = 0
self.AreaName = ''
def LoadData(filename):
df = pd.read_csv(filename, header=None)
data = df.values
st,ed = 1,1
#去掉地区,将治愈的 nan 改成 0
while ed < data.shape[0] :
if pd.isna(data[ed][13]):
data[st] = data[ed]
st = st + 1
ed = ed + 1
data = data[0:st]
for line in range(data.shape[0]):
if pd.isna(data[line][6]):
data[line][6] = 0
res = AllData()
res.ConfirmedData = data[:, 2][1:]
res.ConfirmedData = res.ConfirmedData.astype('float32')
res.DeathData = data[:, 4][1:]
res.DeathData = res.DeathData.astype('float32')
res.RecoverData = data[:, 6][1:]
res.RecoverData = res.RecoverData.astype('float32')
res.AreaName = data[:,12][1:]
#print(res.RecoverData)
#for i in range(len(res.ConfirmedData)):
#res.ConfirmedData[i] -= res.RecoverData[i] + res.DeathData[i]
#print(res.ConfirmedData)
#改百分比
#for line in range(res.ConfirmedData.shape[0]):
#res.RecoverData[line] = res.RecoverData[line]/res.ConfirmedData[line] * 100
#res.DeathData[line] = res.DeathData[line]/res.ConfirmedData[line] * 100
arr = []
dic = {}
now = []
#print(res.ConfirmedData.shape)
for _ in range(res.ConfirmedData.shape[0]):
if res.AreaName[_] in dic:
x = Data()
x.ConfirmedData = res.ConfirmedData[_]
x.DeathData = res.DeathData[_]
x.RecoverData = res.RecoverData[_]
x.AreaName = res.AreaName[_]
now.append(x)
else:
dic[res.AreaName[_]] = 1
if len(now) != 0:
arr.append(now)
now = []
arr.append(now)
return arr
def Patch(data, size):
data = [0] * (size - len(data)) + data
return data
#This will return a (size-2) shape vector, where each element is (d^2 f \ dx^2) \ (df\dx)
def GetRate(data, size):
ret = []
res = []
for i in range(len(data)):
for j in range(1, size - 2):
deri1 = (data[i][j+1] - data[i][j-1]) / 2
deri2 = (data[i][j+1] - data[i][j]) - (data[i][j] - data[i][j-1])
#deri1 = data[i][j]
#deri2 = (data[i][j+1] - data[i][j-1]) / 2
if deri1 == 0:
res.append(0)
else:
res.append(deri2 / deri1)
ret.append(res)
res = []
return ret
def GetConfirmed(data, size):
res = []
for i in range(len(data[0])):
res.append(data[0][i].ConfirmedData)
ret = []
for i in range(len(data[0])):
ret.append(Patch(res[max(0, i-size):i], size))
return ret
def GetDeath(data, size):
res = []
for i in range(len(data[0])):
res.append(data[0][i].DeathData)
ret = []
for i in range(len(data[0])):
ret.append(Patch(res[max(0, i-size):i], size))
return ret
if __name__ == "__main__":
LoadData('data.csv')