Using the TextBlob library it is possible to improve the spelling of strings by defining them as TextBlob objects first and then using the correct
method.
Example:
from textblob import TextBlob
data = TextBlob('Two raods diverrged in a yullow waod and surry I culd not travl bouth')
print (data.correct())
Two roads diverged in a yellow wood and sorry I could not travel both
Is it possible to do this to strings in a Pandas DataFrame series such as this one:
data = [{'one': '3', 'two': 'two raods'},
{'one': '7', 'two': 'diverrged in a yullow'},
{'one': '8', 'two': 'waod and surry I'},
{'one': '9', 'two': 'culd not travl bouth'}]
df = pd.DataFrame(data)
df
one two
0 3 Two raods
1 7 diverrged in a yullow
2 8 waod and surry I
3 9 culd not travl bouth
To return this:
one two
0 3 Two roads
1 7 diverged in a yellow
2 8 wood and sorry I
3 9 could not travel both
Either using TextBlob or some other method.
You could do something like:
df.two.apply(lambda txt: ''.join(textblob.TextBlob(txt).correct()))
Using pandas.Series.apply
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With