5.1. Exercises

Filtering Question

Question 1

If the output of

df['location'] == 'Canada'

is

[True, False, False, True]


What would be the output of

~(df['location'] == 'Canada')

Coding questiongs

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.

Single Condition Filtering

Try to filter the dataframe to obtain only a certain Pokemon type using single condition filtering.

Tasks:

  • Create a new dataframe named fire_pokemon containing only the rows of type “fire”.
Hint 1
  • Are you sure you are saving your dataframe as the correct object names?
  • Are you using pokemon['type'] == 'fire' as your condition?
Fully worked solution:



Filtering using “and”

Let’s find all the pokemon that meet multiple conditions.

Tasks:

  • Filter the dataframe for the pokemon that have attack and defense values both greater than 100.
  • Save this dataframe as an object named mighty_pokemon.
Hint 1
  • Are you sure you are saving your dataframe as the correct object names?
  • Are you separating your conditions with brackets?
  • Are you using the symbol& to get the intersect?
  • Are you using pokemon['defense'] > 100 and pokemon['attack'] > 100 as your conditions?
Fully worked solution: