如何将拼写检查功能应用于大型数据集?

2024-05-22 22:51:24 发布

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

我有一个拼写检查功能(Peter Novig的拼写更正),它可以在小数据帧上工作,但是对于5000字的数据帧,它需要很长时间才能运行,我停止了程序。有人有解决办法吗

#correct spelling
import enchant
from spellchecker import SpellChecker
spell = SpellChecker()
def spell_correct(text):
        try:
            output = ""
            splited_words = text.split()
            d = enchant.Dict("en_US")
            for i in splited_words:
                if d.check(i):
                    output = output + i + " "
                else:
                    output = output + spell.correction(i) + " "
        except Exception as e:
            print(e)
        return output
    
df["Text"] = df["Text"].apply(spell_correct)
df


Tags: 数据textimport功能dfoutputenchantpeter

热门问题