用pandas列匹配列表元素的关键字

2024-05-15 18:00:51 发布

您现在位置:Python中文网/ 问答频道 /正文

这个问题是this的进一步部分。所以我加了一个新问题

如果我的数据帧B是这样的:

ID   category              words                   bucket_id
 1   audi                  a4, a6                  94
 2   bugatti               veyron, chiron          86
 3   mercedez              s-class, e-class        79
 4   dslr                  canon, nikon            69
 5   apple                 iphone,macbook,ipod     51
 6   finance               sales,loans,sales price 12
 7   politics              trump, election, votes  77
 8   entertainment         spiderman,thor, ironmen 88
 9   music                 beiber, rihana,drake    14
     ........              ..............
     .........             .........

我想要映射的类别及其对应的列ID作为dictionary。什么比如:在

^{pr2}$

编辑

我只想映射列words中两个逗号之间精确匹配的关键字,而不是字符串之间的关键字,或者与任何其他单词一起映射。 Image


Tags: 数据idbucket关键字thisclassa4words