-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
multiindex column in to_excel #2701
Comments
Both to_excel and to_csv should allow a multiindex on the columns to print on multiple rows |
I guess then read_csv would have to take a list for the header argument to reconstruct the mi |
#2478, this is already hiding in the codebase, just needs some TLC. |
yes, definitely. |
I think that has been fixed by #5423: import pandas as pd
m = pd.MultiIndex.from_tuples([(1,1),(1,2)], names=['a','b'])
df = pd.DataFrame([[1,2],[3,4]], columns=m)
df.to_excel('test.xls') Output: Can we close this? |
Hi all, I'm trying to write a multiindex dataframe to Excel using the example above, and not getting the same results. Code:
There's an extra line being added-- different than the output generated above. I'm using pandas version 0.19.2 on Ubuntu 14.04 and have also experienced this on Windows 10. I've tried this using pandas version 0.15.0 and it works properly, replicating the output above: Is this a bug? And if so, can we re-open this issue? Thanks, Charlie |
@mappingvermont I'm getting the same result with a real example. I think it is a bug. Using latest version pandas 0.19.2 |
@jreback Can this be reopened? I also get this problem. I've commented this on #6618, which seems related. From what I can see, the problem is that pandas is reserving the first column of the header rows to the MultiIndex, and creates a new line for the row index name even if it is unnamed: >>> df = pd.DataFrame([[1,2,3],[4,5,6]], columns=pd.MultiIndex.from_tuples([('A'
,''),('B','C'),('B','D')]))
>>> df.to_excel("out.xlsx", index_label="Foo") This bug was fixed some time ago for simple columns, but it was probably not a very good solution, since it is still buggy for MultiIndex columns: >>> df = pd.DataFrame([[1,2,3],[4,5,6]], columns=['A','B','C'])
>>> df.to_excel("out.xlsx", index_label="Foo") Version information:
|
@jreback still got the same problem for the multi-index, wish this issue can be reopened. |
Same here, I will open a new issue and try to find the problem |
@etiennecaldo Did you open the issue? |
@Ronkiro no I workarounded it on my side...! |
This still appears to be an issue for multi-index columns (pandas 0.24.2) - is there any way this can be re-opened? data = [[1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12]]
multi_index = pd.MultiIndex.from_product([['a', 'b'], ['one', 'two', 'three']])
df = pd.DataFrame(data, columns=multi_index_one, index=[1, 2])
df.to_excel('test_files/test.xlsx') pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.6.6.final.0
python-bits: 64
OS: Darwin
OS-release: 18.6.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: None
LOCALE: en_IE.UTF-8
pandas: 0.24.2
pytest: 4.1.1
pip: 18.1
setuptools: 40.6.3
Cython: 0.28.2
numpy: 1.15.4
scipy: 1.1.0
pyarrow: 0.11.1
xarray: None
IPython: 7.2.0
sphinx: None
patsy: 0.5.1
dateutil: 2.7.5
pytz: 2018.7
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 3.0.2
openpyxl: None
xlrd: 1.2.0
xlwt: None
xlsxwriter: 1.1.8
lxml.etree: 4.3.0
bs4: 4.7.1
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: 0.2.0
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None |
I got the same issue with a dataset with multiple column and row indizes and would really appreciate a solution.
|
Same issue with pandas 0.25.0
|
Rather than replying to a feature request issue that was implemented and closed 6 years ago it would probably be best to open a new issue with an example(s) that demonstrate the issue. |
For reference, this issue has been created and can be found at #27772 . For any more comments, please post there. |
link to #1651
Saving a multiindex column to_excel saves a sparse index.
Migrated from this StackOverflow question, with a smaller DataFrame.
Saves the xls:
This differs from how
to_csv
(which is not sparse):The text was updated successfully, but these errors were encountered: