我有以下pyspark dataframe:
df
col1 col2 col3
1 2 3
4 None 6
7 8 None
我想用它们所在行的平均值替换None(或Null)值。输出将如下所示:
df_result
col1 col2 col3
1 2 3
4 5 6
7 8 7.5
我尝试的所有操作都会导致错误“Column is not iterable”或“Invalid argument,not a string or column”。非常感谢您的帮助!
3条答案
按热度按时间oaxa6hgo1#
mapinPandas
轻松解决结果
col17t5w2#
Using only spark-in built functions:
尝试使用**
Higher order array (aggregate)
函数,计算数组中non null elements(using lambda functions)
的个数。然后计算
mean of the elements
。最后,
divide
和replace the nulls(case + when statement)
**具有平均值。Example:
k10s72fa3#
试试这个: