Skip to content
Advertisement

PySpark sum all the values of Map column into a new column

I have a dataframe which looks like this

JavaScript

I want to sum of all the row wise decimal values and store into a new column

JavaScript

My approach

JavaScript

This is not working as it says, it can be applied only to int

Advertisement

Answer

JavaScript

Since, your values are of float type, the initial value passed within the aggregate should match the type of the values in the array. So, casting the initial 0 to double instead of using 0 should work fine.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement