From ef2825947379bbd96cc21e552c32264963a5adcf Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Thu, 8 Sep 2022 13:52:21 +0200 Subject: [PATCH] Fix crosstable for electrification in Benin --- _drivers-of-inequality-benin.qmd | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/_drivers-of-inequality-benin.qmd b/_drivers-of-inequality-benin.qmd index 6da54e8..fc5320b 100644 --- a/_drivers-of-inequality-benin.qmd +++ b/_drivers-of-inequality-benin.qmd @@ -210,8 +210,12 @@ totals = df.loc[ electricityaid = totals[totals['DONOR'] < 20000] # drop all 'total' aggregations el_grouped = electricityaid.groupby(['Year', 'Flow']).agg({'Value': ['sum']}) -el_grouped.style.format(escape="latex") -el_grouped +el_grouped = el_grouped.reset_index(['Year', 'Flow']) +el_grouped.columns = el_grouped.columns.to_flat_index() +el_grouped.columns = ['Year', 'Flow', 'Value'] + +crosstab = pd.crosstab(el_grouped['Year'], el_grouped['Flow'], margins=True, values=el_grouped['Value'], aggfunc='sum') +Markdown(tabulate(crosstab.fillna("0.00"), headers="keys", tablefmt="github", floatfmt=".2f")) ``` ::: {custom-style="caption"}