I have to save a dataframe to Pickle file, but it returns an error
df.saveAsPickleFile(path)
AttributeError: 'Dataframe' object has no attribute 'saveAsPickleFile'
saveAsPickleFile
is a method of RDD
and not of a data frame.
see this documentation: http://spark.apache.org/docs/latest/api/python/pyspark.html?highlight=pickle
So you can just call:
df.rdd.saveAsPickleFile(filename)
To load it from file, run:
pickleRdd = sc.pickleFile(filename).collect()
df2 = spark.createDataFrame(pickleRdd)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With