I'm trying to perform two things:
- Highlight 'NaN' values with red color for the dataframe.
- Add the dataframe to the PDF file.
I'm able to display the dataframe successfully in the PDF pages, however NaN values are not reflected with the red color inside the PDF.
I have tried following code:
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)
I have tried few other stuffs using seaborn also:
sns.heatmap(df.isna(), cmap=['red', 'white', 'white'])
I think, I need an option inside the ax.table to highlight the dataframe.
This can be done by creating a list of colors for
cellColorsin the ax.table function. To do this, we create a logical dataframecolor = df.isna(), replace the receivedTrueandFalsewith the colors we need, and convert it to a list. Example: