Read File spark, set field having specific value to null or “”

前端 未结 2 571
[愿得一人]
[愿得一人] 2021-01-17 04:15

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

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-17 04:26

    Once you load the dataframe use the when condition on all the columns in generic way

    inputDf.select(inputDf.columns.map(c=> when(col(c) === “\\N”,””).otherwise(col(c)).alias(c)):_*).show
    

提交回复
热议问题