我想根據特定的分隔符分解字串列(在我的例子中是 |)我有一個這樣的資料集:
----- --------------
|Col_1|Col_2 |
----- --------------
| 1 | aa|bb |
| 2 | cc |
| 3 | dd|ee |
| 4 | ff |
----- ----- ---------
我想要這樣的輸出:
----- --------------
|Col_1|Col_2 |
----- --------------
| 1 | aa |
| 1 | bb |
| 2 | cc |
| 3 | dd |
| 3 | ee |
| 4 | ff |
----- ----- ---------
uj5u.com熱心網友回復:
使用explodeandsplit函式,并使用 \\ escape |。
val df1 = df.select(col("Col_1"), explode(split(col("Col_2"),"\\|")).as("Col_2"))
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/465524.html
