【问题标题】:ValueError: could not convert string to float in PysparkValueError:无法在 Pyspark 中将字符串转换为浮点数
【发布时间】:2018-05-13 13:26:10
【问题描述】:

我的 spark RDD 看起来像这样

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


[1979.0, 640.0, 1947.0, 1590.0, 874.0]

但是当我在它上面运行 reduce 时,我得到如下所述的错误

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

ValueError:无法将字符串转换为浮点数:

请帮忙。

【问题讨论】:

  • There are several 类似问题。我建议先阅读这些内容,并确保您的数据进入,或者在算术之前被转换为浮点数。

标签: apache-spark pyspark rdd


【解决方案1】:

你试过了吗:

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

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

您可能在 flightParsed 中有丢失或不一致的数据

【讨论】:

    猜你喜欢
    • 2017-12-10
    • 1970-01-01
    • 2016-07-06
    • 2019-03-23
    • 2018-06-13
    • 2013-05-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多