I used pandas df.value_counts() to find the number of occurrences of particular brands. I want to merge those value counts with the respective brands in the initial dataframe.>
Pandas DataFrame's merge and value_counts attributes are pretty fast, so I would combine the two.
df.merge(df['brand'].value_counts().to_frame(), how='left', left_on='brand', right_index=True, suffixes=('', 'x'))\ .rename(columns={'brandx':'brand_count'})