Skip to content
Advertisement

How to add a row for subtotal from each group and then a final row of grand total of entries

I have the following dataframe:

Location Student Name
D Amy
D Raj
E Mitch
F Poo
F Mack

I am trying to generate the following dataframe:

Location Student Name
D Amy
D Raj
Total Students at D 2
E Mitch
Total Students at E 1
F Poo
F Mack
Total Students at F 2
Grand Total 5

How do I do that?

Advertisement

Answer

I will offer a solution without loops.

JavaScript

Output :

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement