-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: to_csv doesn't support file handles from ZipFiles #35058
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Part of the challenge in supporting file handlers that require from pandas import DataFrame
with open("output.csv", "w+b") as f:
DataFrame([1, 2, 3]).to_csv(f) If you can find a way to do that, then we'll be all set! |
One approach would be to push this responsibility to the user. Would it be reasonable to require Unfortunately, it seems that from pandas import DataFrame
DataFrame([1, 2, 3]).to_csv("output.csv", mode="w+b")
|
At the moment, yes, but you're more than welcome to try modifying that logic to so that the argments to |
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Code Sample, a copy-pastable example
Last part of the stack trace:
Problem description
I know that
to_csv
supports compression but I want to write a DataFrame into a zip file with multiple other files. I'm not sure whether the above error is an error in pandas or a missing feature/bug in zipfiles.Expected Output
to_csv
supports writing to a ZipFile's file handle.Output of
pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.8.3.final.0
python-bits : 64
OS : Linux
OS-release : 3.10.0-693.5.2.el7.x86_64
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.0.4
numpy : 1.18.4
pytz : 2020.1
dateutil : 2.8.1
pip : 20.1.1
setuptools : 47.1.1.post20200529
Cython : None
pytest : 5.4.3
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.15.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : 3.2.1
numexpr : 2.7.1
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : 5.4.3
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : None
tables : 3.6.1
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None
The text was updated successfully, but these errors were encountered: