print( df.explode("categories") .pivot_table( index="item", columns="categories", aggfunc="size", fill_value=0 ) .reset_index() )