分组统计-小笔记

df['state'] = 0
df.loc[df['tiqian'] <= 4, 'state']= 1
pd.pivot_table(df, values='state', index=['tuandui'], aggfunc=[np.size, np.sum])

y = df.groupby(['tuandui']).size()
x = df[df['state'] == 1].groupby(df['tuandui']).size()
pre = x / y
dff = pd.DataFrame(pre, columns=['no1'])

你可能感兴趣的:(分组统计-小笔记)