How to convert empty arrays to nulls?

后端 未结 7 455
Happy的楠姐
Happy的楠姐 2021-01-13 18:28

I have below dataframe and i need to convert empty arrays to null.

+----+---------+-----------+
|  id|count(AS)|count(asdr)|
+----+---------+-----------+
|11         


        
7条回答
  •  生来不讨喜
    2021-01-13 19:12

    you can do it with selectExpr:

    df_filled = df.selectExpr(
        "id",
        "if(size(column1)<=0, null, column1)",
        "if(size(column2)<=0, null, column2)",
        ...
    )
    

提交回复
热议问题