I have a styled pandas DataFrame that I want to export to HTML with smaller rows than default. I don’t know much about CSS so I haven’t found a way to make it work so far. Can it be achieved and if so, how?
JavaScript
x
7
1
import pandas as pd
2
3
df = pd.DataFrame({"foo": [1, 2, 3], "bar": [4, 5, 6]})
4
styler = df.style
5
# Here I adjust a few styling options
6
html = styler.to_html()
7
Advertisement
Answer
Set the styles for row and data cell line height and reset the padding
JavaScript
1
5
1
styler.set_table_styles([
2
{"selector": "tr", "props": "line-height: 12px;"},
3
{"selector": "td,th", "props": "line-height: inherit; padding: 0;"}
4
])
5