我有一个数据框,其中有一列包含类别,另一列包含单词。单词可以在不同类别中重复,因此可能存在重复项。但是,我想将这些重复项放在字典中,如下所示:
数据框
category | word | score
happy | tolerance | 0.91
unhappy | tolerance | 0.12
angry | kill | 1.0
confident | tolerance | 0.56
friendly | tolerance | 0.70
happy | kill | 0.01
...
预期字典:
d = {
'tolerance' = {'happy': 0.91, 'angry': 0.01, 'confident': 0.56, 'friendly': 0.70},
'kill' = {'happy': 0.01, 'angry': 1.0, 'confident': 0.32, 'friendly': 0.016},
...
}
慕村9548890
相关分类