Making histogram of object attribute of a DataFrame

Viewed 1812

I am making histogram from a dataset but observed that hist() works only for numerical data values. While I have some object type attributes in my dataframe, for example: Name, gender (possible values: male, female) etc.

I want to plot histogram for gender attribute of my dataset. How is that possible with .hist() or any other mechanism?

import matplotlib.pyplot as plt
from matplotlib.ticker import StrMethodFormatter

mydataFrame.hist(column = "Gender") 

"Gender" is an object type attribute.

1 Answers

Try

mydataFrame.gender.value_counts().plot(kind='bar');

value_counts() will make a series with the values of gender in the index, and the count as the values.

Related