Chapter 5: DataFrame operations

DataFrame filtering exercise

face Oana Cocarascu Josiah Wang

Here is another one!

Task 2

Print all Pokemons that are either Type 2 "Electric" or Type 2 "Ice"

>>> filtered_df = ?????
>>> print(filtered_df)
                           #    Type 1  ... Generation  Legendary
Name                                    ...

Dewgong                   87     Water  ...          1      False
Cloyster                  91     Water  ...          1      False
Lapras                   131     Water  ...          1      False
Chinchou                 170     Water  ...          2      False
Lanturn                  171     Water  ...          2      False
Sneasel                  215      Dark  ...          2      False
Snover                   459     Grass  ...          4      False
Abomasnow                460     Grass  ...          4      False
AbomasnowMega Abomasnow  460     Grass  ...          4      False
Weavile                  461      Dark  ...          4      False
RotomFrost Rotom         479  Electric  ...          4      False
Joltik                   595       Bug  ...          5      False
Galvantula               596       Bug  ...          5      False
Stunfisk                 618    Ground  ...          5      False
Zekrom                   644    Dragon  ...          5       True
Kyurem                   646    Dragon  ...          5       True
KyuremBlack Kyurem       646    Dragon  ...          5       True
KyuremWhite Kyurem       646    Dragon  ...          5       True
Amaura                   698      Rock  ...          6      False
Aurorus                  699      Rock  ...          6      False

[20 rows x 12 columns]

>>> filtered_df = df[df["Type 2"].isin(["Electric", "Ice"])]

or

>>> filtered_df = df[(df["Type 2"] == "Electric") | (df["Type 2"] == "Ice")]