I have a df like this:
Index Parameters A B C D E 1 Apple 1 2 3 4 5 2 Banana 2 4 5 3 5 3 Potato 3 5 3 2 1 4 Tomato 1 1 1 1 1 5 Pear 4 5 5 4 3 I want to add all the rows which has Parameter values as "Apple" , "Banana" and "Pear".
Output:
Index Parameters A B C D E 1 Apple 1 2 3 4 5 2 Banana 2 4 5 3 5 3 Potato 3 5 3 2 1 4 Tomato 1 1 1 1 1 5 Pear 4 5 5 4 3 6 Total 7 11 13 11 13 My Effort:
df[:,'Total'] = df.sum(axis=1)-- Works but I want specific values only and not all- Tried by the index in my case
1,2 and 5but in my original df the index can vary from time to time and hence rejected that solution.
Saw various answers on SO but none of them could solve my problem!!