I would like to calculate the difference amount of total_spent for each customer_id by taking the difference for each two column pairs. In this case subtracting total_spent_2020 from total_spent_2021 but in a more dynamic way. In numbers it would be substracting: column_3 from column_2 and column_5 from column_4 and so on.
I was thinking of taking the length of the df and add a range with a 2 interval but I am struggling to do the subtraction based on that interval number.
sample_df
customer_id total_spent_2021 total_spent_2020 total_spent_2019 total_spent_2018
9391 120 100 80 90
2932 90 110 60 50
4294 150 130 40 50
ouput_df
customer_id total_spent_2021_2020_diff total_spent_2019_2018_diff
9391 20 -10
2932 -20 10
4294 20 -10