Pandas: Counting unique values in a dataframe,d.stack().groupby(level=0).apply(pd.Series.value_counts).unstack().fillna(0)