Skip to content
Advertisement

Writing a pandas DataFrame to CSV file

I have a dataframe in pandas which I would like to write to a CSV file.

I am doing this using:

JavaScript

And getting the following error:

JavaScript
  • Is there any way to get around this easily (i.e. I have unicode characters in my data frame)?
  • And is there a way to write to a tab delimited file instead of a CSV using e.g. a ‘to-tab’ method (that I don’t think exists)?

Advertisement

Answer

To delimit by a tab you can use the sep argument of to_csv:

JavaScript

To use a specific encoding (e.g. ‘utf-8’) use the encoding argument:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement