无法在Jupyter笔记本中以HTML表格形式显示输出

时间:2018-10-29 11:11:57

标签: python html jupyter-notebook gurobi

我试图以HTML表格形式打印优化结果,但是它没有表格就打印结果,这意味着它应该看起来像实际的HTML表格。这是结果的快照。

enter image description here

到目前为止我尝试过的事情:

output = "<h1>Scheduling plan</h1><table><thead><tr><td></td><td><b>Only Electricity</b></td><td><b>Electricity and Hotwater</b></td><td><b>Gas</b></td><td><b>Avaible hotwater</b></td></tr></thead>"

for time in time_slots:
    output += "<tbody><tr><td><b>{}</b></td><td style='text-align: right'>".format(time)

    #only electricity
    for u in users:
        for app in appliances:
            for task in task_appliances[app]:
                if x[time, u, app, task].X>0:
                    output += "task<b>{}</b>of appliance<b>{}</b>of user<b>{}</b>at time slot<b>{}</b>uses only electricity<b>{}</b><br/>".format(task, app, u, time, x[time, u, app, task].X)

    #electricity and hotwater
    output += "</td><td style='text-align: right'>"
    for u in users:
        for app in appliances:
            for task in task_appliances[app]:
                if y[time, u, app, task].X>0:
                    output += "task<b>{}</b>of appliance<b>{}</b>of user<b>{}</b>at time slot<b>{}</b>uses electricity and hotwater<b>{}</b><br/>".format(task, app, u, time, y[time, u, app, task].X)
    #only Gas
    output += "</td><td style='text-align: right'>"
    for u in users:
        for app in appliances:
            for task in task_appliances[app]:
                if z[time, u, app, task].X>0:
                    output += "task<b>{}</b>of appliance<b>{}</b>of user<b>{}</b>at time slot<b>{}</b>uses only gas<b>{}</b><br/>".format(task, app, u, time, z[time, u, app, task].X) 

    #Available water in storage tank
    output += "</td><td style='text-align: right'>"
    if available_hotwater_storagetank[time].X>0:
        output += "Available hot water<b>{}</b>wH in storage tank at time slot<b>{}</b><br/>".format(available_hotwater_storagetank[time].X, time)  

    output += "</td></tr></tbody>"

output += "</table>"

from IPython.display import HTML, display
display(HTML(output))

f = open("output.html", "w+")
f.write(output)
f.close()

1 个答案:

答案 0 :(得分:0)

输出看起来像表中一样。 您可能要添加一些样式,边框颜色等。