为什么门罗币拥有尾部增发的特性
811 2023-04-03 04:36:01
我们已知一个DataFrame记录了模型Model1、Model2在3个Epoch优化中的精度变化情况:
frame = pd.DataFrame({"Model1": [0.620, 0.832, 0.902], "Model2": [0.683, 0.867, 0.835]}, index=\ ["Epoch {}".format(r + 1) for r in range(3)]).print(frame)# Model1 Mode2# Epoch 1 0.620 0.683# Epoch 2 0.832 0.867# Epoch 3 0.902 0.835
现在我们像将其输出为html,我们可以这么做:
frame.to_html("Pandas/cluster_log.html")
浏览器打开效果如下:
我们发现这样并不美观。我们想要去除掉表格的边框,并使每个单元格对齐,可以为表格设置style
属性再输出:
frame = frame.style.set_properties(**{'background-color': 'white', "align":"center"}) ## **表示以关键字参数传参,等效于background-color=white形式frame.to_html("Pandas/cluster_log.html")
如果我们想对各模型迭代过程中取得的最大精度进行高亮,可以调用apply()
方法并传入一个回调函数:
def highlight_max(series): #遍历frame的每一列(series)依次设置效果 is_max = series == series.max() return ['background-color: yellow' if value else '' for value in is_max]frame = frame.style.apply(highlight_max) frame.to_html("Pandas/highlight_cluster_log.html")
浏览器打开效果如下: