This notebook does not use Tatoeba data. Instead, it provides some functions that you may want to use in other notebooks. You can check how to:
Run the following cell to be able to run the examples.
import pandas as pd
It is very simple to write a dataframe to a CSV file.
Suppose you have the following dataframe
df = pd.DataFrame({'name': ['Raphael', 'Donatello'],
'mask': ['red', 'purple'],
'weapon': ['sai', 'bo staff']})
df
You can use the to_csv
function to write your dataframe to a CSV file. If you have some Python knowledge, you can check the documentation. Otherwise, the following examples are the most used.
After running the to_csv
function, go back to the Home
page. All files in the current folder are displayed there, so you should see your Data_export.csv
file. If you want to download it, simply check the box on its left and click the Download
button at the top of the list.
Simply specify the name of the file you want to create.
df.to_csv('Data_export.csv')
This will give you the following content
!cat 'Data_export.csv'
The index of a dataframe is the first column on the left (in bold). In some situations, it is a useless information so you can ignore it when you export your data to a file. To do so, add the index=False
parameter.
df.to_csv('Data_export.csv', index=False)
This will give you the following content
!cat 'Data_export.csv'
If you don't need the column headers, add the header=None
parameter.
df.to_csv('Data_export.csv', index=False, header=None)
This will give you the following content
!cat 'Data_export.csv'
The default separator is the comma ,
(hence, CSV :) ). If you want to change it, you can use sep='<character>'
. Note: a tabulation is represented by \t
.
df.to_csv('Data_export.csv', index=False, header=None, sep='\t')
This will give you the following content
!cat 'Data_export.csv'