Reputation: 2507
I would like to take a dataframe, and produce a histogram with the column names as the x-axis and the count as the y-axis
Dataset:
sess lea opps
0 0 0
1 1 0
0 0 0
0 0 0
0 0 0
0 0 0
1 1 0
0 0 0
0 0 0
0 0 0
Upvotes: 1
Views: 2991
Reputation: 30920
you need:
import matplotlib.pyplot as plt
%matplotlib inline #only jupyter notebooks
then you can use to show the sum:
df.sum().plot(kind='bar')
to show the count of zeros and ones:
count=pd.concat([df.sum().rename('count_1'),df.eq(0).sum().rename('count_0')],axis=1)
print(count)
count.plot(kind='bar',stacked=True)
Output:
count_1 count_0
sess 2 8
lea 2 8
opps 0 10
Upvotes: 1
Reputation: 1019
Try this:
import matplotlib.pyplot as plt
counts = df.sum()
x, y = counts.index, counts.values
plt.bar(x, y)
You should get something like this:
Upvotes: 1