Pandas - Plotting a stacked Bar Chart
Solution 1:
Are you getting errors, or just not sure where to start?
%pylab inline
import pandas as pd
import matplotlib.pyplot as plt
df2 = df.groupby(['Name', 'Abuse/NFF'])['Name'].count().unstack('Abuse/NFF').fillna(0)
df2[['abuse','nff']].plot(kind='bar', stacked=True)
Solution 2:
That should help
df.groupby(['NFF', 'ABUSE']).size().unstack().plot(kind='bar', stacked=True)
Solution 3:
Maybe you can use pandas crosstab function
test5 = pd.crosstab(index=faultdf['Site Name'], columns=faultdf['Abuse/NFF'])
test5.plot(kind='bar', stacked=True)
Solution 4:
If you want to change the size of plot the use arg figsize
df.groupby(['NFF', 'ABUSE']).size().unstack()
.plot(kind='bar', stacked=True, figsize=(15, 5))