My data is as below
| Sec | issues | Gaps |
|---|---|---|
| AAA | 22 | 5 |
| BBB | 33 | 2 |
| CCC | 44 | 1 |
Desired result
| Sec | issues | Gaps |
|---|---|---|
| AAA | 22 | 5 |
| BBB | 33 | 2 |
| CCC | 44 | 1 |
| TOTAL | 99 | 8 |
I try below code
df.append(df.sum(numeric_only=True), ignore_index=True)
but with this I miss sector name and simply get totals at end, I want sector name and totals both
df.loc[len(df)]=['Total', *df.iloc[:,1:].sum()](related answer)pd.__version__in the body of your question. If you usedf.append, which is deprecated since version 1.4.0, then answers will have to fit your version. Alternatively, update and use Good alternative to Pandas .append() method, now that it is being deprecated?