-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhigher_dim.py
More file actions
executable file
·43 lines (39 loc) · 1.36 KB
/
higher_dim.py
File metadata and controls
executable file
·43 lines (39 loc) · 1.36 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
#!/usr/local/bin/python3
def readlines(filename, **kwargs):
f = open(filename)
feature_names = f.readline().replace(',', ';').replace(' ', '_').split(";")
print(feature_names)
feature_names[-1] = feature_names[-1].replace('\n', '')
print(feature_names)
shortFile = []
i = 0
while True:
row = f.readline().replace(',', ';')
limit = i
if row == "":
print("hit limit:", i)
break
shortFile.append(row.split(';'))
i += 1
if shortFile:
with open("squared_" + filename, 'w') as fo:
new_features = []
for value in feature_names:
new_features.append(value)
new_features.append(value + '_squared')
del new_features[-1]
fo.write(", ".join(new_features) + "\n")
for row in shortFile:
print('row', row)
new_row = []
for value in row:
print('v', value)
print(type(value))
new_row.append(str(float(value)))
new_row.append(str(float(value)**2))
del new_row[-1]
new_row_s = ", ".join(new_row)
fo.write(new_row_s + '\n')
if __name__ == "__main__":
readlines("winequality-red.csv")
# readlines("winequality-white.csv")