Replace empty strings with None/null values in DataFrame

后端 未结 5 1527
野趣味
野趣味 2020-12-13 10:01

I have a Spark 1.5.0 DataFrame with a mix of null and empty strings in the same column. I want to convert all empty strings in all columns to null

5条回答
  •  北海茫月
    2020-12-13 10:35

    UDFs are not terribly efficient. The correct way to do this using a built-in method is:

    df = df.withColumn('myCol', when(col('myCol') == '', None).otherwise(col('myCol')))
    

提交回复
热议问题