|
试试用pandas,如
In [3]: df
Out[3]:
a b c d
0 1 2 6 5
1 2 3 7 9
2 3 4 8 1
df['row_sum']=df.sum(axis=1)
df=df.append(df[['a','b','c','d']].sum(),ignore_index=True)
df.iloc[3,4]=df.iloc[3,].sum()
df.rename({3:'Totle'})
结果
a b c d row_sum
0 1.0 2.0 6.0 5.0 14.0
1 2.0 3.0 7.0 9.0 21.0
2 3.0 4.0 8.0 1.0 16.0
Totle 6.0 9.0 21.0 15.0 51.0
|
|