I have a text file containing some data stored in three columns. The first column is separated from the second by a comma (,) and a tab (\t) and the same for the separation between the second and the third. However, the last column is terminated with a comma and a newline command (\n). Here is an example:
0.782470450031, 0.0, 0.0, 0.775811285325, 0.025, 0.0, 0.768594334758, 0.05, 0.0, 0.761101295788, 0.075, 0.0, I would like to read this file and transform it into an array. If the columns were only separated by a comma I would just do:
f=open(filename,'r') data=[map(float,line.split(',')) for line in f] data=np.array(data) But I am not exactly sure how to do this in this case.
Thanks in advance for your help!
csvmodule.floatconversion will discard all of that for examplefloat('\t12.5\t\n')will produce the float12.5.