这是因为“类似属性”的列访问不适用于整数列名。使用标准索引:
In [122]: ct["Total"] = ct[0] + ct[1]In [123]: ctOut[123]:B 0 1 TotalA0 26 24 501 30 20 50
请参阅文档本节末尾的警告:http : //pandas.pydata.org/pandas-
docs/stable/indexing.html#attribute-access
当您要使用行时,可以使用
.loc:
In [126]: ct.loc["Total"] = ct.loc[0] + ct.loc[1]
在这种情况下
ct.loc["Total"]相当于
ct.loc["Total", :]



