Let's say I have this table:
What I am looking for instead is something like this:
How can this be done in Python?