Skip to content
Advertisement

Dataframe’s with strange structure with variables in even columns

I’m a beginner with python in combination with pandas, and I understand the basics. But I received a couple days ago 3 strange datasets in excel. As image below: enter image description here

JavaScript

I want the following result: enter image description here

JavaScript

I did try to loop the columns and create a new dataframe, but got stuck and think I make it unnecessary complex. I can’t get my head around it. Someone dealt with this before? and have a useful direction for me to go?

Advertisement

Answer

You can re-structure your data to your desired outcome with a rather simple manipulation. Note that I am using the dataframe (dfinput) you posted:

JavaScript

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