简体   繁体   中英

Python) to_csv: my csv file data is separated and pushed back

I'm saving my pd.DataFrame with """df.to_csv('df.csv', encoding='utf-8-sig)"""

my csv file have a problem...
please see rows, where have content2-1, content2-2, and content2-3 in this pic.

Before saving(to_csv), there was no problem. All the data had right columns, 'content2' was not separated. but after df -> csv...
'content2' is all separated, and the others of 'id2' are allocated to the wrong columns. "2018-04-21" have to be in column D, 0 with E,F,G, and url must be in column I.

why this happen? because of large csv file?(774,740KB), because of language?(Korean), or csv cannot recognize enter key?(All data with problems such as content2 were separated based on the enter key.)

how can I resolve this? I have no idea

Unfortunately I never figured out the reason for this.. I assumed it was something to do with the size of the data i was working with and excel not liking it.

What worked for me though was using .to_excel() instead of to_csv(). I know, far from a perfect answer, but thought id put it here incase it is enough for your case

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM