我应该如何读取没有带 pandas 的“未命名"行的csv文件? [英] how should i read a csv file without the 'unnamed' row with pandas?

查看:56
本文介绍了我应该如何读取没有带 pandas 的“未命名"行的csv文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下命令写入.csv文件:

I am writing to a .csv file with:

my_data_frame.to_cav("some_path")

尝试使用以下方法读取文件时:

When trying to read the file with:

pd.read_csv("some_path")

我可以确定添加了一个未命名的列. 我该如何解决?

I can tell that an unnamed column was added. How can i fix that?

推荐答案

to_csv()默认情况下会写入索引,因此您可以在保存CSV时禁用索引:

to_csv() writes an index per default, so you can either disable index when saving your CSV:

df.to_csv('file.csv', index=False)

或在读取时指定索引列:

or specify an index column when reading:

df = pd.read_csv('file.csv', index_col=0)

这篇关于我应该如何读取没有带 pandas 的“未命名"行的csv文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆