首页 > 其他 > 详细

RDD转dataframe

时间:2020-07-07 15:03:59      阅读:54      评论:0      收藏:0      [点我收藏+]
from pyspark.sql import SparkSession,Row
from pyspark.sql.types import StructField, StructType, StringType, IntegerType, LongType
data = [(Alex,male,3),(Nancy,female,6),[Jack,male,9]] # mixed
rdd_ = spark.sparkContext.parallelize(data)

# schema
schema = StructType([
        # true代表不为空
        StructField("name", StringType(), True),
        StructField("gender", StringType(), True),
        StructField("num", StringType(), True)
    ])
df = spark.createDataFrame(rdd_, schema=schema)  # working when the struct of data is same.
print(df.show()) 

 

RDD转dataframe

原文:https://www.cnblogs.com/muyue123/p/13260672.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!