-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdataprocess.py
More file actions
50 lines (38 loc) · 1.26 KB
/
dataprocess.py
File metadata and controls
50 lines (38 loc) · 1.26 KB
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
import os
with open("zhaoshang", "r") as file:
lines = file.readlines()
i = 0
newLines = []
newLine = ''
for line in lines:
line = line.strip("\n")
if line.find("/") != -1:
line = line.replace("/","-")
if line.find("+") != -1:
line = line.replace("+","")
if line.find("万") != -1:
line = line.replace("万","")
line = str(round(float(line) * 10000, 1))
elif line.find("亿") != -1:
line = line.replace("亿","")
line = str(round(float(line) * 100000000, 1))
elif line.find("%") != -1:
line = line.replace("%","")
line = str(round(float(line) / 100, 4))
if i % 8 == 7:
newLine = newLine + line + "\n"
newLines.append(newLine)
newLine = ''
elif i % 8 < 7:
line = line + ","
newLine = newLine + line
i = i + 1
# print(line)
# print(newLines)
# print(newLines[-1:-len(newLines):-1])
sortedLines = newLines[-1:-len(newLines):-1]
# print(newLines[0])
sortedLines.insert(0, newLines[0])
print(sortedLines)
with open("China Merchants Bank.csv", "w") as file:
file.writelines(sortedLines)