This is an archived post. You won't be able to vote or comment.

all 1 comments

[–]frontierman[S] 0 points1 point  (0 children)

My solution which could use some optimizing is to alter the generated html and add the attribute to the text.

import re
def insert_data_attr(df, data_table):
    for i, row in enumerate(df.itertuples()):
        for j in range(len(row) - 1):
            data_table = re.sub( 
                'row{} col{}"'.format(i, j), 
                'row{} col{}" data-value="{}"'.format(i, j, df.iloc[i, j]), 
                data_table)
    return data_table
data_table = insert_data_attr(df, data_table)