Skip to content
Advertisement

pandas reshape multiple columns fails with KeyError

For a pandas dataframe of:

enter image description here

defined by:

JavaScript

I want to reshape to the following format:

JavaScript

A:

JavaScript

only results in a KeyError. How can I fix the reshape to work fine?

Advertisement

Answer

Here’s a way using stack:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement