Pandas12——excel求和求平均数

excel示例
import pandas as pd
data=pd.read_excel("D:\\python_pandas\\sample\\demo15\\Students.xlsx")

part01 = data[["Test_1","Test_2","Test_3"]]
sum= part01.sum(axis=1)
# aver= part01.mean(axis=1).apply(lambda x:round(x , 2))
aver= part01.mean(axis=1)
data["Total"] = sum
data["average"] = aver
summary = data[["Test_1","Test_2","Test_3","Total","average"]].sum()
data = data.append(summary,ignore_index=True)
print(data)
输出结果:
      ID         Name  Test_1  Test_2  Test_3   Total      average
0    1.0  Student_001    62.0    86.0    83.0   231.0    77.000000
1    2.0  Student_002    77.0    97.0    78.0   252.0    84.000000
2    3.0  Student_003    57.0    96.0    46.0   199.0    66.333333
3    4.0  Student_004    57.0    87.0    80.0   224.0    74.666667
4    5.0  Student_005    95.0    59.0    87.0   241.0    80.333333
5    6.0  Student_006    56.0    97.0    61.0   214.0    71.333333
6    7.0  Student_007    64.0    91.0    67.0   222.0    74.000000
7    8.0  Student_008    96.0    70.0    48.0   214.0    71.333333
8    9.0  Student_009    77.0    73.0    48.0   198.0    66.000000
9   10.0  Student_010    90.0    94.0    67.0   251.0    83.666667
10  11.0  Student_011    62.0    55.0    63.0   180.0    60.000000
11  12.0  Student_012    83.0    76.0    81.0   240.0    80.000000
12  13.0  Student_013    68.0    60.0    90.0   218.0    72.666667
13  14.0  Student_014    82.0    68.0    98.0   248.0    82.666667
14  15.0  Student_015    61.0    67.0    91.0   219.0    73.000000
15  16.0  Student_016    59.0    63.0    46.0   168.0    56.000000
16  17.0  Student_017    62.0    83.0    93.0   238.0    79.333333
17  18.0  Student_018    90.0    75.0    80.0   245.0    81.666667
18  19.0  Student_019   100.0    95.0    55.0   250.0    83.333333
19  20.0  Student_020    61.0    87.0   100.0   248.0    82.666667
20   NaN          NaN  1459.0  1579.0  1462.0  4500.0  1500.000000

pandas常用的数学统计方法

pandas常用的数学统计方法

你可能感兴趣的:(Pandas12——excel求和求平均数)