Reputation: 10051
Given a excel file with the following format:
Reading with: df = pd.read_excel(file, header=[0,1], index_col=[0])
Out:
2018 2019
name quantity price quantity price
bj 10 2 6 5
sh 7 2 3 2
I want to manipulate the multi-index headers by filling the empty cell with year
and rename name
as city
.
How could I do that in Pandas?
Upvotes: 1
Views: 421
Reputation: 863281
df = df.rename_axis(columns=['year','city'])
If possible there is index name and necessary remove, set to None
:
df = df.rename_axis(columns=['year','city'], index=None)
Upvotes: 1