Replies: 4 comments
-
Give them tables, and they will want singing, dancing, and jingling tables... 🌟🔔👯🎵🎆 The most banal obstacle to this is that our tables currently don't support rowspan. As usual in a situation like this: PRs welcome! 😉 |
Beta Was this translation helpful? Give feedback.
-
A workaround: import seaborn as sns
df = sns.load_dataset('tips')
df = (
df.groupby(['sex', 'smoker', 'time'])[['tip', 'size', 'total_bill']]
.mean().round(1).reset_index()
.pivot(index=['smoker', 'time'], columns=['sex'])
).reset_index().astype('str')
levels = df.columns.nlevels
df.columns.names = [None]*levels
columns = [df.columns.get_level_values(l).tolist() for l in range(levels)]
rows = df.values.tolist()
data = columns + rows
with pdf.table(
line_height=pdf.font_size * 2,
text_align='RIGHT',
width=160
) as table:
for data_row in data:
row = table.row()
for datum in data_row:
row.cell(datum) |
Beta Was this translation helpful? Give feedback.
-
For the record, there has been a follow-up of this discussion in #970 |
Beta Was this translation helpful? Give feedback.
-
Another workaround is using from fpdf import FPDF
import seaborn as sns
pdf = FPDF()
pdf.set_font_size(16)
pdf.add_page()
df = sns.load_dataset('tips')
string_html = (
df.groupby(['sex', 'smoker', 'time'])[['tip', 'size', 'total_bill']]
.mean().round(1).reset_index()
.pivot(index=['smoker', 'time'], columns=['sex'])
).reset_index().to_html()
pdf.write_html(string_html)
pdf.output('table-pdf.pdf') |
Beta Was this translation helpful? Give feedback.
-
It looks like this in a Jupyter notebook environment:
I would like to write a table like this in a PDF:
(Please disregard the double/cell borders above. I am unsure how to control them in HTML. Single borders work fine for me)
I found an example here, but it doesn't work on a multi-index dataframe, which is common when generating summary statistics. I'm wondering if someone could help me with this.
Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions