[英]how to group by multiindex in pandas
I have this kind of pandas table我有这种 pandas 表
user_id is_win behave trade_count
0 279 0 0 1
1 279 0 1 1
2 279 1 1 1
3 279 0 0 1
4 279 1 0 1
how to change this table into this form to sum up the last column怎么把这个表改成这个表格来总结最后一列
user_id is_win behave trade_count
279 0 0 1
1 1
1 0 2
1 1
Thanks谢谢
Try this:尝试这个:
df2 = df.groupby(['user_id', 'is_win', 'behave'])['trade_count'].agg('sum').reset_index()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.