-
Notifications
You must be signed in to change notification settings - Fork 0
/
reader.py
29 lines (23 loc) · 1011 Bytes
/
reader.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
import csv
def change_csv(path):
with open(path) as csv_file:
# reading code is from https://docs.python.org/3/library/csv.html#csv.Sniffer
dialect = csv.Sniffer().sniff(csv_file.read(1024))
csv_file.seek(0)
reader = csv.reader(csv_file, dialect)
output = []
row_size = 0 # tracking number of rows with this one
for row in reader:
# only going to check row size the first time around
if row_size == 0:
row_size = len(row)
# we will create a list for all values except last and convert to tuple
list_except_last = []
for i in range(row_size):
list_except_last.append(int(row[i - 1]))
# convert our list to tuple
tuple_except_last = tuple(list_except_last)
# add the final element
complete_tuple = (tuple_except_last, (float(row[row_size - 1])))
output.append(complete_tuple)
return output