ValueError:无法将字符串转换为在Pyspark中浮动 [英] ValueError: could not convert string to float in Pyspark

查看:91
本文介绍了ValueError:无法将字符串转换为在Pyspark中浮动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Spark RDD看起来像这样

my spark RDD looks something like this

totalDistance=flightsParsed.map(lambda x:x.distance)
totalDistance.take(5)


[1979.0, 640.0, 1947.0, 1590.0, 874.0]

但是当我在其上运行reduce时,出现如下所述的错误

But when i run reduce on it I get error as mentioned below

totalDistance=flightsParsed.map(lambda x:x.distance).reduce(lambda y,z:y+z)

ValueError:无法将字符串转换为float:

ValueError: could not convert string to float:

请帮助.

推荐答案

您尝试过:

totalDistance=flightsParsed.map(lambda x: int(x.distance or 0))

totalDistance=flightsParsed.map(lambda x: float(x.distance or 0))

在flightsParsed中您可能缺少或不一致的数据

You may have missing or inconsistent data inside flightsParsed

这篇关于ValueError:无法将字符串转换为在Pyspark中浮动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆