我有以下形式的数据:
"almond" "blueberry" 3
"almond" "leek" 6
"almond" "citron" 7
"almond" "fish" 2
...
"leek" "swiss_cheese" 3
"leek" "pumpkin" 5
"leek" "onion" 4
"leek" "chocolate" 10
...
对于第一列中的每个值,我想根据第三列找到k个最佳合作伙伴。“最佳”是指:第三行中的较低数字。因此,对于杏仁来说,它的三个最佳搭档是鱼、蓝莓、韭菜。对于韭菜来说,它的三个最佳搭档是swiss_cheese
洋葱和南瓜。我最后想将全表减少到第一列中每个因素的三个最佳合作伙伴,即
"almond" "blueberry" 3
"almond" "leek" 6
"almond" "fish" 2
...
"leek" "swiss_cheese" 3
"leek" "pumpkin" 5
"leek" "onion" 4
...