Appending column totals to a Pandas DataFrame
I have a DataFrame with numerical values. What is the simplest way of appending a row (with a given index value) that represents the sum of each column?
To add a Total
column which is the sum across the row:
df['Total'] = df.sum(axis=1)
To add a row with column-totals:
df.loc['Total']= df.sum()