如何用火花中的其他值替换数组中的项目?
How to replace item in array with other values in spark?
+--------------------------------+
|Subject |
+--------------------------------+
|[English, Math, Science, Spark] |
+--------------------------------+
|[English, History, Art] |
+--------------------------------+
如何在两行中用 ENGLISH 替换英文?
使用自定义 UDF 替换单词:
val replace = udf{ x: Seq[String] => x.map(y => if(y == "English") "ENGLISH" else y) }
val df2 = df.select(replace($"Subject").alias("Subject"))
df2.show(false)
+-------------------------------+
|Subject |
+-------------------------------+
|[ENGLISH, Math, Science, Spark]|
|[ENGLISH, History, Art] |
+-------------------------------+
+--------------------------------+
|Subject |
+--------------------------------+
|[English, Math, Science, Spark] |
+--------------------------------+
|[English, History, Art] |
+--------------------------------+
如何在两行中用 ENGLISH 替换英文?
使用自定义 UDF 替换单词:
val replace = udf{ x: Seq[String] => x.map(y => if(y == "English") "ENGLISH" else y) }
val df2 = df.select(replace($"Subject").alias("Subject"))
df2.show(false)
+-------------------------------+
|Subject |
+-------------------------------+
|[ENGLISH, Math, Science, Spark]|
|[ENGLISH, History, Art] |
+-------------------------------+