I have the below dataframe and I need to subtract and find the delta between next quater and current quater plus next to next quater and current quater.
Input data:
Number Name Year Quater value
1 an 2018 1 2.5
2 bn 2018 1 1.5
1 an 2018 2 3.5
2 bn 2018 2 4.5
1 an 2018 3 4.5
1 an 2018 4 2.5
2 bn 2018 4 1.5
1 an 2019 1 5.5
2 bn 2019 1 1.5
Output: d_1
is the difference between next quater and current quater for same number and name, whereas d_2
is the diff between next to next quater and current quater for same number and name.
Number Name Year Quater value d_1 d_2
1 an 2018 1 2.5 1 2
2 bn 2018 1 1.5 3
1 an 2018 2 3.5 1 -1
2 bn 2018 2 4.5 -3
1 an 2018 3 4.5 -2 1
1 an 2018 4 2.5 3
2 bn 2018 4 1.5 0
1 an 2019 1 5.5
2 bn 2019 1 1.5