'Converting a data frame of events into a timetable format

I am working on converting a list of online classes into a heat map using Python & Pandas and I've come to a dead end. Right now, I have a data frame 'data' with some events containing a day of the week listed as 'DAY' and the time of the event in hours listed as 'TIME'. The dataset is displayed as follows:

ID   TIME        DAY
                  
108    15   Saturday
110    15     Sunday
112    16  Wednesday
114    16     Friday
116    15     Monday
..    ...        ...
639    12  Wednesday
640    12   Saturday
641    18   Saturday
642    16   Thursday
643    15     Friday

I'm looking for a way to sum repetitions of every 'TIME' value for every 'DAY' and then present these sums in a new table 'event_count'. I need to turn the linear data in my 'data' table into a more timetable-like form that can later be converted into a visual heatmap.

Sounds like a difficult transformation, but I feel like I'm missing something very obvious.

TIME   Monday   Tuesday   Wednesday   Thursday   Friday   Saturday   Sunday
                  
10       5         2          4           6         1        0         2
11       4         2          4           6         1        0         2
12       6         2          4           6         1        0         2
13       3         2          4           6         1        0         2
14       7         2          4           6         1        0         2

I tried to achieve this through pivot_table and stack, however, the best I got was a list of all days of the week with mean averages for time. Could you advise me which direction should I look into and how can I approach solving this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source