Мне нужен код, чтобы иметь возможность работать с именами состояний с двумя словами.
Код: Выделить всё
import sys
!pip install pyspellchecker
from spellchecker import SpellChecker
#from google.colab import files
import pandas as pd
import io
#Implement spellcheck.
spell=SpellChecker()
for ind in newDF.index:
stateWordList = newDF['State'][ind].split()
if len(stateWordList) == 1:
#print(True)
if stateWordList[0] in spell:
pass
else:
correctState = input("'{}' is not a valid state, please enter a correct spelling:".format(stateWordList[0]))
newDF.at[ind, 'State'] = correctState
else:
misspelledState = False in (stateWord in spell for stateWord in stateWordList)
if misspelledState == True:
pass
else:
correctState = input("'{}' is not a valid state, please enter a correct spelling:".format(stateWordList[0]))
newDF.at[ind, 'State'] = correctState
< /code>
Вместо этого он не видит север, не так ли, как действительный, и возвращает: < /p>
'North' is not a valid state, please enter a correct spelling:
Подробнее здесь: https://stackoverflow.com/questions/720 ... tate-names