This may sound a noob question, but I\'m stuck with it as Python is not one of my best languages.
I have a html page with a table inside it, and I would like to show
In case anyone finds this helpful. I have gone with an alternative because I needed more customization, including the ability to add buttons in the table that performed actions. I also really don't like the standard table formatting as it is very ugly IMHO.
...
df = pd.DataFrame({'Patient Name': ["Some name", "Another name"],
"Patient ID": [123, 456],
"Misc Data Point": [8, 53]})
...
# link_column is the column that I want to add a button to
return render_template("patient_list.html", column_names=df.columns.values, row_data=list(df.values.tolist()),
link_column="Patient ID", zip=zip)
HTML Code: This Dynamically Converts any DF into a customize-able HTML table
{% for col in column_names %}
{{col}}
{% endfor %}
{% for row in row_data %}
{% for col, row_ in zip(column_names, row) %}
{% if col == link_column %}
{% else %}
{{row_}}
{% endif %}
{% endfor %}
{% endfor %}
CSS Code
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #ffffdffffd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #ffffdffffd;
}
It performs very well and it looks WAY better than the .to_html output.