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]
感谢。
答案 0 :(得分:2)
将groupby
与apply
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)
}