from pandas dataframe save csv file without double quotes
Asked Answered
P

1

10

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

Papp answered 21/8, 2018 at 9:42 Comment(0)
O
7
 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

Objectivity answered 21/8, 2018 at 10:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.