Modvinden
Modvinden

Reputation: 43

Reshaping dataframe with multiple IDs

I need helo creating the format transformation:

See here

I have created pd.wide_to_long but I cannot find an example identical to mine?

Can you help?

Upvotes: 1

Views: 26

Answers (1)

ansev
ansev

Reputation: 30930

Use:

df.set_index(['City','Var']).rename_axis(columns='Year').stack().unstack('Var')

Upvotes: 1

Related Questions