2 回答

TA貢獻(xiàn)1877條經(jīng)驗(yàn) 獲得超1個(gè)贊
如果您只想創(chuàng)建一個(gè)從您遇到的拼寫錯(cuò)誤的單詞到他們的建議的映射,您可以通過刪除重復(fù)的單詞來減小數(shù)據(jù)集的大小。spell.unknown這將最大限度地減少對(duì)and的調(diào)用次數(shù),spell.correction并防止對(duì)字典內(nèi)容進(jìn)行不必要的更新。
uniquewords = set().union(*(sentence.split() for sentence in df.text))
corrections = {word: spell.correction(word) for word in spell.unknown(uniquewords)}

TA貢獻(xiàn)1773條經(jīng)驗(yàn) 獲得超3個(gè)贊
您可以嘗試 pd.apply 而不是循環(huán):
eng = pd.Series(['EmpName', 'EMP_NAME', 'EMP.NAME', 'EMPName', 'CUSTOMIR', 'TIER187CAST', 'MultipleTIMESTAMPinTABLE', 'USD$'])
eng = eng.str.lower()
eng = eng.str.split()
spell = SpellChecker()
def msp(x):
return spell.unknown(x)
eng.apply(msp)
添加回答
舉報(bào)