如何在 Pandas 的 .csv 文件中写入 DataFrame 时删除索引列?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40934185/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 02:33:42  来源:igfitidea点击:

How to drop the index column while writing the DataFrame in a .csv file in Pandas?

pythoncsvpandasdataframe

提问by aroma

My DataFrame contains two columns named 'a','b'. Now when I created a csv file of this DataFrame:

我的 DataFrame 包含名为“a”、“b”的两列。现在,当我创建此 DataFrame 的 csv 文件时:

df.to_csv('myData.csv')

df.to_csv('myData.csv')

And when I opened this in an excel file, there is an extra column with indices that appears alongside the columns 'a' and 'b', but I don't want that. I only want columns 'a' and 'b' to appear in the excel sheet.

当我在一个 excel 文件中打开它时,有一个额外的列与索引一起出现在列“a”和“b”旁边,但我不想要那个。我只希望 'a' 和 'b' 列出现在 Excel 工作表中。

Is there any way to do this?

有没有办法做到这一点?

回答by Aakash Makwana

Try,

尝试,

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