求和,求平均数

 1 import pandas
 2 excel=pandas.read_excel(r'F:\pandas练习\成绩.xlsx',index_col='id',sheet_name='Sheet1')
 3 temp=excel[['score1','score2']]
 4 
 5 row_sum=temp.sum(axis=1)   #默认axis=0,对每一列进行求和
 6 row_mean=temp.mean(axis=1)
 7 
 8 excel['total']=row_sum
 9 excel['average']=row_mean
10 
11 col_mean=excel[['score1','score2','total','average']].mean()  #对每一列进行求平均值
12 col_mean['name']='summary'
13 excel=excel.append(col_mean,ignore_index=True)   #在excel表的最后再增加一行
14 print(excel)

 

上一篇:cv


下一篇:pytorch(六)一些训练技巧