java 将Spark Dataframe 的一列转换为小写

wwwo4jvm  于 2023-02-28  发布在  Java
关注(0)|答案(1)|浏览(160)

如何在Java中将Spark dataframe中的列值转换为小写/大写?
例如,下面是输入 Dataframe :

name | country | src        | city       | debit
---------------------------------------------
"foo"| "NZ"    | salary     | "Auckland" | 15.0
"bar"| "Aus"   | investment | "Melbourne"| 12.5

我需要将“city”列转换为小写

name | country | src        | city       | debit
------------------------------------------------
"foo"| "NZ"    | salary     | "auckland" | 15.0
"bar"| "Aus"   | investment | "melbourne"| 12.5

我在Scala和Python中找到了解决方案,但在Java中没有,如下所示
How to change case of whole column to lowercase?
在java中有一个转换列名的解决方案,但不转换它的数据。
How to lower the case of column names of a data frame but not its values?
如何将列值转换为小写?

2izufjch

2izufjch1#

以防有人在寻找答案。下面是根据@blackbishop的建议提出的解决方案

import static org.apache.spark.sql.functions.lower; 
df=df.withColumn("city", lower(df.col("city")))

相关问题