Series.to_csv quotechar missing or to_csv wrong behaviour
See original GitHub issueCode Sample, a copy-pastable example if possible
import pandas as pd
pd.Series(['x','x,x']).to_csv('my_file.txt', index=False)
The result of this code when you open the file my_file.txt
is:
x
"x,x"
Expected Output
I think that either A) we decide that Series.to_csv
doesn’t quote and the expected output is
x
x,x
or B) we decide that Series.to_csv
quotes in the same way as DataFrame.to_csv
in which case I would expect that Series.to_csv
can take argument quotechar
.
output of pd.show_versions()
INSTALLED VERSIONS
------------------
commit: None
python: 2.7.9.final.0
python-bits: 64
OS: Linux
OS-release: 3.19.0-68-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_GB.UTF-8
pandas: 0.18.1
nose: 1.3.4
pip: 1.5.6
setuptools: 26.1.1
Cython: None
numpy: 1.8.2
scipy: 0.14.1
statsmodels: None
xarray: None
IPython: 5.1.0
sphinx: None
patsy: None
dateutil: 2.2
pytz: 2015.7
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.4.2
openpyxl: 2.3.5
xlrd: 1.0.0
xlwt: None
xlsxwriter: None
lxml: 3.4.2
bs4: 4.3.2
html5lib: 0.999
httplib2: 0.9.2
apiclient: 1.5.3
sqlalchemy: 0.9.8
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.34.0
pandas_datareader: None
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Python Pandas export to csv not correctly handling escaping
I have the following problem: i read a csv with the following sequence \"\\\" which pandas reads correctly (because if i print the...
Read more >Pandas to_csv() - Convert DataFrame to CSV - DigitalOcean
Pandas DataFrame to_csv() function converts DataFrame into CSV data. We can pass a file object to write the CSV data into a file....
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.Series.to_csv — pandas 1.5.2 documentation
Character used to escape sep and quotechar when appropriate. ... os.makedirs('folder/subfolder', exist_ok=True) >>> df.to_csv('folder/subfolder/out.csv').
Read more >Python Pandas read_csv: Load Data from CSV Files
The use of the quotechar allows the “NickName” column to contain semicolons ... When data is exported to CSV from different systems, missing...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Would there be any interest in a
to_string
which accepts filenames? If not I guess we can have this closed. I wouldn’t mind implementing it.Got it. So why does
to_string
only accept a buffer butto_csv
accepts either a buffer or a filename path?