Exercise

Strings

Columns containing strings are represented as the object type in Pandas.

Since a lot of data you will encounter involve strings, it is important that you know how to manipulate them. Python allows you to use its built-in string manipulation methods with the str accessor. There are several string methods, some of which are .upper() and .lower(). They convert strings to upper and lower case, respectively.

# Converts 'col_a' to lower case
df['col_a'].str.lower()

# Converts 'col_b' to upper case
df['col_b'].str.upper()

Instructions

100 XP
  • Inspect the 'sex' and 'smoker' columns in the shell.
  • Convert the 'sex' column into lower case.
  • Convert the 'smoker' column into upper case.
  • Inspect the 'sex' and 'smoker' columns to ensure that case conversion worked.