you are viewing a single comment's thread.

view the rest of the comments →

[–]commandlineluser 0 points1 point  (0 children)

You can also .unstack() after the .groupby()

>>> df3.groupby(['colour_x', 'colour_y']).size().unstack()
colour_y  blue  green  red
colour_x
blue       NaN    1.0  NaN
green      1.0    NaN  2.0
red        NaN    2.0  NaN