无法从某些列中删除标点符号,而其他列则可以正常运行

发布于 2025-01-18 02:04:40 字数 625 浏览 1 评论 0原文

我正在尝试使用标点符号删除函数,它对于某些列工作正常,但对于少数列,它只是将错误作为列名给出。

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.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半衾梦 2025-01-25 02:04:40

这里的 KeyError 基本上表示您的数据框中没有名为 command 的列。 Command 是大写 C 吗?

The KeyError here basically says that you don't have column by the name command in your data frame. Is the Command with capital C?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文