#strip dataframe to contain just name, favorite_colordf=df[['name','favorite_color']]#pivot the df (note that reset_index can be removed if we want to hold pivot levels. In most cases I reset the index)df_pivot=df.groupby(['favorite_color']).count().reset_index()#rename 'name' column to n-count of colorsdf_pivot.columns=['favorite_color','name']df_pivot.head()