Pyspark: saveastextfile ended up in TypeError: unsupported operand type(s) for /: 'unicode' and 'float'

Hi guys,
Need help here.
I was trying to save output of spark RDD into text file and got following error:

TypeError: unsupported operand type(s) for /: ‘unicode’ and ‘float’

Here are sample records:

filedata.take(3)
[‘3724\t3.63’, ‘344\t3.25’, ‘346\t3.53’]

Here is code to save file:
result.saveAsTextFile("/user/myusername/problem5/solution.txt")

Edit1: Now i converted result to string rdd before saving as text file and still getting same error.r

result.map(lambda x: “\t”.join(str(i) for i in x)).saveAsTextFile("/user/myusername/problem5/solution.txt")

(or)

result.map(lambda x: (str(x[0])+"\t"+str(x[1])).saveAsTextFile("/user/myusername/problem5/solution.txt")

Na, its still not generating file but not showing error.

result = moviefinal.filter(lambda x: x[1] > 3)
result.map(lambda x: (str(x[0])+"\t"+str(x[1])).saveAsTextFile("/user/myusername/problem5/solution3.txt")

… )
PythonRDD[6] at RDD at PythonRDD.scala:43

And it still generates same error with this command - result.map(lambda x: “\t”.join(str(i) for i in x)).saveAsTextFile("/user/myusername/problem5/solution.txt")

its still not generating file? means what?

please check the output dir do not exists before executing the code.

If that is not the case please share complete code, i can help you

sorry Karthik, i should have replied earlier. I was able to solve problem by type casting to string for couple of elements of RDD.

1 Like