Python中的字典搜索
我有一个包含数据和标题的数据集。我正在尝试通过所有头条新闻来应用词典搜索循环。
dict = pd.read_csv("suspectdict.csv")
news_df = pd.read_csv("news.csv")
suspectdict.csv中的单词包含描述动作的动词
被指控,被谋杀,谋杀,被捕,被捕..
。因此,在这种情况下,当它通过句子循环时,例如:
“一个被盗窃的当地男子”
因为被充电是在词典中,它将返回1 else 0 0
I have a dataset that contains data and headlines of articles. I am trying to apply dictionary search looping through all the headlines.
dict = pd.read_csv("suspectdict.csv")
news_df = pd.read_csv("news.csv")
words in suspectdict.csv contains verbs that describes the actions
charged, murdered, murder, caught, arrested..
and my news.csv consists of criminal articles. So in this case when it loops through the sentences and if for example:
"a local man charged for theft"
since charged is in the dictionary, it will return 1 else 0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,您需要使您正在对集合进行检查的字典为O(1)。
然后,您可以通过检查集合交点的大小是否大于0,检查标题中的任何单词是否在字典中。
So you'd want to make the dictionary you are checking against a set as inclusion in the set is O(1).
You could then check if any of the words of in the title are in the dictionary by checking for if the size of the set intersection is greater than 0.