When saving a dataframe to csv or excel, pandas will automatically add a first column as row index. I know there's a index=False
argument to avoid this. However, if my dataframe have multiple column index, the error shows:
NotImplementedError: Writing to Excel with MultiIndex columns and no index ('index'=False) is not yet implemented.
Is there another way to skip this first column while keeping the multi-level column name for the header rows inside the excel file?
An example code to generate the dataframe:
import pandas as pd
import numpy as np
col = pd.MultiIndex.from_arrays([['one', 'one', 'one', 'two', 'two', 'two'],
['a', 'b', 'c', 'a', 'b', 'c']])
data = pd.DataFrame(np.random.randn(4, 6), columns=col)
data.to_excel('test.xlsx')
And open the excel file you'll see:
I would like to keep B1:G2
as my column name structure and drop the A:A
(and also A3:G3
). Thank you for any help~.