[enter image description here]
Suppose I have multiple entries in a column search term, I want to calculate the percentage of occurrence of the brand. I know how to get the count of each brand but can someone suggest a way to get these in percentage?
df = df.groupby(["searchterm","brand"]).size().reset_index(name='count')
CodePudding user response:
You should be able to use
df.groupby('searchterm')['brand'].value_counts(normalize=True)