【问题标题】:What is causing this error (ValueError: could not convert string to float: 'High')? [duplicate]是什么导致了这个错误(ValueError: could not convert string to float: 'High')? [复制]
【发布时间】:2019-11-10 00:21:05
【问题描述】:

我不知道如何修复错误(ValueError: could not convert string to float: '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])

【问题讨论】:

    标签: python string csv


    【解决方案1】:

    我猜你的 CSV 有一个标题行,所以第一行的列值是字符串“High”,它不能转换为数字。在这种情况下,只需在 for 循环之前调用 next(csv_reader) 即可跳过第一行。

    【讨论】:

      猜你喜欢
      • 2021-11-26
      • 2021-11-19
      • 1970-01-01
      • 2020-12-11
      • 2019-12-18
      • 2018-02-13
      • 1970-01-01
      • 2019-05-22
      • 1970-01-01
      相关资源
      最近更新 更多