import subprocess f=open("dfAccountSummary.html", "w+") html = """ Hello, world! {0} """.format(botStats.T.to_html()) html = html.replace('border="1" class="dataframe"','class="table table-sm table-striped"').replace('','') f.write(html) f.close() process = subprocess.run(["wkhtmltoimage","dfAccountSummary.html", "out.png"], check=True, stdout=subprocess.PIPE, universal_newlines=True) process.stdout