python - 是什么导致了这个错误(ValueError: could not convert string to float: 'High')?
问题描述
我不知道如何修复错误(ValueError:无法将字符串转换为浮点数:'High')。任何帮助将非常感激。
high = 0
with open('file.csv', 'r') as csv_file:
csv_reader = csv.reader(csv_file)
for line in csv_reader:
if float(line[2]) > high:
high = float(line[2])
解决方案
我猜你的 CSV 有一个标题行,所以第一行的列值是字符串“High”,它不能转换为数字。在这种情况下,只需在循环next(csv_reader)
之前调用即可跳过第一行。for
推荐阅读
- java - Android - 线程问题(随机字符在按钮中切换,直到单击按钮)
- go - GO编程,在阅读器事件上阻塞读取功能
- r - 无法在 jupyter 中加载 ggmap 包
- redux-form - 带有 Reactstrap 的 Redux-form
- java - Java Android getApplicationContext() 从上一个类返回一个空对象
- swift - 即使在保护自我和非可选属性之后,也可以获取“在初始化之前使用的变量‘self.xxx’”
- ios - 如何处理拍摄的图像,然后使用 Swift 将结果查看到“文本视图”?
- mongodb - MongoDB 从子子数组中删除所有匹配项
- java - 来自先前 Spring Boot 测试的 Quartz 作业随机仍在运行
- javascript - Libgdx HTML5 AnimationScheduler 长度为空