I'm new to Spark and code in Python. I save the processed data by using saveAsTextFile
. The data are lists of rows and are turned into strings after being saved. When I load them via numpy.loadtxt("filename", delimiter=',')
(this method will automatically transform loaded data into float), there is an error report said that the data can't be transformed into float because of the '[' square brackets.
So how can I save lists of rows without square brackets, or with those brackets but later load them and transform them into float correctly?
Sorry I'm also new to SO. Here are explanations why my question isn't a duplicate one.
The similar question in linked column is in Scala but mine is in Python(Although answers are in Scala). Besides, here is an answer using replace
that can solve my question(remove square brackets of lists) perfectly but this method hasn't been present in the similar question.(I'm not sure whether my second point is an explanation) I've comment the Python version of replace
method for later viewers of this question.