【发布时间】:2021-09-19 19:19:50
【问题描述】:
count_freq data
3 [['58bcd029', 2, 'expert'],
['58bcd029', 2, 'user'],
['58bcd029', 2, 'expert']]
2 [['58bcd029', 2, 'expert'],
['58bcd029', 2, 'expert']]
1 [['1ee429fa', 1, 'expert']]
所以我想从数据框的每一行和每个列表中获取“专家”和“用户”的计数。在统计了专家和用户之后,我想将各自的 id 存储在另一个列表中。我尝试将它们转换为字典并使用键进行计算,但它不起作用。谁能帮我做这件事?
我想要这种格式的数据框:
count_freq count_expert ids count_user ids
3 2 ['58bcd029','58bcd029'] 1 ['58bcd029']
2 2 ['58bcd029','58bcd029'] 0 []
1 1 ['1ee429fa'] 0 []
【问题讨论】:
标签: python pandas list dataframe dictionary