I don't understand how this could be fixed, I went through on some of the questions here already, but didn't find a perfectly fitting answer.
I have a dataframe which has the following important columns: building_id, area, height.
The UDF I tried to write calculates a difference between the square root of the area and the height. It returns a value, which should be added to the dataframe.
def calculate_difference(area, height):
# calculate the square root of the area
import numpy as np
nr = np.sqrt(area)
# calculate the difference between the square root of the area and the height
dif = nr - height
return dif
And then I register this UDF:
calculate_differenceUDF = udf(calculate_difference)
The function works when I pass two numbers, it returns the value I expect. I want to add a new column to my dataframe, where we have a calculated value, based on the function.
display(df.withColumn("diff", calculate_differenceUDF(col("area"), col("height"))))
Then I receive this error:
PickleException: expected zero arguments for construction of ClassDict (for numpy.dtype)
I understand that I don't return maybe a correct type, but I don't see how to fix it! :)