2024-09-28 22:25:05 发布
网友
使用df.withColomn{}和otherwise(***empty_array***)时,如何添加空数组 新的列类型是来自UDF的T.ArrayType(T.StringType())
df.withColomn
otherwise(***empty_array***)
T.ArrayType(T.StringType())
我希望避免以NaN值结束
只需使用array(lit(None))
array(lit(None))
df.select(when(col('target_bool')=='true',array(lit(1))).otherwise(array(lit(None)))).show()
尝试以下操作-创建一个无值列并强制转换为数组()
df_b = df_b.withColumn("empty_array", F.when(F.col("rn") == F.lit("1"), (None))).withColumn("empty_array", F.col("empty_array").cast(T.ArrayType(T.StringType()))) df_b.show() root | col1: string (nullable = true) | col2: string (nullable = true) | rn: integer (nullable = true) | case_condition: integer (nullable = true) | empty_array: array (nullable = true) | | element: string (containsNull = true)
只需使用
array(lit(None))
尝试以下操作-创建一个无值列并强制转换为数组()
相关问题 更多 >
编程相关推荐