Python 熊猫数据帧-按唯一用户分组艺术家
为了避免相同用户的重复,我想使用pandasPython 熊猫数据帧-按唯一用户分组艺术家,python,pandas,dataframe,pandas-groupby,Python,Pandas,Dataframe,Pandas Groupby,为了避免相同用户的重复,我想使用pandasgroupby函数整齐地组织一个嵌套的{k:artist1、artist2、artist3等}。这是示例数据(我的直觉告诉我链一个agg func?) …像df.groupby('users') 我相信您正在这里寻找groupby+agg df.groupby('users').artist.apply(list).to_dict() {'00001411dc427966b17297bf4d69e7e193135d89': ['the most se
groupby
函数整齐地组织一个嵌套的{k:artist1、artist2、artist3等}
。这是示例数据(我的直觉告诉我链一个agg func?)
…像df.groupby('users')
我相信您正在这里寻找
groupby
+agg
df.groupby('users').artist.apply(list).to_dict()
{'00001411dc427966b17297bf4d69e7e193135d89': ['the most serene republic',
'stars',
'broken social scene',
'have heart',
'luminous orange',
'boris',
...
]
}
我说不出你的预期产出是多少。你能澄清一下吗?可能重复:
df.groupby('users').artist.apply(list).to_dict()
{'00001411dc427966b17297bf4d69e7e193135d89': ['the most serene republic',
'stars',
'broken social scene',
'have heart',
'luminous orange',
'boris',
...
]
}