[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')
You should be able to use
df.groupby('searchterm')['brand'].value_counts(normalize=True)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.