python
Pandas DataFrame to CSV
# Use custom separator sep
df.to_csv('file_name.csv',sep='\t')
# Write without index index
df.to_csv('file_name.csv',index=False)
# Write without headers header
df.to_csv('file_name.csv',header=False)
# Write subset of columns columns
df.to_csv('file_name.csv',columns=['col_A','col_B'])
# Change file encoding format encoding
df.to_csv('file_name.csv',encoding='utf-8')
# Change NaNs as Unknown na_rep
df.to_csv('file_name.csv',na_rep='Unknown')
Was this helpful?
Similar Posts
- Pandas - How to check whether a pandas DataFrame is empty
- Pandas - Delete,Remove,Drop, column from pandas DataFrame
- Reorder dataframe columns using column names in pandas
- Convert pandas DataFrame to python collection - dictionary
- Convert pandas DataFrame to List of dictionaries python
- Convert a dictionary to pandas DataFrame in python
- Create pandas DataFrame and add columns and rows to it