与其他列的组合我有熊猫DF没有。在大熊猫DF
id_x id_y
a b
b c
c d
d a
b a
and so on around (1000 rows)
我想找到与id_y每个id_x组合的计数表。
即。一个具有a-b,d-a(total 2 combinations)
同样B级组合已总2 combinations(b-c) and also a-b to be considered as a combination for b(a-b = b-a)
并创建一个数据帧DF2具有
id combinations
a 2
b 2
c 2 #(c-d and b-c)
d 1
and so on ..(distinct product_id_'s)
我试图这样做代码
df.groupby(['id_x']).size().reset_index()
但得到错误的结果;
id_x 0
0 a 1
1 b 1
2 c 1
3 d 1
我应该遵循什么方法?我的python技能在初学者水平。 在此先感谢。
@jezrael这是我的问题 – Shubham