Writing a pandas DataFrame to CSV file

前端 未结 7 1830
死守一世寂寞
死守一世寂寞 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:33

    it could be not the answer for this case, but as I had the same error-message with .to_csvI tried .toCSV('name.csv') and the error-message was different ("SparseDataFrame' object has no attribute 'toCSV'). So the problem was solved by turning dataframe to dense dataframe

    df.to_dense().to_csv("submission.csv", index = False, sep=',', encoding='utf-8')
    

提交回复
热议问题