无法从某些列中删除标点符号,而其他列则可以正常运行
我正在尝试使用标点符号删除函数,它对于某些列工作正常,但对于少数列,它只是将错误作为列名给出。
def remove_punctuations(text):
for punctuation in string.punctuation:
text = text.replace(punctuation, '')
return text
dataset['Info'] = dataset['Info'].apply(remove_punctuations)
dataset['Message'] = dataset['Message'].apply(remove_punctuations)
dataset['Target'] = dataset['Target'].apply(remove_punctuations)
dataset['command'] = dataset['command'].apply(remove_punctuations)
最后一次运行它给了我一个错误。
I am trying to use a punctuation removal function and it worked fine for some columns but for few columns it just give the error as the column name.
def remove_punctuations(text):
for punctuation in string.punctuation:
text = text.replace(punctuation, '')
return text
dataset['Info'] = dataset['Info'].apply(remove_punctuations)
dataset['Message'] = dataset['Message'].apply(remove_punctuations)
dataset['Target'] = dataset['Target'].apply(remove_punctuations)
dataset['command'] = dataset['command'].apply(remove_punctuations)
for the last run it gives me an error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里的
KeyError
基本上表示您的数据框中没有名为command
的列。Command
是大写 C 吗?The
KeyError
here basically says that you don't have column by the namecommand
in your data frame. Is theCommand
with capital C?