-
-
Notifications
You must be signed in to change notification settings - Fork 19.1k
Description
df = pd.DataFrame.from_dict({1:'Single line', 2:'Multiline \n with bkslash_N', 3:'Multiline \r with bkslash_R'}, orient="index", columns=['text'])
df.to_csv()
',0\n1,Single line\n2,"Multiline \n with bkslash_N"\n3,Multiline \r with bkslash_R\n'
No quotes on line 3
Problem description
When text has '\r' as a line separator, pandas.to_csv()
does not consider such text as multiline and does not surround it with quotes. As a result such CSV files are incompatible other parsers.
Expected Output
The text around "Multiline \r with bkslash_R" should be quoted
',0\n1,Single line\n2,"Multiline \n with bkslash_N"\n3,"Multiline \r with bkslash_R"\n'
Output of pd.show_versions()
INSTALLED VERSIONS
commit : b5958ee
python : 3.6.12.final.0
python-bits : 64
OS : Darwin
OS-release : 20.3.0
Version : Darwin Kernel Version 20.3.0: Thu Jan 21 00:07:06 PST 2021; root:xnu-7195.81.3~1/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.1.5
numpy : 1.19.5
pytz : 2021.1
dateutil : 2.8.1
pip : 20.3.3
setuptools : 52.0.0.post20210125
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.3
IPython : 7.16.1
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : 0.8.5
fastparquet : None
gcsfs : None
matplotlib : 3.3.4
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 3.0.0
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.5.4
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None