Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 熊猫数据帧-按唯一用户分组艺术家_Python_Pandas_Dataframe_Pandas Groupby - Fatal编程技术网

Python 熊猫数据帧-按唯一用户分组艺术家

Python 熊猫数据帧-按唯一用户分组艺术家,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

为了避免相同用户的重复,我想使用pandas
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',
  ...
]
}