添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I'm trying to save a file with text information into csv format. However, after I use 'to_csv' in pandas (without specifying anything) save the file and I then use pd.read_csv to reopen the file. It will give me this error message:

ParserError: Error tokenizing data. C error: Buffer overflow caught - possible malformed input file.

But if I read the csv file in pandas like pd.read_csv('file.csv',lineterminator='\n'). It will open the file properly.

However, I need to use a software to process these text file, and the software opens the file the same way as how Excel opens the csv file, and I cannot specifying lineterminator='\n' like I did in the python. If I open the csv file using that software, some text in the column will go to other rows. The text between the index 378 and 379 is supposed to be together in 378 row. However, they goes to other rows and go to the index column.

           id               text
378         1    Good morning. This row's text goes to the following rows
Dot dot    NaN              NaN
HELLO      NaN              NaN
Apple      NaN              NaN
379         2    This row is correct

Does anyone know how to solve this problem when i use pandas.to_csv to save the dataframe? what should i specify if i want to open the file properly in a software like Excel?

Thanks for your reply. But i'm not going to open the csv using python, I will save it using to_csv in python but I will open it in an excel-like software and I hope I can open it properly. Do you know how to save the csv file so that i can open it properly in excel? – user12596119 Sep 12, 2020 at 11:50

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.