Reputation: 1198
I have a Pandas dataframe with about 10 binary variables and I want to plot the zero and one counts in a stacked barchart using Seaborn. Anyone can help me how to do this?
Upvotes: 0
Views: 1414
Reputation: 863166
I think is possible create stacked bar in seaborn, but really complicated.
Simplier is use DataFrame.plot.bar
with parameter stacked=True
:
from collections import Counter
df = pd.DataFrame({'A':['1110','1111', '0000']})
print (df)
A
0 1110
1 1111
2 0000
#get counts of 0, 1
x = Counter([a for x in df['A'] for a in list(x)])
print (x)
Counter({'1': 7, '0': 5})
df = pd.DataFrame([x])
print (df)
0 1
0 5 7
df.plot.bar(stacked=True)
Upvotes: 2