-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsv_mat.py
28 lines (25 loc) · 873 Bytes
/
csv_mat.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
import csv
with open('data.csv', 'r') as csvfile:
spamreader = csv.reader(csvfile, delimiter=',')
list_of_list = []
j=0
lines = [line for line in spamreader]
for i in range(len(lines)):
list_ = []
if(len(lines)<=i+j):
break;
first = lines[i+j][0]
while(first == lines[i+j][0]):
list_.append(lines[i+j][2])
j+=1
if(len(lines)<=i+j):
break;
j-=1
list_of_list.append(list(map(float,list_)))
#maxlen = len(max(list_of_list))
#print("\t"+"\t".join([str(el) for el in range(1,maxlen+1)])+"\n")
#for i in range(len(list_of_list)):
# print(str(i+1)+"\t"+"\t".join([str(el) for el in list_of_list[i]])+"\n")
with open("out.csv", "w", newline="") as f:
writer = csv.writer(f)
writer.writerows(list_of_list)