python - 确定 csv 表中每一列的大小
问题描述
我正在尝试从 csv 文件中读取一对列,并想知道每一对中每一列的大小。
我已经尝试了附加的代码。它会引发以下错误:(1)字符串无法转换为浮点数,只要它看到空白单元格(2)IndexError,如果要读取的第一对比其余的小。基本上, len(table) 给出了表中的最大行数。或者我在这里错过了什么。
x1 y1 x2 y2
0.0031 0.01527 -0.41973 0.01237
0.30568 0.08478 -0.07486 0.16463
0.4986 0.26355 0.0097 0.44943
0.61884 0.5102 0.30568 0.83218
0.75758 0.90136 0.62544 0.98121
1.02977 0.96214
# Save above data to file temp.csv (strip-off the first row) and the try to
# read by following code
infile = open("temp.csv", 'r')
table = []
for row in csv.reader(infile):
table.append(row)
infile.close() # better leave that file alone.
for r in range (0, len(table)):
for c in range(0, len(table[r])):
table[r][c] = float(table[r][c])
float() 将给出错误:ValueError: could not convert string to float for the second set of data。
当 csv 表中的所有对大小不同时,我想知道每个单独对的大小。
解决方案
推荐阅读
- asp.net-mvc - 在 asp.net MVC 应用程序中展开行时,Kendo 嵌套网格绑定内部网格
- node.js - 避免统一请求标头中的 Content-Length
- c# - 如何过滤子集合,将 datetime 属性与另一个一加时间跨度值进行比较?
- javascript - 如何在html中按下按钮时触发Angular Mentions?
- reactjs - 如何在 react-chart-js-2 中使用填充 true 隐藏边框
- logging - GCP StackDriver RESTful API 没有记录,即使它返回 200
- javascript - 如何在单个页面中处理多个 mathquill 元素
- android - 在活动之间切换屏幕/视图
- git - Gitlab-CE 中的开发人员和维护人员权限正在实现自动合并
- json - 如何使用 python json.loads 处理 json 日期中的“\”