for line in s.split('\n'):
    line = line.strip()
if not re.match('^table', line):
    line = re.sub('^', 'table ', line)
new_style.append(line)
new_style = ['<style>'] + new_style + ['</style>']
style = re.sub('table(#\\S+)?', 'table#%s' % random_id, '\n'.join(new_style))
df_html = re.sub('<table', '<table id=%s ' % random_id, df_html)
return HTML(style + df_html)
Change the color of text within a pandas dataframe html table python using styles and css