Writing a pandas DataFrame to CSV file

前端 未结 7 1825
死守一世寂寞
死守一世寂寞 2020-11-22 11:07

I have a dataframe in pandas which I would like to write to a CSV file. I am doing this using:

df.to_csv(\'out.csv\')

And getting the error

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-22 11:31

    Example of export in file with full path on Windows and in case your file has headers:

    df.to_csv (r'C:\Users\John\Desktop\export_dataframe.csv', index = None, header=True) 
    

    For example, if you want to store the file in same directory where your script is, with utf-8 encoding and tab as separator:

    df.to_csv(r'./export/dftocsv.csv', sep='\t', encoding='utf-8', header='true')
    

提交回复
热议问题