This is a follow-up question for a question I asked previously. The old question can be found here, I received an answer from @jezrael.
Now I want to plot the grades.
For plotting all grades I can do
counts_gardes = df1['new'].value_counts(sort=False)
counts_gardes.plot(kind='bar')

However, I could not figure out how to plot per grade group including zero counts.
counts_gardes_group = df1['new'].value_counts(sort=False)
counts_gardes_group.plot(kind='bar')

I would like to also include zero counts for F in the plotted figures. I tried the solutions provided in here, here and here but they did not work. The first returns all grades, while the latter gives an error stating that index does not have levels.
Any help is really appreciated.
You can use Series.reindex with swap order (if necessary) of list of all grades and if not match replace to 0:
grade_leters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'D+', 'D','D-', 'F']
counts_gardes_group = (df1['new'].value_counts(sort=False)
.reindex(grade_leters[::-1], fill_value=0))
counts_gardes_group.plot(kind='bar')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With