To delimit by a tab you can use the sep argument of to_csv:
df.to_csv(file_name, sep='\t')
To use a specific encoding (e.g. 'utf-8') use the encoding argument:
df.to_csv(file_name, sep='\t', encoding='utf-8')
In many cases you will want to remove the index and add a header:
df.to_csv(file_name, sep='\t', encoding='utf-8', index=False, header=True)
Answer from Andy Hayden on Stack OverflowHow to create a csv file from text
Create and load CSV over the internet with pandas
Writing to CSV with pandas
When to save as CSV if using Pandas data frame?
To delimit by a tab you can use the sep argument of to_csv:
df.to_csv(file_name, sep='\t')
To use a specific encoding (e.g. 'utf-8') use the encoding argument:
df.to_csv(file_name, sep='\t', encoding='utf-8')
In many cases you will want to remove the index and add a header:
df.to_csv(file_name, sep='\t', encoding='utf-8', index=False, header=True)
When you are storing a DataFrame object into a csv file using the to_csv method, you probably wont be needing to store the preceding indices of each row of the DataFrame object.
You can avoid that by passing a False boolean value to index parameter.
Somewhat like:
df.to_csv(file_name, encoding='utf-8', index=False)
So if your DataFrame object is something like:
Color Number
0 red 22
1 blue 10
The csv file will store:
Color,Number
red,22
blue,10
instead of (the case when the default value True was passed)
,Color,Number
0,red,22
1,blue,10
I made a python program that can read a csv and replace it with new values.
I do this with pandas.read_csv() and .to_csv() locally, also works with an http for google drive when reading but not when replacing with to_csv().
I there some free database where I can have my file and do both operations through my program?