为了避免重复同一个用户,我希望使用pandas {k: artist1, artist2, artist3, etc}
函数巧妙地组织groupby
的嵌套字典。这是样本数据(我的直觉告诉我链接一个agg函数?)
...喜欢df.groupby('users')
?
users artist
0 00001411dc427966b17297bf4d69e7e193135d89 the most serene republic
1 00001411dc427966b17297bf4d69e7e193135d89 stars
2 00001411dc427966b17297bf4d69e7e193135d89 broken social scene
3 00001411dc427966b17297bf4d69e7e193135d89 have heart
4 00001411dc427966b17297bf4d69e7e193135d89 luminous orange
5 00001411dc427966b17297bf4d69e7e193135d89 boris
6 00001411dc427966b17297bf4d69e7e193135d89 arctic monkeys
7 00001411dc427966b17297bf4d69e7e193135d89 bright eyes
8 00001411dc427966b17297bf4d69e7e193135d89 coaltar of the deepers
9 00001411dc427966b17297bf4d69e7e193135d89 polar bear club
10 00001411dc427966b17297bf4d69e7e193135d89 the libertines
11 00001411dc427966b17297bf4d69e7e193135d89 death from above 1979
12 00001411dc427966b17297bf4d69e7e193135d89 owl city
13 00001411dc427966b17297bf4d69e7e193135d89 coldplay
14 00001411dc427966b17297bf4d69e7e193135d89 okkervil river
15 00001411dc427966b17297bf4d69e7e193135d89 jim sturgess
16 00001411dc427966b17297bf4d69e7e193135d89 deerhoof
17 00001411dc427966b17297bf4d69e7e193135d89 fear before the march of flames
18 00001411dc427966b17297bf4d69e7e193135d89 breathe carolina
19 00001411dc427966b17297bf4d69e7e193135d89 mstrkrft
答案 0 :(得分:2)
我相信你在这里寻找agg
+ df.groupby('users').artist.apply(list).to_dict()
{'00001411dc427966b17297bf4d69e7e193135d89': ['the most serene republic',
'stars',
'broken social scene',
'have heart',
'luminous orange',
'boris',
...
]
}
。
{{1}}