你可以
groupby上
Column1再取
Column3来
apply(list)和呼叫
to_dict?
In [81]: df.groupby('Column1')['Column3'].apply(list).to_dict()Out[81]: {0: [1], 1: [2, 3, 5], 2: [1, 2], 3: [4, 5], 4: [1], 5: [1, 2, 3]}
或者,做
In [433]: {k: list(v) for k, v in df.groupby('Column1')['Column3']}Out[433]: {0: [1], 1: [2, 3, 5], 2: [1, 2], 3: [4, 5], 4: [1], 5: [1, 2, 3]}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)