i am new in Pyspark and I have some doubts.
I have a df like this:
+---+---+-------+
| a1| a2|formula|
+---+---+-------+
| 18| 12| a1+a2|
| 11| 1| a1-a2|
+---+---+-------+
I'm trying to parse the column 'formula' to create a new column with the formula resolved and obtain a df like this
+---+---+-------+----------------+
| a1| a2|formula|resolved_formula|
+---+---+-------+----------------+
| 18| 12| a1+a2| 30|
| 11| 1| a1-a2| 10|
+---+---+-------+----------------+
I have tried using
df2 = df.withColumn('resolved_formula', f.expr(df.formula))
df2.show()
but i'm obtaining this type error
TypeError: Column is not iterable
can someone help me?
Thank you very much!!