I have what I thought would be a simple task. I need to create a text file that has uses the unix LF convention at the end of a line. However, when I attempt to accomplish this
Note this answer is specific to Python 2's CSV handling.
to_csv
defaults to opening the file in 'w'
mode which defaults to text mode. On Windows text mode translates \n
to \r\n
. Open the the file in binary mode instead, and specify an encoding if you have non-ASCII text in your frame.
df.to_csv('filename.txt',sep='\t',mode='wb',encoding='utf8')