1

I'am exporting a pandas data frame to csv with the following function:

tocsv.to_csv("/Users/john/test/test3.csv")

The outcome is fine but after sorting in excel at the end of the file there were some funny rows:

enter image description here

I think this have been caused by the character '|'. Any suggestion on how to deal with it?

Anand S Kumar
  • 88,551
  • 18
  • 188
  • 176
Blue Moon
  • 4,421
  • 20
  • 52
  • 91
  • What happens when you remove all the "|" characters? What are the separators set to in Excel? – Paul Jul 31 '15 at 09:48
  • And how are these rows represented in your dataframe? What is exactly wrong (compared to the original data)? – joris Jul 31 '15 at 10:32
  • As you can see from the image, each row should begin with the index number, than some strings representing several ids, price than timestamp and so on. from line 84 onwards this structure is not preserved. – Blue Moon Jul 31 '15 at 10:38
  • OK, we can see that. But the data in these rows, are they present in the original dataframe? And in what way? You can also look in the csv file itself (using a text editor instead of excel) to see how they look and to be sure it is not an excel import issue. – joris Jul 31 '15 at 12:18
  • I checked the csv on TextWrangler. It looks fine no messed rows neither at the beginning or end of the file. Ho should I tell excel to import it correctly then? – Blue Moon Jul 31 '15 at 12:30
  • Can you show the lines that mess up in excel as they are in the csv? – joris Jul 31 '15 at 12:31
  • 3
    Nobody can debug your picture, please provide data from your dataframe and the data that comes out of your `to_csv` function as text in your question. Please scale down your data to a few rows (you can use `tocsv.head().to_csv()`) and post the data. After that your problem will probably be easily solved – firelynx Jul 31 '15 at 14:35
  • data is confidential and I cannot post it. Moreover, it is roughly 4000 rows x 400 columns. So I couldn't show it on SO anyway – Blue Moon Jul 31 '15 at 14:43
  • 3
    What you can show is a minimal complete verifiable example: http://stackoverflow.com/help/mcve or http://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples – JohnE Jul 31 '15 at 14:46

0 Answers0