2. Primary Types and Attack, Defense, & Speed (55 pts)
Now, let’s group by the primary type, and examine the average values of each of attack, defense, and speed.
a. Bar Chart (15 pts)
Using matplotlib directly or via pandas’ plotting routines, create a grouped bar chart that shows the mean attack, defense, and speed for each primary type. Set the figure size wider to improve the visualization. Include a legend.

Hints:
- Here, a groupby will work well, and pandas’ plot routine will treat each column as a separate bar for each group.
- You can use the
width
property to control the amount of whitespace between bars.
b. Scatterplot (15 pts)
From the bar chart, we think there may be a negative correlation between attack and defense averages versus speed averages. First, compute a data frame that includes the mean attack, defense, and speed averages for each primary type, and then add the attack and defense means together to create a new column. Plot this new column versus the speed column. Label the axes appropriately. You should see one significant outlier with respect to the negative correlation. Determine the primary type of this outlier.
Hints:
- You can select multiple columns to be processed after a groupby, and the same aggregation can be applied to all of them.
c. Interactive Scatter Matrix (25 pts)
Now, let’s use all three attributes and use altair to create a scatter matrix. A scatter matrix is a bunch of scatterplots, one for each pair of variables. Begin by creating a scatterplot that compares just attack and speed. Once you have this, change the x and y values to use the repeat capabilities of altair, and set the repeat over the speed, attack, and defense attributes. Finally, add a brush to the visualization so that we can interactively check relationships between the individual attributes. For example, try creating a rectangular selection over those primary types with high average attack and defense to see where their speeds land.

Hints:
- Altair’s example gallery is very helpful. See the scatter_matrix and scatter_linked_brush examples.