如何从其他两个数据框创建一个数据框? [英] How to create a dataframe from two others dataframe?

查看:85
本文介绍了如何从其他两个数据框创建一个数据框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这两个dataframe对象,每个对象都有一个列:

I have these two dataframe objects, with a single column each:

a = predictons_lr.select('prediction')
b = predictions_nb.select('prediction')

我想创建一个以 a b 为列的单个结果数据框.我已经尝试过:

I would like to create a single resulting dataframe having a and b as columns. I have tried:

df_result = spark.createDataFrame([a, b])

但我收到此错误:

AssertionError:位于0x000002260F3D4240的dataType py4j.java_gateway.JavaMember对象应该是"pyspark.sql.types.DataType"类的实例.

AssertionError: dataType py4j.java_gateway.JavaMember object at 0x000002260F3D4240 should be an instance of class 'pyspark.sql.types.DataType'

有没有一种有效的方法来创建这种数据框?

There is an efficient method to create a dataframe of this kind?

推荐答案

如果这两列都是相同的数据类型,则只需合并即可

If this two column are same data type , you can just union

a = predictons_lr.select('prediction')
b = predictions_nb.select('prediction')

new_df = a.union(b)

这篇关于如何从其他两个数据框创建一个数据框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆