我想做两件事:
- 用红色突出显示数据帧的‘NaN’值.
- 将数据帧添加到PDF文件.
我能够在PDF页面中成功地显示dataframe
个值,但是NaN
个值不会在PDF中反映为红色.
我try 了以下代码:
df.style.highlight_null('red')
with PdfPages('stale_curve_report.pdf') as pdf:
fig, ax = plt.subplots()
ax.axis('off')
ax.table(cellText=df.values, colLabels=df.columns, rowLabels=df.index, loc='center',colWidths=[0.12] * 15)
pdf.savefig(fig)
plt.close(fig)
我还试过其他几种方法:
sns.heatmap(df.isna(), cmap=['red', 'white', 'white'])
我想,我需要ax.table
中的一个选项来突出显示数据帧.