+1 vote
388 views
Hi, is it possible to export results as excel via olca-ipc.py ?
in Miscellaneous by (180 points)

1 Answer

+2 votes
by (610 points)
selected by
 
Best answer

I have used pandas dataframes and associated export features for this. In OLCA 1.11 there was an export to excel function that I have not seen in 2.02. here is a section of the code:

def export_total_result(result):
    data = [
      (item.impact_category.name, item.impact_category.ref_unit, item.amount)
      for item in result.get_total_impacts()
    ]
    df = pd.DataFrame(data, columns=["impact_category", "ref_unit", "amount"])
    # df.to_excel("output1.xlsx", sheet_name='Impacts',startcol=1, startrow=1,index=False)
    return df
I have other similar functions, but for space don't post here.
then after result is calculated, the code below will write to excel
......
        tot_impact_df = export_total_result(result)
        #flow_impact_df = export_flow_cat(result)
        #proc_impact_df = export_proc_cat(result,'flow')
        #info_df = export_setup(setup, farm)
        with pd.ExcelWriter(fName) as writer:
            #info_df.to_excel(writer,sheet_name='Setup info',index=True)
            tot_impact_df.to_excel(writer, sheet_name='Impacts',  startcol=1,startrow=1,index=False)
            #flow_impact_df.to_excel(writer, sheet_name='Flow impact contributions', startcol=2,startrow=1,index=False)
            #proc_impact_df.to_excel(writer, sheet_name='Process impact contributions',startcol=2,startrow=1, index=False)
by (180 points)
Thanks a lot! Nice piece of code :)
...