pandas Pandas IO tools (reading and saving data sets) Save to CSV file


Example

Save with default parameters:

df.to_csv(file_name)

Write specific columns:

df.to_csv(file_name, columns =['col'])

Difault delimiter is ',' - to change it:

df.to_csv(file_name,sep="|")

Write without the header:

df.to_csv(file_name, header=False)

Write with a given header:

df.to_csv(file_name, header = ['A','B','C',...]

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

df.to_csv(file_name, encoding='utf-8')