0

I have searched a lot about this topic of how to remove the index column of the datframe when exporting the dataframe to csv file. I found many solutions and tricks but none of them worked with me. In the csv output I got 0 (the column index) at the first row of the CSV output. Can you guide me of fixing such a problem?!!

3
  • Have you tried df.to_csv(index=False)? Commented Nov 5, 2020 at 16:24
  • are you using df.reset_index(inplace=True) before doing df.to_csv(index=False)? Commented Nov 5, 2020 at 16:32
  • Yes I have tried both and didn't work. Commented Nov 5, 2020 at 16:46

2 Answers 2

1
   df.to_csv('output.csv', index=False, header=False)
Sign up to request clarification or add additional context in comments.

Comments

1

Are you using pandas? If so, you can use the .to_csv method with the argument index=False to remove index:

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

or header=False to remove column names:

df.to_csv('output.csv', header=False)

5 Comments

Thanks a lot. This was my first try and this removes the row's index not the column index.
Thanks a lot for your support.
Does this print the results into terminal?
@alper it doesn't. It only creates a csv file. If you want to print something you have to say it to print whatever you want to print.
Can I redirect it to the terminal in paralel ? or should I do cat output.csv' inside the python script?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.