相关文章推荐
可爱的豆芽  ·  快看漫画VIP油猴 - 抖音·  1 年前    · 
安静的西瓜  ·  asp.net core - Status ...·  1 年前    · 
小胡子的沙发  ·  Oops!!! - 简书·  1 年前    · 
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

Pandas to_csv adds extra line terminator by default - winpython 3.8.5.0, Pandas 1.1.0. Is this expected behavior?

Ask Question

Just upgraded to WinPython 3.8.5 and now an extra line is added with the Pandas DataFrame to_csv() method.

import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.randint(0,15,size=(15, 4)), columns=list('ABCD'))
df.to_csv('d://data//df.csv')
# gives
,A,B,C,D
0,2,3,0,1
1,0,1,2,0
2,0,4,2,0
3,0,0,3,2

Where as with the line_terminator explicitly referenced:

df.to_csv('d://data//test.csv',line_terminator='\n')
# gives the normal output expected
,A,B,C,D
0,2,3,0,1
1,0,1,2,0
2,0,4,2,0
3,0,0,3,2
4,4,4,0,4

Did upgrade to pandas 1.1.1 from 1.1.0 but had no effect and looks like non-expectant behaviour.

No extra spaces in my csv with your first code. I'm on Windows10, JupyterLab 2.2.6, pandas 1.1.1., python 3.8.5. – Trenton McKinney Sep 1, 2020 at 6:57 Thanks @TrentonMcKinney I get extra spaces in my csv with the first code. I'm on Windows10, JupyterLab 2.2.4, pandas 1.1.1., python 3.8.5, winPython3.8.5 – Charles Sep 2, 2020 at 7:45 See the link to issue raised in winPython. github.com/winpython/winpython/issues/…. Overriding os.linesep = '\n' indicates that that is where the issue is. – Charles Sep 3, 2020 at 13:28

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.