1

I want to produce a heatmap using matplolib and this pandas dataframe:

          class  time  day
0         URxvt     2    6
1         Emacs     3    6
2       Firefox    90    6
3     KeePassXC     5    6
4         URxvt    91    6
..          ...   ...  ...
144  Matplotlib     1    1
145  Matplotlib     1    1
146  Matplotlib     2    1
147  Matplotlib     5    1
148  Matplotlib    93    1

[149 rows x 3 columns]

I want to produce a heatmap with day (from 0 to 6 (but for the moment 0, 1 and 6)) on x-axis and class on y-axis, values are aggregate sums according to class and day). I tried to groupby these two columns which produces:

                          time
class               day       
Emacs               0     1149
                    1      130
                    6      634
Eog                 1       83
                    6       66
Evince              0      775
                    6       60
File-roller         0       40
Firefox             0    32109
                    1     6344
                    6     9887
GParted             1       25
Gedit               0       77
                    1        7
Gimp-2.10           6       25
Gmpc                1       73
Gnome-disks         1       21
Gtk-recordmydesktop 0       57
Gufw.py             6      100
KeePassXC           0       44
                    1       17
                    6      126
Matplotlib          1      151
Org.gnome.Nautilus  0      141
                    1      559
                    6       68
Scangearmp2         6       28
Totem               0       12
URxvt               0      346
                    1      488
                    6     3364
vlc                 0       22

but I can't get a proper heatmap (with X:day Y:class and values: time)

1 Answer 1

1

You can try:

sns.heatmap(df.groupby(['class','day'])['time'].sum()
              .unstack('day',fill_value=0)
           )

Output:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.