python - How can I preserve a pandas multi-index between a to_excel() and a read_excel()? -


according pandas documentation read_excel, can put index column names on separate line , method which columns should used indices.

i want create excel file multi-indexed dataframe can read in such, can't figure out how pandas write to_excel in such way additional row created (from multi-indexed dataframe).

i can't imagine storing multi-indexed dataframe excel worksheet , pulling in later uncommon use case, i'm wondering if haven't figured out how this.

here's example of dataframe i'd 'freeze' in excel before reading in without having tell read_excel columns indices:

ipdb> my_df                              date         amount rec section             row                          0   top section         2    2015-05-01      -105.00 1   middle section      3    2015-05-04     90247.60 2   middle section      4    2015-05-05     -2992.99 3   bottom section      5    2015-05-08      -800.00 

in example, there 3 index columns: rec, section, , row.

when write excel , read in, don't want have tell this. since read_excel seems have method infers index names when appear on separate row, want have figure out (assuming correctly write excel file).

what missing?

i encountering same issue when trying write pivot table excel. able work modifying frame.py file in ../pandas/core. changing if self.columns.nlevels > 1 if self.columns.nlevels > 1 , not index got me needed.

as functionality still not supported pandas, may still encounter funny output. also, not solve issue read_excel either. helps little!

i referenced 'onesandzeros' in github comment.


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -