Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

from pandas dataframe save csv file without double quotes

To save a csv file from pandas dataframe I have tried following way:

res.to_csv('seq_test.fa',header= False, index= False, sep = '\t', quoting = csv.QUOTE_NONE)

and this gives me following error:need to escape, but no escapechar set

If I don't use quoting = csv.QUOTE_NONE . I get output below way:

>His-ATG-1-1    33-35
"TGGGGTATAGCTCCATGGTAGAGCGCATGCCTATGAAGCGTGAGGTCCTGGGTTTGATCCCCAGAACCACAACCA
"   
>Pro-AGG-2-1    33-35
"GGCTTGTTGGTCTAGGGGTATGATTCTCACTTAGGGTGTGAGAGGTCCTGGGTTCAAATCTTGGACGAGTCCCCA
"   
>Lys-TTT-1-1    34-36
"GCCCGGATAGCTCAGTCGGTAGAGCATCAGACTTTTAATCTGAGGGTCCAGGGTTCAAGTCCCTGTTCGGGCGCCA
"   
>Ile-TAT-3-1    34-36
"GGTTCCATAGGGTAGTGGTTATCACATCTGCTTTATATGCAGAAGGTCCTGAGTTTGAGCCCCAGTGGAACTACCA
"

Here I don't want any double quotes in my output. Can someone suggest me any possible way? If anycase required I am using pandas version 0.17 on python 2.7

like image 890
KR12 Avatar asked Aug 21 '18 09:08

KR12


1 Answers

 res.to_csv('seq_test.fa',header= False, index= False, sep = '\t', quoting = csv.QUOTE_NONE, escapechar = ' ')

Fill in the escapechar with whatever character is appropriate.

Reference: https://pandas.pydata.org/pandas-docs/version/0.17.0/generated/pandas.DataFrame.to_csv.html

like image 76
ericstenberg Avatar answered Sep 28 '22 05:09

ericstenberg