Get startedGet started for free

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()

This exercise is part of the course

Python for R Users

View Course

Exercise instructions

  • 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.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Convert sex to lower case
tips____ = tips____

# Convert smoker to upper case
tips____ = tips____

# Print the sex and smoker columns
print(tips[['sex', 'smoker']])
Edit and Run Code