如何减少数据框的列名而不是其值的大小写? [英] 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
taget数据框
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屋!
查看全文