Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Percentage of occurrences in a column using groupby in python pandas

[enter image description here]

1

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

df = df.groupby(["searchterm","brand"]).size().reset_index(name='count')

>Solution :

You should be able to use

df.groupby('searchterm')['brand'].value_counts(normalize=True)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading