How can I create a UDF to programatically replace null values in a spark dataframe in each column with the column mean value. for instance in the example data col1 null value will have a value of ((2+4+6+8+5)/5) = 5.
Example data:
col1 col2 col3
2 null 3
4 3 3
6 5 null
8 null 2
null 6 4
5 2 8
Desired Data:
col1 col2 col3
2 4 3
4 3 3
6 5 4
8 4 2
5 6 4
5 2 8