Skip to content Skip to sidebar Skip to footer

Pandas Adds "\r" To Csv File

This boils down to a simpler problem here I have a pandas dataframe that looks like this: In [1]: df Out[1]: 0 1 0 a A\nB\nC 1 a D\nE\nF 2 b A\nB\nC When I write

Solution 1:

As some have already said in comments above and on the post you have put in reference here, this is a typical windows issue when serializing newlines. The issue has been reported on pandas-dev github #17365 as well.

Hopefully on Python3, you can specify the newline:

withopen("out.csv", mode='w', newline='\n') as f:
    df.to_csv(f, sep=",", line_terminator='\n', encoding='utf-8')

Post a Comment for "Pandas Adds "\r" To Csv File"