close

How to make a histogram from a list of strings in Python?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to make a histogram from a list of strings in Python in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to make a histogram from a list of strings in Python?

  1. How to make a histogram from a list of strings in Python?

    Very easy with Pandas.
    import pandas from collections import Counter a = ['a', 'a', 'a', 'a', 'b', 'b', 'c', 'c', 'c', 'd', 'e', 'e', 'e', 'e', 'e']

  2. make a histogram from a list of strings in Python

    Very easy with Pandas.
    import pandas from collections import Counter a = ['a', 'a', 'a', 'a', 'b', 'b', 'c', 'c', 'c', 'd', 'e', 'e', 'e', 'e', 'e']

Method 1

Very easy with Pandas.

import pandas
from collections import Counter
a = ['a', 'a', 'a', 'a', 'b', 'b', 'c', 'c', 'c', 'd', 'e', 'e', 'e', 'e', 'e']
letter_counts = Counter(a)
df = pandas.DataFrame.from_dict(letter_counts, orient='index')
df.plot(kind='bar')

Notice that Counter is making a frequency count, so our plot type is 'bar' not 'hist'.

histogram of letter counts

Method 2

here’s a concise all-pandas approach:

a = ['a', 'a', 'a', 'a', 'b', 'b', 'c', 'c', 'c', 'd', 'e', 'e', 'e', 'e', 'e']
pd.Series(a).value_counts().plot('bar')
barplot of counts

Conclusion

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read