【发布时间】:2017-10-03 07:34:34
【问题描述】:
我有一个看起来像
的数据框数据
*id*, *name*, *URL*, *Type*
2, birth_france_by_region, http://abc. com, T1
2, birth_france_by_region, http://pt. python, T2
3, long_lat, http://abc. com, T3
3, long_lat, http://pqur. com, T1
4, random_time_series, http://sadsdc. com, T2
4, random_time_series, http://sadcadf. com, T3
5, birth_names, http://google. com, T1
5, birth_names, http://helloworld. com,T2
5, birth_names, http://hu. com, T3
我想要一个这个数据框来合并 id 相等的行,并将字典的 Type 列表作为字典 URL 的键作为值 所以最终输出这个:-
*id*, *name*, *URL*
2,birth_france_by_region, [{T1:http://abc .com},{T2:http://pt.python}]
3,long_lat, [{T3:http://abc .com},{T1:http://pqur. com}]
4,random_time_series, [{T2:http://sadsdc. com},{T3:http://sadcadf .com}]
5,birth_names, [{T1:http://google .com},{T2:http://helloworld. com},
{T3:http://hu. com}]
【问题讨论】:
-
看看如何用 groupby stackoverflow.com/questions/17841149/…连接字符串
标签: python python-2.7 pandas dataframe