如何降低数据框列名的大小写而不是其值? [英] How to lower the case of column names of a data frame but not its values?
本文介绍了如何降低数据框列名的大小写而不是其值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何降低数据框列名的大小写而不是其值?使用 RAW Spark SQL 和 Dataframe 方法?
How to lower the case of column names of a data frame but not its values? using RAW Spark SQL and Dataframe methods ?
输入数据框(假设我有 100 个大写的这些列)
Input data frame (Imagine I have 100's of these columns in uppercase)
NAME | COUNTRY | SRC | CITY | DEBIT
---------------------------------------------
"foo"| "NZ" | salary | "Auckland" | 15.0
"bar"| "Aus" | investment | "Melbourne"| 12.5
目标数据框
name | country | src | city | debit
------------------------------------------------
"foo"| "NZ" | salary | "Auckland" | 15.0
"bar"| "Aus" | investment | "Melbourne"| 12.5
推荐答案
Java 8
将列名转换为小写的解决方案.
Java 8
solution to convert the column names to lower case.
import static org.apache.spark.sql.functions.col;
import org.apache.spark.sql.Column;
df.select(Arrays.asList(df.columns()).stream().map(x -> col(x).as(x.toLowerCase())).toArray(size -> new Column[size])).show(false);
这篇关于如何降低数据框列名的大小写而不是其值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文