Conform Series.to_csv to DataFrame.to_csv · Issue #19715 · pandas-dev/pandas (original) (raw)
Thank you for this awesome package!
Problem description
When indexing/selecting/slicing a DataFrame
, pandas may return a Series
. Both classes support the to_csv
method, but the methods have subtle differences. These subtle differences may break your code, or demand a call to to_frame
. Perhaps it would be beneficial to conform the Series.to_csv
method to the DataFrame.to_csv
method?
At least, the following two examples seem relevant (and are the reason I came here):
DataFrame.to_csv
accepts the keyword parameterpath_or_buf
. This seems to be completely analogous to the differently named keyword parameterpath
ofSeries.to_csv
.DataFrame.to_csv
accepts the keyword parameterline_terminator
. There does not seem to be an analogous keyword parameter ofSeries.to_csv
.
Addendum: Other differences
The following two keyword parameters are implemented for DataFrame.to_csv
, but not for Series.to_csv
: compression
, chunksize
. I suppose these are mostly relevant if you have very large dataframes, but I do not see any reason why they should not have analogous methods for Series.
Some of the keyword parameters of DataFrame.to_csv
are specific to multi-column data and may therefore not make immediate sense for Series.to_csv
. On the other hand, a user may wish to use quoting in a single-column file in order to maintain conformity with other parts of a bigger project. In this relation, the following keyword parameters are implemented for DataFrame.to_csv
but do not for Series.to_csv
: quoting
, quotechar
,doublequote
, escapechar
.
Output of pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.6.3.final.0
python-bits: 64
OS: Linux
OS-release: 4.13.0-32-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL:
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
pandas: 0.22.0
pytest: None
pip: 9.0.1
setuptools: 38.5.1
Cython: None
numpy: 1.14.0
scipy: None
pyarrow: None
xarray: None
IPython: 6.2.1
sphinx: None
patsy: None
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: 2.5.0
xlrd: 1.1.0
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
None