cannot write file with full path in Python

前端 未结 2 489
深忆病人
深忆病人 2021-01-07 07:22

I am using Pandas on Mac, to read and write a CSV file, and the weird thing is when using full path, it has error and when using just a file name, it works. I post my code w

2条回答
  •  心在旅途
    2021-01-07 08:14

    You didn't specify python version. On 3.4 you can use pathlib, otherwise use os.path.join() or quoting:

    sourceDf.to_csv(r'~/Downloads/newMaster.csv')
    

    Notice the r. The problem is that /n is newline, which is not allowed in a path.

提交回复
热议问题