我已经引用了下面的帖子,它非常有用,但我还需要更进一步。 Python - Searching a string within a dataframe from a list
我不仅要在我的数据框中搜索单词列表,还要跟踪是否找到多个单词以及频率。因此,使用上述帖子中的示例:
如果这是我的搜索列表
search_list = ['STEEL','IRON','GOLD','SILVER']
这是我正在搜索的数据框
a b
0 123 'Blah Blah Steel'
1 456 'Blah Blah Blah Steel Gold'
2 789 'Blah Blah Gold'
3 790 'Blah Blah blah'
我希望我的输出是
a b c d
0 123 'Blah Blah Steel' 'STEEL' 1
1 789 'Blah Blah Steel Gold' 'STEEL','GOLD' 2
2 789 'Blah Blah Gold' 'GOLD' 1
3 790 'Blah Blah blah'
我如何在上面提到的文章中扩展这些令人敬畏的解决方案,以获得所需的输出?目前,我正在利用投票结果最高的答案作为起点
我更关心的是能够标记列表中的多个单词。我还没有找到任何方法来做到这一点。如果在这一步中无法实现,我可以将字符串计数函数应用于数据帧以创建频率列。如果有一种方法可以一步完成这一切,那也很高兴知道
提前谢谢
您可以使用re.findall()而不是extract()来执行所需的操作
此输出如下所示:
相关问题 更多 >
编程相关推荐