pandas取出均值后重命名——reset_index()
1、源数据
2.取出差值的均值并重命名
3.结果展示
4.代码
import pandas as pd
inputfile = 'C:/Users/An/Desktop/……/源数据.xlsx'
outputfile = 'C:/Users/An/Desktop/……/result2.xlsx'
data = pd.read_excel(inputfile,sheet_name = '数据查询')
ga = data.groupby('姓名')['差值'].mean().reset_index()
ga.columns = ['姓名','个人均值']
print(ga)
ga.to_excel(outputfile)
5.不加reset_index()的结果如下: