I'm trying to streamline a process at work and ran into a problem with using Pandas Styler objects and PowerPoint.
Bottom line, the recipients don't want a Jupyter Notebook or even an HTML version of a Jupyter Notebook with the code hidden/removed. They want PowerPoint, no exceptions.
I've written a number of modules in Python to replicate the process and everything is in perfect working order except for the Pandas dataframes. The recipients want nice colorful tables and I've found a way to replicate exactly what they want. The below code gives me the exact table:
import pandas as pd
df = pd.DataFrame({'Col1': ['a', 'b', 'c', 'd'],
'Col2': ['e', 'f', 'g', 'h'],
'Col3': [1, 2, 3, 4]})
(df.style
.background_gradient(cmap='RdYlGn', subset='Col3')
.set_caption('Test'))
When running this in Juypter Notebooks I get exactly the output I want to have rendered in PowerPoint.
How do I take exactly what I'm looking at and get it into PowerPoint without taking a screenshot? The idea is to automate this as much as possible.
I've tried the Pandas.DataFrame.Styler.render()
method but I see no way to inject the raw HTML code into PowerPoint and get a rendered table without a separate plugin (not an option).
I also see no way to export the Styler object as an image so it seems that's out unless I missed it.
I did export it to Excel which does retain the cell coloring but loses number formatting (e.g. $100 turns back into 99.98573822839575) so that's out.
The best I've found is to use the wonderful python-pptx
package which does lots of great things with tables but I cannot find a way to use this package to import the Styler object into PowerPoint.
pd.__version__ = '0.24.2'
python.__version__ = '3.7.3'
jupyter.__version__ = '1.0.0'
notebook.__version__ = '5.7.8'
PowerPoint 2013 (15.0.5093.1000) MSO (15.0.5127.1000) 32-bit
Windows 10 Enterprise 10.0.16299 Build 16299