【发布时间】:2023-03-07 14:24:01
【问题描述】:
我在 pandas 数据框中有一列(它实际上相当大,大约 150 万行文本数据),我想与一个字符串进行比较。对于一个简单的完整性检查/测试,我只想在前 100 行上尝试一下,以了解它不会花费很长时间来执行。因此,数据帧的最小样本如下所示:
Text
Hello, this is Peter, what would you need me to help you with today? I need you
Good Morning, John here, are you calling regarding your cell phone bill? I am not
......
我有一个固定的字符串
"Can I help you today?"
我的目标是获得相似度分数(我仍在决定使用哪个指标,Levenstein vs Jaccard 或 Cosine)但这不是我的主要问题,以获得每个 pandas 数据框值和固定字符串之间的相似度分数值,然后可能只是按顺序对它们进行排序。
这是我写的代码:
import nltk
nltk.download()
nltk.download('stopwords')
nltk.download('wordnet')
Levenstein = []
Counter = 0
for x in All_sentences.rows:
while Counter < 100:
distance = nltk.edit_distance(All_sentences['Text'], "what I wanted
to calling because I lost my ATM card debit card")
Levenstein.append(distance)
Counter +=1
当我运行这段代码时,首先,它会弹出一个带有 NLTK 下载器的对话框
[WinError 10060] A connection attempt failed because the connected party did
not properly respond after a period of time, or established connection
failed because connected host has failed to respond.
其次,我看到一条消息(在我正在运行但未完成执行的代码下方):
showing info https://raw.githubusercontent.com/nltk/nltk_data/gh-pages/index.xml
我等待了很长时间,但输出中没有显示任何内容(它仍在运行,我只看到它仍在处理的 *)。
这些消息是什么,最重要的是,如果我只对 100 个值而不是整个数据集进行样本比较,为什么要花这么长时间来处理?
【问题讨论】:
-
您是否在使用公司代理?
-
费城同胞你好:) 我不太确定这是什么意思?如果这就是你的意思,我确实在一家公司工作?我可以 imort nltk 但是当我运行 nltk.download() 时它似乎不起作用。
-
您好!大多数公司都在防火墙/代理后面。如果您现在正在工作(即在您公司的网络上),您需要添加逻辑以通过代理。您可以通过设置
HTTP_PROXY或HTTPS_PROXY环境变量或使用nltk.set_proxy()来做到这一点 -
是的,我已经按照以下答案的建议进行了尝试,但这似乎并没有改变我的输出中的任何内容
-
我的意思是你不能使用
http://proxy.example.com:3128。您必须找到 您的 代理 URL。
标签: python python-3.x nltk edit-distance