A grouped bar chart places multiple bars beside one another for each category, making subcategory counts directly comparable. It supports exploratory analysis of relationships such as quarter and conversion outcome. section 6.2.3
Build one from grouped categorical counts:
- Group observations by a main category and outcome, then reshape with unstack(fill_value=0). section 6.2.3
- Plot the reshaped data with plot(kind='bar'), annotate bar heights, label axes, and name the outcome legend. section 6.2.3
- Interpret differences as associations rather than causal effects; play type may reflect yards required for conversion. section 6.2.3
>>> import matplotlib.pyplot as plt #1
>>> grouped_data = (nfl_pbp.groupby(['QUARTER', 'CONVERT']) \
>>> .size().unstack(fill_value = 0)) #2
>>> grouped_data.plot(kind = 'bar') #3
>>> for p in ax.patches:
>>> ax.annotate(str(p.get_height()),
>>> (p.get_x() + p.get_width() / 2., p.get_height()),
>>> ha = 'center', va = 'bottom',
>>> fontweight = 'bold',
>>> color = 'black') #4
>>> plt.title('Observation Counts by Quarter') #5
>>> plt.xlabel('Quarter') #6
>>> plt.ylabel('Count') #7
>>> plt.xticks(rotation = 0) #8
>>> plt.legend(title = 'CONVERT',
>>> labels = ['No', 'Yes']) #9
>>> plt.show() #10
Annotated Python listing showing grouped counts, bar plotting, labels, and value annotations. section 6.2.3

