-
Notifications
You must be signed in to change notification settings - Fork 0
/
normalize_data.py
62 lines (49 loc) · 1.83 KB
/
normalize_data.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
import pandas as pd
import numpy as np
import zipfile
import csv
list_100 = ['PS1', 'PS2', 'PS3', 'PS4', 'PS5',
'PS6', 'EPS1']
list_10 = ['FS1', 'FS2']
list_100 = [s + '.txt' for s in list_100]
list_10 = [s + '.txt' for s in list_10]
master_df = pd.DataFrame()
for key in list_100:
new_file = open(key.replace('.txt', '') + '_normalized.csv', "w")
writer = csv.writer(new_file, delimiter='\t')
with zipfile.ZipFile('data.zip') as myzip:
with myzip.open(key) as myfile:
df = pd.read_table(myfile, header=None)
for i in range(2205):
row = df.loc[i, :].values.tolist()
definite_row = []
sum = 0
for x, y in enumerate(row):
if x == 0:
sum += y
elif x == len(row)-1:
sum += y
definite_row.append(sum/2)
elif x % 2 != 0:
sum += y
else:
definite_row.append(sum/2)
sum = 0
sum += y
writer.writerow(definite_row)
del definite_row[:]
for key in list_10:
new_file = open(key.replace('.txt', '') + '_normalized.csv', "w")
writer = csv.writer(new_file, delimiter='\t')
with zipfile.ZipFile('data.zip') as myzip:
with myzip.open(key) as myfile:
df = pd.read_table(myfile, header=None)
# df.to_csv(header=None, index=None)
for i in range(2205):
row = df.loc[i, :].values.tolist()
definite_row = []
sum = 0
for x, y in enumerate(row):
definite_row.append(y)
writer.writerow(definite_row)
del definite_row[:]