Skip to content

to_csv does not quote fields with special characters #3503

@bmacauley

Description

@bmacauley

I am using pandas 0.11.in python 2.7.3

I am processing csv data with windows line terminators in some of the field data. The input data is properly quoted(with QUOTE_MINIMAL )

when writing the data using to_csv, pandas does not quote the fields with windows line terminators ie not using QUOTE_MINIMAL ?

test3.csv

Id,Description,Field1,Field2
1,"test data 1 ^M\n",2,3
2,"test data 2 ^M\n",3,4

In [93]: in_csv = 'test3.csv'

In [94]: cols = ['Id', 'Description', 'Field1', 'Field2']

In [95]: reader = pd.read_csv(in_csv, usecols=cols, dtype=object)

In [96]: print reader
  Id       Description Field1 Field2
0  1  test data 1 \r\n      2      3
1  2  test data 2 \r\n      3      4

In [97]: reader.to_csv(out_csv, index=False, encoding='utf-8')

Id,Description,Field1,Field2
1,test data 1 ^M\n,2,3
2,test data 2 ^M\n,3,4

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIO CSVread_csv, to_csvIO DataIO issues that don't fit into a more specific labelOutput-Formatting__repr__ of pandas objects, to_string

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions