Quantcast
Viewing all articles
Browse latest Browse all 14040

Excel Pivot Export from Pandas Dataframe

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.

Val1Val2Val3Val5Val6Val7Val8Val9
L110040070000000
L220050080000000
L330060090000000
L500010001300000
L600011001400000
L700000190029003500
L800000200023003600
L900000210024003700
L1000000220028003900

Viewing all articles
Browse latest Browse all 14040

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>