ValueError: could not convert string to float:

uuxxl 2017-03-28 10:04:44
python2.7的代码在python3.6的环境下运行,报错。temp=float(lis[date_idx][6:]) * 60.。十分确定float()函数里的值为数字。请问大神们,我应该怎么修改代码。
...全文
2674 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
sanGuo_uu 2017-03-29
  • 打赏
  • 举报
回复
引用 2 楼 sxl_xl 的回复:
lis[date_idx]的数据是14102100,理论上来说lis[date_idx][6:] 应该为00。源码为int(lis[date_idx][6:]) * 60。但是在会报int() with base 10,因此我将int()改为float()。但是还是报valueError。大神请帮帮我
我去论坛上查了下。 python转换为int型错误 它会报int() with base 10,说明你的int函数参数为空字符串,而不是你上面说的 你可以针对这点改下。
>>> c = ''
>>> i = int(c)
Traceback (most recent call last):
  File "<pyshell#26>", line 1, in <module>
    i = int(c)
ValueError: invalid literal for int() with base 10: ''
uuxxl 2017-03-29
  • 打赏
  • 举报
回复
引用 1 楼 u012536120 的回复:
我试了下,没问题啊 lis[date_idx][6:] 把这个贴出来看下
lis[date_idx]的数据是14102100,理论上来说lis[date_idx][6:] 应该为00。源码为int(lis[date_idx][6:]) * 60。但是在会报int() with base 10,因此我将int()改为float()。但是还是报valueError。大神请帮帮我
uuxxl 2017-03-29
  • 打赏
  • 举报
回复
引用 3 楼 u012536120 的回复:
[quote=引用 2 楼 sxl_xl 的回复:] lis[date_idx]的数据是14102100,理论上来说lis[date_idx][6:] 应该为00。源码为int(lis[date_idx][6:]) * 60。但是在会报int() with base 10,因此我将int()改为float()。但是还是报valueError。大神请帮帮我
我去论坛上查了下。 python转换为int型错误 它会报int() with base 10,说明你的int函数参数为空字符串,而不是你上面说的 你可以针对这点改下。
>>> c = ''
>>> i = int(c)
Traceback (most recent call last):
  File "<pyshell#26>", line 1, in <module>
    i = int(c)
ValueError: invalid literal for int() with base 10: ''
[/quote] 打印出来了,发现是因为用excel删除数据行的时候保存的时候居然把数据删除了,但是还保留着,。 谢谢你大神。
sanGuo_uu 2017-03-29
  • 打赏
  • 举报
回复
我试了下,没问题啊 lis[date_idx][6:] 把这个贴出来看下

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧