1 | initial version |
Supposed you have a csv file separating the values by comma and separating the rows by semicolon: get rid of the whitespaces, split the csv file into a list of rows, the rows into lists of data, and zip these lists to tuples.
csv_data = """ 0.1 , 2 , 3.01, 4; 5, 6.7, 7, 8;
9, 8, 7, 6 ; """
csv_data = ''.join(csv_data.split())
rows = csv_data.split(';')
print rows
rows = [row.split(',') for row in rows if row<>'']
rows = [[float(data) for data in rows[k] ] for k in range(len(rows))]
print rows
list_of_tuples = zip(rows[0],rows[1],rows[2])
print list_of_tuples
a = vector(list_of_tuples[0]) # and so on
2 | No.2 Revision |
Supposed you have a csv file separating the values by comma and separating the rows by semicolon: get rid of the whitespaces, split the csv file into a list of rows, the rows into lists of data, and zip these lists to tuples.
csv_data = """ 0.1 , 2 , 3.01, 4; 5, 6.7, 7, 8;
9, 8, 7, 6 ; """
csv_data = ''.join(csv_data.split())
rows = csv_data.split(';')
print rows
rows = [row.split(',') for row in rows if row<>'']
rows = [[float(data) for data in rows[k] ] for k in range(len(rows))]
print rows
list_of_tuples = zip(*rows) # zip(rows[0],rows[1],rows[2])
print list_of_tuples
a = vector(list_of_tuples[0]) # and so on