在pandas中的数据帧上使用constructions.fix时,IndexError:字符串索引超出范围

2024-09-29 01:36:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用contractions.fix扩展数据集中的单词。但是,当我运行代码并尝试将扩展的单词添加到数据集中的新列时,会得到一个超出范围的错误字符串索引。我试着到处找,但找不到解决办法

数据集的屏幕截图,我想在comments列上运行contractions.fix

img

将抛出代码和错误的屏幕截图:

This is the code I am using and it shows the error(below in the screenshot)

这是我运行constrations.fix的代码:

rws["expanded_words"]=rws['comments'].apply(lambda x: [contractions.fix(word) for word in x.split()])

Tags: 数据字符串代码屏幕错误fix单词comments