0
我想用两个RDD的列创建一个Dataframe。 第一个是我从CSV获得的RDD,第二个是另一个RDD,每行都有一个集群预测。将RDD添加到DataFrame列PySpark
我的模式是:
customSchema = StructType([ \
StructField("Area", FloatType(), True), \
StructField("Perimeter", FloatType(), True), \
StructField("Compactness", FloatType(), True), \
StructField("Lenght", FloatType(), True), \
StructField("Width", FloatType(), True), \
StructField("Asymmetry", FloatType(), True), \
StructField("KernelGroove", FloatType(), True)])
地图我RDD和创建数据框:
FN2 = rdd.map(lambda x: (float(x[0]), float(x[1]),float(x[2]),float(x[3]),float(x[4]),float(x[5]),float(x[6])))
df = sqlContext.createDataFrame(FN2, customSchema)
而且我的群集预测:
result = Kmodel.predict(rdd)
所以,最后我想有在我的DataFrame中我的CSV行和他们的集群预测在最后。
我试图添加一个新的列与.WithColumn(),但我什么都没有。
谢谢。