I have multiple functions that generate multiple data frames of different lengths, I am aiming to consolidate all of them in one place and later pivot it out and export to Excel, here is an example of three different output data frames from three functions.
import pandas as pddata1 = {'Header':['L1','L2','L3'], 'Val1':[float(100),float(200),float(300)],'Val2':[float(400),float(500),float(600)], 'Val3': [float(700),float(800),float(900)]}data1_summary = pd.DataFrame(data=data1)# Inside loop it'll create two more such outputs but with different values but with the same labels.data2 = {'Header':['L5','L6'], 'Val5':[float(1000),float(1100)],'Val6':[float(1300),float(1400)]}data2_summary = pd.DataFrame(data=data2)data3 = {'Header':['L7','L8','L9','L10'], 'Val7':[float(1900),float(2000),float(2100),float(2200)],'Val8':[float(2900),float(2300),float(2400),float(2800)], 'Val9': [float(3500),float(3600),float(3700),float(3900)]}data3_summary = pd.DataFrame(data=data3)
There are different 'Headers' in all three outputs, similarly, there are different labels 'Val1' to 'Val9' and there are corresponding values against each of them, If we output everything in a sheet (i.e.,data1_summary,data2_summary,data3_summary) it'll be like a grid and later we can perform pivot on that data.
The expected output is as follows.
Val1 | Val2 | Val3 | Val5 | Val6 | Val7 | Val8 | Val9 | |
---|---|---|---|---|---|---|---|---|
L1 | 100 | 400 | 700 | 0 | 0 | 0 | 0 | 0 |
L2 | 200 | 500 | 800 | 0 | 0 | 0 | 0 | 0 |
L3 | 300 | 600 | 900 | 0 | 0 | 0 | 0 | 0 |
L5 | 0 | 0 | 0 | 1000 | 1300 | 0 | 0 | 0 |
L6 | 0 | 0 | 0 | 1100 | 1400 | 0 | 0 | 0 |
L7 | 0 | 0 | 0 | 0 | 0 | 1900 | 2900 | 3500 |
L8 | 0 | 0 | 0 | 0 | 0 | 2000 | 2300 | 3600 |
L9 | 0 | 0 | 0 | 0 | 0 | 2100 | 2400 | 3700 |
L10 | 0 | 0 | 0 | 0 | 0 | 2200 | 2800 | 3900 |