I have a df data frame with columns "col1" and "col2". I want to create a third column that uses one of the columns, as in the exponent function.
df = df.withColumn("col3", 100**(df("col1")))*df("col2")
However, this always leads to:
TypeError: unsupported operand type for ** or pow (): 'float' and 'Column'
I understand that this is due to the fact that the function takes df ("col1") as a "column" instead of an element in this row.
If I do
results = df.map(lambda x : 100**(df("col2"))*df("col2"))
this works, but I cannot add to the original data frame.
Any thoughts?
This is my first post, so I apologize for any formatting issues.
source
share