为什么可以从Python中导入的CSV删除列/字段?

发布于 2025-01-26 07:29:23 字数 308 浏览 2 评论 0原文

我合并了您在另一个文件中看到的DF,当我将其导入到当前文件中时,我遇到了一个奇怪的字段,“未命名:0”,我以前从未见过。它没有回来。

我列出了列名,准确地复制了字段名称,并试图将其删除,但没有成功。

任何输入都将不胜感激。

I merged the df you see below in another file, and when I imported it into the current file, I was met with a strange field, 'Unnamed: 0', that I hadn't seen before. It wasn't there back.

I have listed the column names, copied the field name exactly, and attempted to drop it but was unsuccessful.

enter image description here

Any input would be appreciated.

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

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

发布评论

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

评论(2

还在原地等你 2025-02-02 07:29:23

尝试此操作时,

df.drop('Unnamed: 0', axis = 1, inplace = True)

请始终使用Inplace = true当您更改数据框架中的某些内容或如果您不更改源dataframe,则尝试将其存储在不同的数据框架中,

new_df = df.drop('Unnamed: 0', axis = 1)

Try this

df.drop('Unnamed: 0', axis = 1, inplace = True)

Always use inplace = True when you are changing something in place in a dataframe or try to store in the different dataframe like this if you are not changing the source dataframe,

new_df = df.drop('Unnamed: 0', axis = 1)
<逆流佳人身旁 2025-02-02 07:29:23

尝试以下操作:

df = pd.read_csv(path_to_data+file_name, sep=',')
columns_to_drop = [column for column in df.columns if 'Unnamed:' in column]
df.drop(columns_to_drop, axis = 1, inplace = True)

try this :

df = pd.read_csv(path_to_data+file_name, sep=',')
columns_to_drop = [column for column in df.columns if 'Unnamed:' in column]
df.drop(columns_to_drop, axis = 1, inplace = True)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文