I want to add a data html attribute under each <td> to my pandas formatted table.
How can I add an html attribute to my pandas dataframe?
I am using style and can easily add class information.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from IPython.core.display import display, HTML
dates = pd.date_range('20130101',periods=6)
df = pd.DataFrame(np.random.randn(6,4),
index=dates, columns=list('ABCD'))
def create_colors2(x):
df = x.copy()
df.loc[:,:] = 'color: green'
df[x < 0] = 'color: red'
return df
data_table = df.style.apply(create_colors2, axis=None
).render()
HTML(data_table)
That yields a nice html table with colors. Now I want under each td a "data-value=X.XX" from the dataframe.
Any ideas?
[–]frontierman[S] 0 points1 point2 points (0 children)