Michael
Michael

Reputation: 5335

Read Excel file with blank cells as Pandas dataframe with multiindex

Suppose there is a Excel file:

enter image description here

Is there a way to read it directly as a Pandas dataframe with multiindex, without filling blank spaces in the first column?

Upvotes: 0

Views: 287

Answers (1)

Trenton McKinney
Trenton McKinney

Reputation: 62503

Data:

enter image description here

Code:

df = pd.read_excel('test.xlsx')

enter image description here

.ffill():

df.i0.ffill(inplace=True)

enter image description here

set_index():

df.set_index(['i0', 'i1'], inplace=True)

enter image description here

Upvotes: 2

Related Questions