gpt4 book ai didi

python - 是什么导致了此错误(ValueError : could not convert string to float: 'High' )?

转载 作者:太空宇宙 更新时间:2023-11-03 20:42:06 25 4
gpt4 key购买 nike

我不知道如何修复错误(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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com