您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何在句子的pandas列中使用自动更正

如何在句子的pandas列中使用自动更正

使用自动更正库,您需要遍历数据框的行,然后遍历给定行中的单词以应用该spell方法。这是一个工作示例:

from autocorrect import spell 
import pandas as pd

df = pd.DataFrame(["and this hass a spel error"], columns=["colTest"])
df.colTest.apply(lambda x: " ".join([spell(i) for i in x.split()]))

同样,正如@jpp在下面的注释中建议的那样,我们可以避免使用lambda以下方法

df["colTest"] = [' '.join([spell(i) for i in x.split()]) for x in df['colTest']]

输入内容如下所示:

                      colTest
0  and this hass a spel error

输出

0    and this has a spell error
Name: colTest, dtype: object
其他 2022/1/1 18:41:44 有486人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶