Spark处理DataFrame中的空字符串
在Spark2.x 中 Dataframe.na.drop()
似乎只对Null
值有效,对空字符串''
没有处理。
需求:把空字符串转成 N/A
- re正则表达式:
df.withColumn("Col_Name", regexp_replace(col("Col_Name"), "", "N/A"))
- withColumn + when-otherwise
df.withColumn("Col_Name", when($"Col_Name" === "", lit("N/A")).otherwise($"Col_Name"))
敬请斧正 😃