df.groupby(['id', 'group', 'term']).size().unstack(fill_value=0)