question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DataFrame.to_csv with empty dataframe probleme quoting

See original GitHub issue

Code Sample, a copy-pastable example if possible

>>>import pandas as pd
>>> pd.DataFrame([""]).to_csv("/tmp/test.csv", header= False, index= False, quoting=3)
[...]Error: single empty field record must be quoted

Problem description

I cannot get an empty csv. There is allways quote for the first row

Expected Output

I should get a csv with an empty row.

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.6.0.final.0 python-bits: 64 OS: Linux OS-release: 4.8.0-45-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: fr_FR.UTF-8 LOCALE: fr_FR.UTF-8

pandas: 0.19.2 nose: 1.3.7 pip: 9.0.1 setuptools: 27.2.0 Cython: 0.25.2 numpy: 1.12.0 scipy: 0.18.1 statsmodels: 0.6.1 xarray: None IPython: 5.1.0 sphinx: 1.5.2 patsy: 0.4.1 dateutil: 2.6.0 pytz: 2016.10 blosc: None bottleneck: 1.2.0 tables: 3.3.0 numexpr: 2.6.1 matplotlib: 2.0.0 openpyxl: 2.4.1 xlrd: 1.0.0 xlwt: 1.2.0 xlsxwriter: 0.9.6 lxml: 3.7.2 bs4: 4.5.3 html5lib: None httplib2: 0.10.3 apiclient: 1.6.2 sqlalchemy: 1.1.5 pymysql: None psycopg2: None jinja2: 2.9.4 boto: 2.45.0 pandas_datareader: None

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
jrebackcommented, Apr 4, 2017

I think this is a bug, so marked. @parisni welcome to have a PR to fix! (code is actually not bad for writing csvs…)

0reactions
mroeschkecommented, May 8, 2021

This looks fixed on master. Could use a test

In [3]: In [8]: pd.DataFrame([None, None]).to_csv(None, header= False, index= False, na_rep='')
Out[3]: '""\n""\n'
Read more comments on GitHub >

github_iconTop Results From Across the Web

pandas to_csv output quoting issue - Stack Overflow
It says: quoting : int, Controls whether quotes should be recognized. Values are taken from csv.QUOTE_* values. Acceptable values are 0, 1 ...
Read more >
Pandas Write DataFrame to CSV - Spark by {Examples}
By using pandas.DataFrame.to_csv() method you can write/save/export a pandas DataFrame to CSV File. By default to_csv() method export DataFrame to a CSV.
Read more >
Pandas to_csv() - Convert DataFrame to CSV - DigitalOcean
Pandas DataFrame to_csv () function converts DataFrame into CSV data. ... representing null or missing values, default is empty string.
Read more >
pandas.DataFrame.to_csv — pandas 0.19.1 documentation
[source]¶. Write DataFrame to a comma-separated values (csv) file ... quoting : optional constant from csv module. defaults to csv.QUOTE_MINIMAL.
Read more >
How to read a CSV file to a Dataframe with custom delimiter in ...
squeeze, If True and only one column is passed then returns pandas series ; skiprows, This parameter is use to skip passed rows...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found