groupby = df.groupby('id')
# 遍历
for id,group in groupby:
print(id)
print(group)
# 取其中一组
data = groupby.get_group('aaa')
df_groupby = df.groupby('id')['salary'].sum()
df_groupby = df.groupby(['id','gender'])['salary'].sum()
mean, min, max, count, std,
https://www.cnblogs.com/Yanjy-OnlyOne/p/11217802.html
df_groupby = df.groupby('id')['salary'].agg(['max','min','std'])
效果:各类别高于3倍标准差为1,否则为0
def handle_abnormal(df, shred=3):
df_temp = df[df>(df.mean()+ shred *df.std())]
if not df_temp.empty:
return 1
else:
return 0
df_beh_abnormal = df_beh_date.groupby('id')['count'].apply(handle_abnormal)