我不知道如何修复错误(ValueError:无法将字符串转换为 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])
最佳答案
我猜您的 CSV 有标题行,因此第一行中的列值是字符串“High”,无法转换为数字。在这种情况下,只需在 for
循环之前调用 next(csv_reader)
即可跳过第一行。
关于python - 是什么导致了此错误(ValueError : could not convert string to float: 'High' )?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56800168/