Pandas Format

I've been working on a project where I look at the Github Actions costs for mayor open source projects. It turns out, these costs can be significant. In fact, they are so significant that my pandas tables no longer render in a clear manner in Jupyter.

Here's an example.

The table renders, but the dollar amounts are hard to read. It turns out though that pandas comes with a style formatter that can be used to render pretty values.

This is great for dollar amounts but it's a very flexible system. You can also add captions to the rendered table if you're interested.

(agg.style
 .format({'yearly_cost': '${0:,.2f}', 'daily_cost': '${0:,.2f}'})
 .set_caption("GitHub Actions costs for popular projets.")
 .set_table_styles([{
     'selector': 'caption',
     'props': 'caption-side: bottom; font-size:0.9em; color: gray;'
 }]))

You could even add a bit of interactivity, change the background color or change the color of the text by changing the css properties. It's a bit too much effort for my taste but the docs show a fancy demo in case you're interested.