Skip to content Skip to sidebar Skip to footer

Render Pandas Dataframe To Html Table With Row Seperators

I render a pandas multi-index into an html table. When rendering, after I passed a specific index X I want to add a separator line into the table. I can do this manually by editin

Solution 1:

You can groupby index and loop through it while adding the separator:

df = pd.DataFrame({"col1":list("AABBCCA"),"unit":[1,2,1,3,4,4,6]})

for _, data in df.groupby("col1"):
    print (data.to_html())
    print ('<td colspan="20" class="divider"><hr /></td>')

Result:

enter image description here

Post a Comment for "Render Pandas Dataframe To Html Table With Row Seperators"