+--------------------+-------------------+------------+
| name | 1990|1991 |
+--------------------+-------------------+------------+
|abc |100 | 300 |
|bbc |200 | 400 |
|cbc |300 | 500 |
|xyz |700 | 500 |
|xzz |200 | 500 |
Above is a dataframe in pyspark. I would like to convert this to a pivoted table and calculate a rolling summation. Is there a way to convert the columns to row on the name? Belo sis the expected result which is basically summation of previous 2 years. How can we accomplish this?
+--------------------+-------------------+------------+
| year | abc |bbc |
+--------------------+-------------------+------------+
|1990 |100 | 300 |
|1991 |100+200 | 400+300 |