[英]How do I read in this csv-file in python? (3 commas (,,,) in each row)
I tried我试过
measurements = np.loadtxt(fname = 'TEK0001.CSV', delimiter = ',')
which gives back an error message: "could not convert string to float".这会返回一条错误消息:“无法将字符串转换为浮点数”。
The data is obtained from an oszilloscope.数据是从示波器获得的。 I want to read in the csv file as a two dimensional array which I then can plot.我想在 csv 文件中读取一个二维数组,然后我可以绘制它。
Csv-file: TEK0001.CSV CSV 文件:TEK0001.CSV
,,,00.000000055000, -0.18400,
,,,00.000000056000, -0.18400,
,,,00.000000057000, -0.18400,
,,,00.000000058000, -0.20000,
,,,00.000000059000, -0.20800,
,,,00.000000060000, -0.21600,
,,,00.000000061000, -0.22400,
,,,00.000000062000, -0.22400,
,,,00.000000063000, -0.24000,
,,,00.000000064000, -0.23200,
,,,00.000000065000, -0.23200,
,,,00.000000066000, -0.21600,
,,,00.000000067000, -0.20000,
,,,00.000000068000, -0.19200,
,,,00.000000069000, -0.17600,
,,,00.000000070000, -0.16000,
,,,00.000000071000, -0.15200,
,,,00.000000072000, -0.13600,
,,,00.000000073000, -0.14400,
,,,00.000000074000, -0.12800,
,,,00.000000075000, -0.12800,
,,,00.000000076000, -0.12800,
,,,00.000000077000, -0.12800,
,,,00.000000078000, -0.12000,
,,,00.000000079000, -0.12000,
,,,00.000000080000, -0.12000,
,,,00.000000081000, -0.12000,
,,,00.000000082000, -0.12000,
,,,00.000000083000, -0.12000,
,,,00.000000084000, -0.11200,
,,,00.000000085000, -0.11200,
,,,00.000000086000, -0.12000,
,,,00.000000087000, -0.12800,
,,,00.000000088000, -0.12800,
,,,00.000000089000, -0.13600,
,,,00.000000090000, -0.13600,
,,,00.000000091000, -0.14400,
,,,00.000000092000, -0.14400,
,,,00.000000093000, -0.14400,
,,,00.000000094000, -0.15200,
,,,00.000000095000, -0.13600,
,,,00.000000096000, -0.14400,
,,,00.000000097000, -0.15200,
,,,00.000000098000, -0.15200,
,,,00.000000099000, -0.16000,
,,,00.000000100000, -0.16800,
,,,00.000000101000, -0.16800,
,,,00.000000102000, -0.17600,
,,,00.000000103000, -0.19200,
,,,00.000000104000, -0.19200,
,,,00.000000105000, -0.20800,
,,,00.000000106000, -0.20000,
,,,00.000000107000, -0.21600,
Commas mean that cells are empty, also an extra comma at the end of each line must be stripped.逗号表示单元格为空,每行末尾的额外逗号也必须去掉。 A workaround is to explicitly specify which columns to parse.解决方法是明确指定要解析的列。 For that you can use usecols
argument which in your case has value [3,4]
为此,您可以使用usecols
参数,该参数在您的情况下具有值[3,4]
np.loadtxt('test.csv', delimiter=',', usecols=[3,4])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.