Suppose I have a DataFrame of created like this:
import pandas as pd
s1 = pd.Series([\'a\', \'b\', \'a\', \'c\', \'a\', \'b\'])
s2 = pd.Series([\'a\', \'f\',
Recreating the dataframe:
import pandas as pd
s1 = pd.Series(['a', 'b', 'a', 'c', 'a', 'b'])
s2 = pd.Series(['a', 'f', 'a', 'd', 'a', 'f', 'f'])
d = pd.DataFrame({'s1': s1, 's2': s2})
To get the histogram with subplots as desired:
d.apply(pd.value_counts).plot(kind='bar', subplots=True)
The OP mentioned pd.value_counts
in the question. I think the missing piece is just that there is no reason to "manually" create the desired bar plot.
The output from d.apply(pd.value_counts)
is a pandas dataframe. We can plot the values like any other dataframe, and selecting the option subplots=True
gives us what we want.