我需要将数据帧值添加到指定列中的每个不同值
例如
df1:
Patterns.PHONE.matcher(phone).matches();
df2:
+----+----+
|col1|col2|
+----+----+
| A| 100|
| B| 70|
| C| 50|
+----+----+
生成的df应该如下所示:
+----+----+
|col3|col4|
+----+----+
|jose| 1|
| li| 2|
| liz| 3|
+----+----+
答案 0 :(得分:2)
您实际上要求的是crossJoin
-
df = df1.crossJoin(df2)
df.show()
+----+----+----+----+
|col1|col2|col3|col4|
+----+----+----+----+
| A| 100|jose| 1|
| A| 100| li| 2|
| A| 100| liz| 3|
| B| 70|jose| 1|
| B| 70| li| 2|
| B| 70| liz| 3|
| C| 50|jose| 1|
| C| 50| li| 2|
| C| 50| liz| 3|
+----+----+----+----+