I am trying to find the difference between every two columns in a pyspark dataframe with 100+ columns. If it was less, I could manually create a new column each time by doing df.withColumn('delta', df.col1 - df.col2) but I am trying to do this in a more concise way. Any ideas?
| col1 | col2 | col3 | col4 |
|---|---|---|---|
| 1 | 5 | 3 | 9 |
Wanted output:
| delta1 | delta2 |
|---|---|
| 4 | 6 |