在 pandas 中保存csv时删除索引列 [英] Remove index column while saving csv in pandas
本文介绍了在 pandas 中保存csv时删除索引列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试用熊猫创建csv
,但是当我将数据导出到csv
时,它会给我一个额外的列
I'm trying to create a csv
with pandas, but when I export the data to csv
it gives me an extra column
d = {'one' : pd.Series([1., 2., 3.]),'two' : pd.Series([1., 2., 3., 4.])}
df0_fa = pd.DataFrame(d)
df_csv = df0_fa.to_csv('revenue/data/test.csv',mode = 'w')
因此,我的结果是:
,one,two
0,1.0,1.0
1,2.0,2.0
2,3.0,3.0
3,4.0,4.0
但是,预期结果是:
one,two
1.0,1.0
2.0,2.0
3.0,3.0
4.0,4.0
推荐答案
您看到的是索引列.只需设置index=False
:
What you are seeing is the index column. Just set index=False
:
df_csv = df0_fa.to_csv('revenue/data/test.csv',mode = 'w', index=False)
这篇关于在 pandas 中保存csv时删除索引列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文