-2

I am reading a csv file using 'pd.read_csv' and writing it to another csv using 'file.to_csv'. It is incorrectly displaying the headers in the output file. For example,

input:

ABC | 20151004 | 1900 | 0000000002 | MUPPETS SP 1-10/4, THE |  |  | R|RS

0

0

0

0

0

2993

script:

data = pd.read_csv(r'filepath/input.csv')

print data

Input header: ABC | 20151004 | 1900 | 0000000002 | MUPPETS SP 1-10/4, THE | | | R|RS

Output header: ABC | 20151004 | 1900 | 0000000002 | MUPPETS SP 1-10/4, THE | | | R|RS.1

Not sure why it is adding '.1' to the end of some of the headers.

4
  • 2
    add first five lines from csv file here. Commented Aug 6, 2016 at 4:49
  • Possible duplicate of stackoverflow.com/questions/20845213/… Commented Aug 6, 2016 at 5:15
  • Better duplicate question: stackoverflow.com/questions/26786960/… Commented Aug 6, 2016 at 5:16
  • I tried using index=False param. I am receiving below error. TypeError: parser_f() got an unexpected keyword argument 'index' Commented Aug 6, 2016 at 5:22

1 Answer 1

0

Try this:

data = pd.read_csv(r'filepath/input.csv',sep='|')

The rs.1 is likely indicative of duplicate 'rs' columns

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you. You are right. It's a large file and I did not notice it.It is a duplicate column. Is there a way to read the column as it is without adding '.1' in the end?
you need to add some columns to the question, to solve. Those dont look like headers but rather its all data. You also need to work through a tutorial before posting questions. people.duke.edu/~ccc14/sta-663/…

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.