如何将数据框的列分组到pandas中列出?

时间:2017-06-16 07:15:14

标签: pandas

   member_srl  click_day  productid
0        6963   20170106    3927352
1        6963   20170106    3790726
2        6963   20170106     977962
3        6963   20170106    1393860
4        6963   20170106    3759353

这是我的df,我想将member_srl和click_day分组,以获取productid列表。例如,member_srl 6963和click_day 20170106将对应于产品列表:[3927352,3790726,977962,1393860,3759353]

感谢。

1 个答案:

答案 0 :(得分:2)

groupbyapply df = df.groupby(['member_srl','click_day'])['productid'].apply(list) print (df) member_srl click_day 6963 20170106 [3927352, 3790726, 977962, 1393860, 3759353] Name: productid, dtype: object df = df.groupby(['member_srl','click_day'])['productid'].apply(list).reset_index() print (df) member_srl click_day productid 0 6963 20170106 [3927352, 3790726, 977962, 1393860, 3759353]

一起使用
someFunction(foo, bar) match {
  case (two, three) => someOtherFunction(one, two, three)
}