如何在pyspark中删除空值超过x的行
在我的数据帧中删除大于空值的na_阈值的行时遇到一些问题如何在pyspark中删除空值超过x的行,pyspark,null,Pyspark,Null,在我的数据帧中删除大于空值的na_阈值的行时遇到一些问题 na_threshold=2 df3=df3.dropna(thresh=len(df3.columns) - na_threshold) 当我跑的时候 df_null = df3.where(reduce(lambda x, y: x | y, (f.col(x).isNull() for x in df3.columns))) df_null是一个数据帧条目,有一行,其中只有一列的值为null 我尝试过增加na_阈值,但没有效果
na_threshold=2
df3=df3.dropna(thresh=len(df3.columns) - na_threshold)
当我跑的时候
df_null = df3.where(reduce(lambda x, y: x | y, (f.col(x).isNull() for x in df3.columns)))
df_null是一个数据帧条目,有一行,其中只有一列的值为null
我尝试过增加na_阈值,但没有效果。我意识到drop.na函数确实有效 发生的事情是,文件最初是用Pandas读入的,我在将其他类似Null的值转换为Null之前使用了drop na函数,因为Pandas使用nan、NaT,有时使用“-”
for column in columns:
df3 = df3.withColumn(column,when((col(column)=='nan'),None).otherwise(F.col(column)))
df3 = df3.withColumn(column,when((col(column)=='NaT'),None).otherwise(F.col(column)))
df3 = df3.withColumn(column,when((col(column)=='-'),None).otherwise(F.col(column)))
na_threshold=2
df3=df3.dropna(thresh=len(df3.columns) - na_threshold)```