0

I am writing a CSV file in python using the following line:

data.to_csv(mydata.csv)

Unfortunately, the output presents a useless column as follow:

     Date  median       ori
0  2000-01-31   0.159  0.182900
1  2000-02-29   0.153  0.171349
2  2000-03-31   0.152  0.162461
3  2000-04-30   0.150  0.152306
4  2000-05-31   0.167  0.141220
5  2000-06-30   0.174  0.137749
6  2000-07-31   0.169  0.138802
7  2000-08-31   0.164  0.150315 

How can I get rid of this useless first column?

steve
  • 511
  • 1
  • 9
  • 33
  • Try: `data.to_csv('mydata.csv', index=False)`. Explained in docs: https://pandas.pydata.org/pandas-docs/version/0.23/generated/pandas.DataFrame.to_csv.html – sjw Sep 19 '18 at 17:28
  • Use `index=False` – rahlf23 Sep 19 '18 at 17:28
  • 1
    Duplicate. Here’s the answer you need: https://stackoverflow.com/a/25230582/7619676 – ZaxR Sep 19 '18 at 17:28

1 Answers1

3

data.to_csv("mydava.csv", index=False)

That should do it. Here's the documentation.

https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_csv.html

ltd9938
  • 1,444
  • 1
  • 15
  • 29