简体   繁体   English

如何将 append 一个 dataframe 变成另一个 dataframe 作为一列

[英]How to append one dataframe into another dataframe as a column

May be my issue description is wrong but what is described below.可能是我的问题描述是错误的,但如下所述。 I need solution in pyspark.我需要 pyspark 中的解决方案。

I have 2 data frames我有 2 个数据框

Df1
A B C
1 2 3
5 6 7
8 9 1
6 2 3

Df2
D E
a b
c d
e f

I want final dataframe as below我想要最终的 dataframe 如下

A B C D E
1 2 3 a b
1 2 3 c d
1 2 3 e f
5 6 7 a b
5 6 7 c d
5 6 7 e f
8 9 1 a b
8 9 1 c d
8 9 1 e f
6 2 3 a b
6 2 3 c d
6 2 3 e f

Basically new dataframe will be for each row for DF1 will repeat for each row of DF2.基本上新的 dataframe 将针对 DF1 的每一行将针对 DF2 的每一行重复。 Final count would be: count(Df1) * count(Df2)最终计数为: count(Df1) * count(Df2)

Please help, I am new to pysaprk.请帮忙,我是pysaprk的新手。

You can use crossJoin , which is df.crossJoin(df2) .您可以使用crossJoin ,即df.crossJoin(df2) You can check this https://spark.apache.org/docs/3.1.1/api/python/reference/api/pyspark.sql.DataFrame.crossJoin.html . You can check this https://spark.apache.org/docs/3.1.1/api/python/reference/api/pyspark.sql.DataFrame.crossJoin.html .

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将一个数据帧的列值附加到另一个数据帧的列 - How to append column values of one dataframe to column of another dataframe 如何从一个数据框中的列中提取特定值并将它们附加到另一个数据框中的列中? - 熊猫 - How do you extract specific values from a column in one dataframe and append them to a column in another dataframe? - Pandas pandas数据框根据另一数据框中的值将值追加到一列 - pandas dataframe append values to one column based on the values in another dataframe 我如何根据列单元格值和 append 查找一个 dataframe 上的一行到另一个 dataframe 上的一行? - How do i lookup a row on one dataframe based on the column cell value and append that to a row on another dataframe? 如何基于另一列将 append 数据转换为 dataframe? - How to append data to dataframe based on another column? 熊猫-如何将数据帧的转置作为列标题附加到另一个数据帧? - Pandas- How to append a transpose of dataframe to another dataframe as column headers? 如何将 append 列转换为 DataFrame 以收集 Python 中另一个 DataFrame 的值? - How to append a column to a DataFrame that collects values of another DataFrame in Python? 将数据框附加到另一个数据框的列和Python常量 - Append a dataframe with a column of another dataframe and a constant with Python Append 单列 dataframe 到最后一个 DataFrame - Append a single Column dataframe to another DataFrame in the last 列名称不同时如何将数据框追加到另一个(具有相同列大小) - How to append a dataframe to another one (with the same column size) when the column names are different
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM