How to change end-of-line conventions?

前端 未结 1 1412
孤独总比滥情好
孤独总比滥情好 2021-01-21 02:25

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

相关标签:
1条回答
  • 2021-01-21 03:06

    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')
    
    0 讨论(0)
提交回复
热议问题