程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Pandas sum, average, statistics

編輯:Python

There is such a watch :

Sum up , Averaging :

  1. import pandas as pd
  2. student = pd.read_excel("C:/Users/Administrator/Desktop/Students.xlsx",index_col="ID")
  3. temp = student[["Test_1","Test_2","Test_3"]]
  4. student["total"] = temp.sum(axis=1)#axis 0 Column ,1 For the line
  5. student["avg"] = temp.mean(axis=1)
  6. print(student)

Calculate the average score of each subject , Sum up :

  1. col_mean = student[["Test_1","Test_2","Test_3","total","avg"]].mean()
  2. col_mean["Name"]="Summary"
  3. student = student.append(col_mean,ignore_index=True)
  4. student[["Test_1","Test_2","Test_3","total","avg"]] = student[["Test_1","Test_2","Test_3","total","avg"]].astype(int)
  5. print(student)

append You can add a line directly

DataFrame.append(other, ignore_index=False, verify_integrity=False, sort=None)

Refer to the official website


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved