读取文件火花,将具有特定值的字段设置为空或“"; [英] Read File spark, set field having specific value to null or ""
本文介绍了读取文件火花,将具有特定值的字段设置为空或“";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在阅读以 | 分隔的文本文件.有一些字段具有值 \N .当逐行读取文件到数据帧时,是否有任何方法可以使具有值 \N 的字段为 null 或 "" .代码如下.
I'm Reading a text file delimited with | . There are some fields having value \N . When read the file row by row to a data-frame, is there any way to make the field having value \N to null or "" . Code is given below.
val inputDf = sqlContext.read.format("csv")
.option("header", "true")
.option("inferSchema", "false")
.schema(myschema)
.option("delimiter", "|")
.option("nullValue", "")
.load("My Input file Path")
推荐答案
"DataFrameNaFunctions" 可用于将所有列中的值 "\N" 替换为 "":
"DataFrameNaFunctions" can be used for replace value "\N" in all columns with "":
df.na.replace(df.columns.toSeq, Map("\\N" -> ""))
这篇关于读取文件火花,将具有特定值的字段设置为空或“";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文