I have a Pandas data frame, as shown below, with multiple columns and would like to get the total of column, MyColumn
.
X MyColumn Y Z
0 A 84 13.0 69.0
1 B 76 77.0 127.0
2 C 28 69.0 16.0
3 D 28 28.0 31.0
4 E 19 20.0 85.0
5 F 84 193.0 70.0
Expected Output
I'd have expected the output to be the total of this column: 319
.
Or alternatively, I would like df
to be edited with a new row entitled TOTAL
containing the total:
X MyColumn Y Z
0 A 84 13.0 69.0
1 B 76 77.0 127.0
2 C 28 69.0 16.0
3 D 28 28.0 31.0
4 E 19 20.0 85.0
5 F 84 193.0 70.0
TOTAL 319
I have attempted to get the sum of the column using groupby
and .sum()
:
Total = df.groupby['MyColumn'].sum()
This causes the following error:
TypeError: 'instancemethod' object has no attribute '__getitem__'