pandas处理拼写错误用textblob模块处理

直接用textblob(x).correct()

from textblob import TextBlob
import pandas as pd
d = {
    
    'col1': ["heoll chica", "hello girl"], 'col2': [2, 4]}
df = pd.DataFrame(data=d)
print(df)
def textblob_test(x):
    blob = TextBlob(x)
    return blob.correct()
print(df['col1'].apply(lambda x:textblob_test(x)))
#结果为
0    (h, e, l, l,  , c, h, i, n, a)
1    (h, e, l, l, o,  , g, i, r, l)

#在返回的代码中加入str()
def textblob_test(x):
    blob = TextBlob(x)
    return str(blob.correct())
#现在可以成功使用textblob的拼写错误问题,其他textblob的使用方法一致。
0    hell china
1    hello girl

猜你喜欢

转载自blog.csdn.net/weixin_45631815/article/details/108980257