使用pandas写入excel表。 在总结两栏和新增栏目方面

我正试图在我的excel表上总结两列。 当我打印DF。[总]的值是正确的。 但不会在Excel电子表格中写入新列。 我怎么能这样做?

这里是我的Excel表单包括:

Jan |Feb 10000 |62000 95000 |45000 91000 |120000 45000 |120000 162000 |120000 

目标:将这两个值相加并写出所得总和的新和列。 并得到我的Excel电子表格:

 Jan |Feb |Sums 10000 |62000| 72000 95000 |45000|140000 91000 |120000 |211000 45000 |120000 | 165000 162000 |120000 | 282000 

这是我的代码:

 import pandas as pd import numpy as np from pandas import ExcelWriter df = pd.read_excel("samplesheet.xlsx") df["total"] = df["Jan"] + df["Feb"] df.head() #print(df["total"]) df_total = df["total"] print(df_total) df_total = pd.DataFrame(df_total) writer = ExcelWriter('samplesheet.xlsx') df_total.to_excel(writer,'Sheet1') writer.save() 

在打印df [“total”]后,结果是:72000,140000,211000,165000,282000。正如你所看到的,总结实际上是工作,但我不知道写一个新的列到excel表中列名称为“总和“与具体的行有关的总和。

谢谢