Reputation: 69
I have the following DataFrame:
Date Year Month Day Security Trade Value
0 2011-01-10 00:00:00 2011 1 10 AAPL Buy 1500
1 2011-01-13 00:00:00 2011 1 13 AAPL Sell 1500
When I write this to csv, an extra column is created at the start of the file:
,Date,Year,Month,Day,Security,Trade,Value
0,2011-01-10 00:00:00,2011,1,10,AAPL,Buy,1500
1,2011-01-13 00:00:00,2011,1,13,AAPL,Sell,1500
How can i resolve this?
Upvotes: 2
Views: 2343
Reputation: 353449
The "extra column" is the index. You can suppress this by passing index=None
, for example:
>>> df
A
0 10
1 20
2 30
>>> df.to_csv("out.csv")
>>> !cat out.csv
,A
0,10
1,20
2,30
>>> df.to_csv("out.csv", index=None)
>>> !cat out.csv
A
10
20
30
Upvotes: 5