I am struggling with creating a pandas based html table that will look like the one in the attached picture. As you can see there are multiple table headers, colspans, rowspans, shadings, etc.
In more detail, I am developing a reporting system, and I want to be able to create engaging tables from data sets. The data sets themselves are just plain tables, but I want to be able to present them with multiple headers, grouping of repeating values, etc. I am currently using Jinja templates to do that, with some success but it is a very cumbersome solution. So I am looking for a way to use pandas instead but still be bale to use Jinja templates to a certain degree.
My question is, if anyone can point me to some material about doing that, and if there are existing tools that can be used along with pandas, to ease table formatting.
Many thanks
Oren
2
Answers
Just updating that pandas.io.formats.style.Styler gives me exactly what I wanted. It allows rendering dataframes into html while using jinja templates
I use css style to generate html format from dataframe, not sur whether this meet your request.
step1: prepare your dataframe
step2: create css file and save in same folder of .py file
step3: create html string to link the css file
step4: use dataframe.to(html) to add the dataframe into html file
below is my simple code, some private data is replace as XXXXX, you may use your own data instead
Python Code
CSS file data, I jsut copy+paste for other place, you may test as well.
css Code
#step2: create css file and save in same folder of .py file