df.columns = pd.MultiIndex.from_tuples([('Mortgage', 'Interest'),
('Mortgage', 'Principal'),
('Mortgage', 'Extra Payment'),
('Mortgage', 'Loan Balance'),
('Investment', 'Payment'),
('Investment', 'Balance'),
('Appreciation', 'Balance'),
('Net Worth', 'w/o appr.'),
('Net Worth', 'with appr.')], names=['','Year'])
vmin = -interest_rate*principal
vmax = m_payment-interest_rate*principal
(df.style
.format('{:.0f}', na_rep="")
.bar(subset=pd.IndexSlice[df[df[('Mortgage', 'Interest')]<=0].index,('Mortgage', 'Interest')],
align='right', vmin=vmin, vmax=0, cmap="autumn",
height=80, width=80, props="width: 100px; border-right: 1px solid gray;"
)
.bar(subset=pd.IndexSlice[df[df[('Mortgage', 'Principal')]>=0].index,('Mortgage', 'Principal')],
align='left', vmin=0, vmax=m_payment, cmap="summer_r",
height=80, width=80, props="width: 100px; border-right: 1px solid gray;"
)
.bar(subset=[('Mortgage', 'Extra Payment')], align='left', vmin=0, vmax=lump_sum, cmap="summer_r",
height=80, width=80, props="width: 80px; border-right: 1px solid gray; border-left: 1px solid gray;"
)
.bar(subset=[('Investment', 'Payment')], align='left', vmin=0, vmax=max(lump_sum, m_payment), cmap="summer_r",
height=80, width=80, props="width: 80px; border-right: 1px solid gray; border-left: 1px solid gray;"
)
.bar(subset=[('Mortgage', 'Loan Balance')], align='right', vmin=-2.5*principal, vmax=0, cmap="PuRd_r",
height=80, width=100, props="width: 80px; border-right: 1px solid gray; border-left: 1px solid gray;"
)
.bar(subset=[('Appreciation', 'Balance')], align='left', vmin=0, vmax=2.5*principal, cmap="Blues",
height=80, width=100, props="width: 80px; border-right: 1px solid gray;"
)
.bar(subset=[('Investment', 'Balance')], align='left', vmin=0, vmax=2.5*principal, cmap="Blues",
height=80, width=100, props="width: 80px; border-right: 1px solid gray; border-left: 1px solid gray;"
)
.bar(subset=[('Net Worth', 'w/o appr.')], align='left', vmin=0, vmax=2.5*principal, cmap="Blues",
height=80, width=100, props="width: 80px; border-right: 1px solid gray;"
)
.bar(subset=[('Net Worth', 'with appr.')], align='left', vmin=0, vmax=2.5*principal, cmap="Blues",
height=80, width=100, props="width: 80px; border-right: 1px solid gray;"
)
.set_table_styles({
('Total:'): [{'selector': 'th', 'props': 'border-top: 1px solid gray; border-bottom: 1px solid gray'},
{'selector': 'td', 'props': 'border-top: 1px solid gray; border-bottom: 1px solid gray'}]
}, overwrite=False, axis=1)
.set_table_styles([
{'selector': 'table', 'props': 'border-spacing: 2px'},
{'selector': 'thead', 'props': 'border: 1px solid gray'},
{'selector': 'th', 'props': 'text-align: center; padding: 4.5px;'},
{'selector': 'th.col_heading', 'props': 'border: 1px solid gray'},
{'selector': 'tbody', 'props': 'border: 1px solid gray'},
{'selector': 'td', 'props': 'text-align: center; border-left: 1px solid gray; border-right: 1px solid gray;'}
], overwrite=False)
.set_table_styles({
('Investment', 'Balance'): [{'selector': 'th', 'props': 'border-right: 1px solid gray'},
{'selector': 'td', 'props': 'border-right: 1px solid gray'}]
}, overwrite=False, axis=0)
)