6.1. Exercises

Practice Replacing Values

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 make a new column by assigning each pokemon base score as either “strong” or “weak”.

Tasks:

  • Create a new column in the dataframe named base_score by assigning values 500 or greater from the column total_bs as ‘strong’ pokemon and values less than 500 as ‘weak’ pokemon.
  • Display the first 10 rows of the dataframe.
Hint 1
  • Are you naming the new column named base_score?
  • Are you using .loc[df['total_bs'] >= 500, 'base_score'] and assigning it to the correct value?
  • Are you using single equality signs for the assignment?
Fully worked solution:


Using the new column base_score we made above, make a bar graph showing the frequency of the strong and weak pokemon.

Tasks:

  • Create an object using single brackets to obtain the column base_score and name it bs_column.
  • Plot the object bs_column using .mark_bar() and save this graph as score_plot.
Hint 1
  • Are you using single square brackets or obtain the column base_score?
  • Are you using count() to count the occurences of the base scores?
  • Are you saving the objects with the correct names?
Fully worked solution: