-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.

shivsn
  • 7,680
  • 1
  • 26
  • 33
naveen ch
  • 25
  • 3
  • 2
    add first five lines from csv file here. – RAVI Aug 06 '16 at 04:49
  • Possible duplicate of http://stackoverflow.com/questions/20845213/how-to-avoid-python-pandas-creating-an-index-in-a-saved-csv – Kartik Aug 06 '16 at 05:15
  • Better duplicate question: http://stackoverflow.com/questions/26786960/pandas-to-csv-first-extra-column-remove-how-to – Kartik Aug 06 '16 at 05:16
  • I tried using index=False param. I am receiving below error. TypeError: parser_f() got an unexpected keyword argument 'index' – naveen ch Aug 06 '16 at 05:22

1 Answers1

0

Try this:

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

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

Merlin
  • 24,552
  • 41
  • 131
  • 206
  • 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? – naveen ch Aug 06 '16 at 16:58
  • 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. https://people.duke.edu/~ccc14/sta-663/IntroductionToPythonSolutions.html – Merlin Aug 06 '16 at 17:04