python—如何创建每行的重复值,然后插入新的Dataframe?

ljo96ir5  于 2021-07-13  发布在  Spark
关注(0)|答案(1)|浏览(328)



如何复制原始dataframe的每一行,然后添加dataframe2,这样我的最终输出是:我正在pyspark dataframe中用python编写这个。

drnojrws

drnojrws1#

您需要的是交叉连接:

result = df1.crossJoin(df2)

result.show()

# +------+--------+------+-------+------------+-----------------+

# |  name| address|salary|bonus %|allowances %|employee category|

# +------+--------+------+-------+------------+-----------------+

# |   Tom| Chicago| 75000|      5|           5|           onsite|

# |   Tom| Chicago| 75000|     10|          10|        off shore|

# |Martha|New york| 80000|      5|           5|           onsite|

# |Martha|New york| 80000|     10|          10|        off shore|

# |Samuel| Phoenix| 90000|      5|           5|           onsite|

# |Samuel| Phoenix| 90000|     10|          10|        off shore|

# |   Rom|  Dallas| 65000|      5|           5|           onsite|

# |   Rom|  Dallas| 65000|     10|          10|        off shore|

# +------+--------+------+-------+------------+-----------------+

相关问题