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.>
is that what you want:
import numpy as np
import pandas as pd
# generating random DataFrame
brands_list = ['brand{}'.format(i) for i in range(10)]
a = pd.DataFrame({'brands': np.random.choice(brands_list, 100)})
b = pd.DataFrame(np.random.randint(0,10,size=(100, 3)), columns=list('ABC'))
df = pd.concat([a, b], axis=1)
print(df.head())
# generate 'brands' DF
brands = pd.DataFrame(df.brands.value_counts().reset_index())
brands.columns = ['brands', 'count']
print(brands)
# merge 'df' & 'brands_count'
merged = pd.merge(df, brands, on='brands')
print(merged)
PS first big part is just a dataframe generation.
The part which is interesting for you starts with the # generate 'brands'
DF comment