I am using python 3.9 on Spyder, I receive data frames from a source where I can not control how the data is received. However, I know that the data is grouped under a certain header. When trying to group the data using pandas it is failing. Below is an example of the received dataframes and the output needed.
and below is how I want it to be arranged.
Any ideas on how I can achieve this? Note that I have a very large amount of data so I am searching for a method with reduced memory usage.
Edit: I had a typo in name and age, I also added that the headers are different than name and age such as column1 and column2.

