1

This is my csv file.

Uid,Message,Status
9425252526,Hello 1,0
9425252527,Hello 2,0
9425252528,Hello 3,0
9425252529,Hello 4,0
9425252530,Hello 5,0

if I convert it to pandas dataframe and write it back to another file,it adds this unwanted extra column as below (leftmost column)

,Uid,Message,Status
0,9425252526,Hello 1,0
1,9425252527,Hello 2,0
2,9425252528,Hello 3,0
3,9425252529,Hello 4,0
4,9425252530,Hello 5,0

How to remove this column ?

2 Answers 2

2

Assuming you named your dataframe df. You need to set the index to false:

df.to_csv("yourFile.csv", index=False)
Sign up to request clarification or add additional context in comments.

Comments

1

You need add index=False to to_csv:

print df.to_csv(index=False)

"Uid,Message,Status"
"9425252526,Hello 1,0"
"9425252527,Hello 2,0"
"9425252528,Hello 3,0"
"9425252529,Hello 4,0"
"9425252530,Hello 5,0"

Or with filename:

df.to_csv('filename', index=False)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.