3.1. Exercises

Pivoting Questions

Applying Pivot

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 take a look at the new dataset named lego.

Let’s convert the dataframe lego into a wider dataframe using .pivot().

Tasks:

  • Convert the untidy data into tidy data using .pivot().
  • Don’t forget to reset your index.
  • Name the new dataframe tidied_lego.
  • Save the mean number of parts (num_parts) of the Lego sets in an object named set_parts_mean. (We’ve added a verb named .round() to round to the nearest whole number)
Hint 1
  • Are you pivoting the correct column named lego_info with values='value'?
  • Are you resetting your index after you pivot?
Fully worked solution: