我有一个包含list
的列的pandas
数据框:
df = pd.DataFrame({'List': [['once', 'upon'], ['once', 'upon'], ['a', 'time'], ['there', 'was'], ['a', 'time']], 'Count': [2, 3, 4, 1, 2]})
Count List
2 [once, upon]
3 [once, upon]
4 [a, time]
1 [there, was]
2 [a, time]
我该如何合并
List
列并求和Count
列?预期结果是:Count List
5 [once, upon]
6 [a, time]
1 [there, was]
我曾尝试过:
df.groupby('List')['Count'].sum()
这将导致:
TypeError: unhashable type: 'list'