largeQ
这应该这样做:import numpy as npimport pandas as pd# create dummy dataids = [1,1,1,1,2,2,2,2,2,3,3,3,3,4,4,4,4]values = [13,21,34,22,34,2,3,34,12,45,45,23,67,76,32,23,80]df = pd.DataFrame({'ID': ids, 'Values': values})df = df.groupby('ID').agg({'Values': [min, max, np.mean]}) # group by on ID and calculate new columns min, max, mean for the values columnsdf.columns = df.columns.droplevel(0) # get rid of the multilevel columns due to the groupingdf.reset_index()编辑:感谢 ALollz 指出以下快捷方式(避免多级索引):df = df.groupby('ID')['Values'].agg([min, max, np.mean]) # group by on ID and calculate new columns min, max, mean for the values columnsdf.reset_index()让我知道是否有任何步骤需要详细说明。