Hello all,
I used the “processing.create_dataframe(om)” to generate a panda data frame and exported
it with the pd.ExcelWriter function.
The result looks like:
Is it possible to generate a panda dataframe which contains labels of oemof elements instead of pyomo tuples by using your
“processing.create_dataframe(om)”, because I would like to analyse the results in excel format. I already tried my best but I wasn’t able to change the processing code so I can produce the panda frame I want to have.
Thanks a lot!
Greetz
Steffen
You could try this to put the scalars/sequences of all nodes into single sheets of an Excel-file:
import pandas as pd
from oemof.outputlib import processing, views
# om is the optimization model which has been solved
result_data = processing.results(om)
result_data = views.convert_keys_to_strings(result_data)
xls_file = 'results.xls'
writer = pd.ExcelWriter(xls_file, engine='xlsxwriter')
# add regular optimization results
nodes = sorted(set([item for tup in result_data.keys() for item in tup]))
for n in nodes:
node_data = views.node(result_data, n)
n = n[:30] # trim string length to allowed chars for a worksheet
if 'scalars' in node_data:
node_data['scalars'].to_excel(writer, sheet_name=n+'_scalars')
if 'sequences' in node_data:
for key in keys:
if key in data['sequences']:
node_data['sequences'][key] = data['sequences'][key]
node_data['sequences'].to_excel(writer, sheet_name=n+'_sequences')
writer.save()
Cheers
Cord
Thank you Cord! That helps.
Greetz
Steffen
Finally i just used this and got all results
# om is the optimization model which has been solved
result_data = processing.results(om)
result_data = views.convert_keys_to_strings(result_data)
xls_file = 'TEST.xlsx'
writer = pd.ExcelWriter(xls_file, engine='xlsxwriter')
# add regular optimization results
nodes = sorted(set([item for tup in result_data.keys() for item in tup]))
for n in nodes:
node_data = views.node(result_data, n)
n = n[:10] # trim string length to allowed chars for a worksheet
if 'sequences' in node_data:
node_data['sequences'].to_excel(writer, sheet_name=n+'sequences')