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

Find the most common word in a data frame column python

How do I find the most common first name from the column ‘First Name’ of my data set.

I have previously tried to use the mode function, however it was unfortunately not working. I am unsure what to do please help thank you very much.

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

>Solution :

I would do:

first_names = df['First Name']
most_common_name = first_names.value_counts().idxmax()

where df is a dataframe from a csv file, something you created on your own, etc.

Using mode wouldn’t work because that would give you the mode of each column rather than a single one that you’re looking for. Using value_counts would give you a specific count of how many times values appear in a specific column. Put that with idmax and it will only provide you the most common column value.

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