Spark -Python无法在列中添加值

时间:2018-01-30 08:12:42

标签: python-3.x pyspark

我创建了一个名为Distance的RDD。所有都是浮点值。我打算添加它们并找到总和。

print(Distance.take(5))
Output : [802.0, 1055.0, 919.0, 204.0, 951.0]

print(sum(Distance.take(5)))
Output : 3931.0

totalDistance=Distance.reduce(lambda x,y:(x+y))
Output: Py4JJavaError                             Traceback (most recent call last)
<ipython-input-29-874f9e382e38> in <module>()
  2 # Reduce takes a function that acts on two elements and returns an object of same type.
  3 
----> 4 totalDistance=Distance.reduce(lambda x,y:(x+y))

0 个答案:

没有答案