df.drop('Element', axis=1) .query('Name != "" ') .assign(E_count = df['ID'].map(df['Element'].value_counts()))