Importing a cvs file and converting to a matrix of float fails

asked 2020-07-05 17:20:00 +0200

Cyrille gravatar image

updated 2020-07-05 17:21:03 +0200

Here is a cvs file

;Airbus;LOréal;Total;Crédit Agricole;BNP Paribas
04-01-2010;13.98;78.38;45.37;12.45;56.14
05-01-2010;13.88;79.61;45.75;12.8;57.23
06-01-2010;13.96;78.57;45.675;13.02;57.35
07-01-2010;13.91;77.94;45.765;13.16;57
08-01-2010;14.315;78.59;46.01;13.34;58.45
11-01-2010;14.47;78.28;46.19;13.5;60
12-01-2010;14.475;78.34;46.13;13.25;59.06
13-01-2010;14.05;77.92;45.64;12.705;57.59
14-01-2010;14.175;79.05;45.55;12.91;58.94
15-01-2010;14.25;77.79;45;13.1;58.91
18-01-2010;14.48;78.61;44.085;13.1;56.99
19-01-2010;14.67;78.9;44.6;12.825;56.21
20-01-2010;14.76;79.9;44.96;12.865;56.06
21-01-2010;14.89;79.33;44.65;12.77;55.56
22-01-2010;14.345;77.51;43.5;12.08;53.3
25-01-2010;14.04;76.59;42.81;11.89;51.97
26-01-2010;13.87;76;42.34;11.81;50.99
27-01-2010;13.81;77.5;42.5;11.7;51.96
28-01-2010;13.95;78.09;42.895;11.9;52.84
29-01-2010;13.81;76.26;41.7;11.42;51.33

named hereafter global.csv. And here is a code to read it in Sage

import csv
file=r'C:\data\Global.csv'
reader=csv.reader(open(file, encoding = "ISO-8859-1"), delimiter=';')
tbl=[]
for row in reader:
    tbl.append(row)
tbl.pop(0) #Ne prend pas en compte la première ligne
G=[tbl[i][1:len(tbl)] for i in range(len(tbl))]
GG=[[float(eval(preparse(G[i][j]))) for i in range(len(G))] for j in range(len(G[0]))]

I have the infamous unexpected EOF while parsing's error. But what is strange is that normaly this error comes with an unbalanced () or []. But I have verified the parity of both and I donot see my error. Thanks for help

edit retag flag offensive close merge delete