【发布时间】:2020-03-08 16:41:18
【问题描述】:
我正在尝试从 Excel 中计算一列的平均值。 我删除了名为“TFD”的列中的所有空值和“-”,并通过选择三列来形成一个新的数据框。我想用 groupby 计算新数据帧的平均值。但是有一个名为“没有要聚合的数字类型”的错误,我不知道为什么会出现这个错误以及如何修复它。
sheet=pd.read_excel(file)
sheet_copy=sheet
sheet_copy=sheet_copy[(~sheet_copy['TFD'].isin(['-']))&(~sheet_copy['TFD'].isnull())]
sheet_copy=sheet_copy[['Participant ID','Paragraph','TFD']]
means=sheet_copy['TFD'].groupby([sheet_copy['Participant ID'],sheet_copy['Paragraph']]).mean()
【问题讨论】: