I have below mentioned dataframe:
Month Val1 Val2 Part1 Part2
Feb-17 250 10000 25 100
A 25 2000 5 20
B 25 2000 5 20
C 100 2000 5 20
D 10 2000 5 20
E 40 2000 5 20
Jan-17 200 8000 50 100
A 20 1000 10 20
B 40 1600 10 20
C 100 1600 10 20
D 20 1600 10 20
E 20 2200 10 20
I want to add two columns Per_1
after Val1
and Per_2
after Val2
. Which compare Feb-17 Data with Jan-17 Data and give growth percentage (increase or decrease).
Note: For A,B,C,D and E the sequence would be differ in Feb-17 and Jan-17, here i want to calculate growth of Feb-17 A with Jan-17 A and respectively.
In case of Jan-17, since there are no Data in last month to compare with in dataframe, the Per_1
and Per_2
should be 0.00%
in that case.
Required Output:
Month Val1 Per_1 Val2 Per_2 Part1 Part2
Feb-17 250 25.00% 10000 25.00% 25 100
A 25 25.00% 2000 100.00% 5 20
B 25 -37.50% 2000 25.00% 5 20
C 100 0.00% 2000 25.00% 5 20
D 10 -50.00% 2000 25.00% 5 20
E 40 100.00% 2000 -9.09% 5 20
Jan-17 200 0.00% 8000 0.00% 50 100
C 100 0.00% 1600 0.00% 10 20
A 20 0.00% 1000 0.00% 10 20
B 40 0.00% 1600 0.00% 10 20
E 20 0.00% 2200 0.00% 10 20
D 20 0.00% 1600 0.00% 10 20