Symspell' float'对象没有属性。

发布于 2025-02-02 14:23:44 字数 1469 浏览 1 评论 0原文

我想更正咒语,我尝试此代码是工作

from symspellpy import SymSpell, Verbosity

input_term = "diperbakin tertnduk kenaps"
suggestions = sym_spell.lookup_compound(input_term, max_edit_distance=2)

for suggestion in suggestions:
    print(suggestion.term)

输出:Diperbaki tertunduk kenapa

,但我想在数据集中应用此代码,但我遇到了此错误

comment = []
for index, row in df.iterrows():
    suggestions = sym_spell.lookup_compound(row["Comment"], max_edit_distance=2)
    comment.append(suggestions[0].term)
    
df["Comment"] = comment
df.head()

,此错误

AttributeError                            Traceback (most recent call last)
<ipython-input-28-3b0edc49798e> in <module>()
      1 comment = []
      2 for index, row in df.iterrows():
----> 3     suggestions = sym_spell.lookup_compound(row["Comment"], max_edit_distance=2)
      4     review.append(suggestions[0].term)
      5 

1 frames
/usr/local/lib/python3.7/dist-packages/symspellpy/helpers.py in parse_words(phrase, preserve_case, split_by_space)
    196     if preserve_case:
    197         return re.findall(r"([^\W_]+['’]*[^\W_]*)", phrase)
--> 198     return re.findall(r"([^\W_]+['’]*[^\W_]*)", phrase.lower())
    199 
    200 

AttributeError: 'float' object has no attribute 'lower'

dataset
i want to correct spell i try this code is work

from symspellpy import SymSpell, Verbosity

input_term = "diperbakin tertnduk kenaps"
suggestions = sym_spell.lookup_compound(input_term, max_edit_distance=2)

for suggestion in suggestions:
    print(suggestion.term)

output : diperbaki tertunduk kenapa

but i want to apply this code in my dataset but i got this error

comment = []
for index, row in df.iterrows():
    suggestions = sym_spell.lookup_compound(row["Comment"], max_edit_distance=2)
    comment.append(suggestions[0].term)
    
df["Comment"] = comment
df.head()

and this the error

AttributeError                            Traceback (most recent call last)
<ipython-input-28-3b0edc49798e> in <module>()
      1 comment = []
      2 for index, row in df.iterrows():
----> 3     suggestions = sym_spell.lookup_compound(row["Comment"], max_edit_distance=2)
      4     review.append(suggestions[0].term)
      5 

1 frames
/usr/local/lib/python3.7/dist-packages/symspellpy/helpers.py in parse_words(phrase, preserve_case, split_by_space)
    196     if preserve_case:
    197         return re.findall(r"([^\W_]+['’]*[^\W_]*)", phrase)
--> 198     return re.findall(r"([^\W_]+['’]*[^\W_]*)", phrase.lower())
    199 
    200 

AttributeError: 'float' object has no attribute 'lower'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文