有没有办法将 Spark Df(不是 RDD)转换为 Pandas DF
我尝试了以下方法:
var some_df = Seq(
("A", "no"),
("B", "yes"),
("B", "yes"),
("B", "no")
).toDF(
"user_id", "phone_number")
代码:
%pyspark
pandas_df = some_df.toPandas()
错误:
NameError: name 'some_df' is not defined
有什么建议。
最佳答案
以下应该工作
some_df = sc.parallelize([
("A", "no"),
("B", "yes"),
("B", "yes"),
("B", "no")]
).toDF(["user_id", "phone_number"])
pandas_df = some_df.toPandas()
关于pandas - 将 spark DataFrame 转换为 pandas DF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50958721/