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

SparseDataFrame to_csv returns IndexError: too many indices for array #19384

hannahlindsley opened this Issue Jan 24, 2018 · 1 comment


None yet
2 participants

hannahlindsley commented Jan 24, 2018

Calling to_csv on a SparseDataFrame returns IndexError: too many indices for array.

import pandas as pd
from scipy.sparse import rand

x = rand(100, 10001, density=0.2, format='csr')
df = pd.SparseDataFrame(x)

Calling .to_dense() on the df prior to writing out, of course, works fine.


I'd like to be able to save sparse data to disk. If for some reason it shouldn't be written out this way, is there any way to add that in the doc or the error message?

Expected Output

Nontype, no exception, and a csv on the file system.


commit: None
python-bits: 64
OS: Darwin
OS-release: 16.7.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None

pandas: 0.21.0
pytest: None
pip: 9.0.1
setuptools: 28.8.0
Cython: None
numpy: 1.13.3
scipy: 1.0.0
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: 2.1.0
psycopg2: (dt dec pq3 ext lo64)
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None


This comment has been minimized.


hexgnu commented Jan 29, 2018

I think I found the issue here. Made a PR for it. The problem is that get_values needs to be called internally since it's assuming something is an ndarray instead of a sparse array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment