9.1. Exercises

Plotting a Groupby Object

Instructions:
Running a coding exercise for the first time, could take a bit of time for everything to load. Be patient, it could take a few minutes.

When you see ____ in a coding exercise, replace it with what you assume to be the correct code. Run it and see if you obtain the desired output. Submit your code to validate if you were correct.

Let’s attempt to answer the question “Which pokemon type has the highest mean attack score?” by making a bar chart from a groupby object.

Tasks:

Create a plot by chaining the following actions.

  • Make a groupby object on the column type and name it pokemon_type.
  • Use .mean() on the new groupby object.
  • reset the index so it no longer has type as index column.
  • Use reset_index() to make type a column again.
  • Sort the pokemon mean attack values in descending order using sort argument.
  • Name the y-axis “Mean attack scores”.
  • Name the object attack_plot.
Hint 1
  • Are you grouping by the column named type?
  • Are you using .loc[:, 'attack']?
  • While sorting, are you using the argument ascending=False?
  • Are you resetting the index?
  • Are you giving your plot a title??
Fully worked solution: