In the previous exercise, we learned how to add columns to a DataFrame.

Often, the column that we want to add is related to existing columns, but requires a calculation more complex than multiplication or addition.

For example, imagine that we have the following table of customers.

Name Email
JOHN SMITH [email protected]
Jane Doe [email protected]
joe schmo [email protected]

It’s a little annoying that the capitalization is different for each row. Perhaps we’d like to make it more consistent by making all of the letters uppercase.

We can use the apply function to apply a function to every value in a particular column. For example, this code overwrites the existing 'Name' columns by applying the function upper to every row in 'Name'.

df['Name'] = df.Name.apply(str.upper)

The result:

Name Email
JOHN SMITH [email protected]
JANE DOE [email protected]
JOE SCHMO [email protected]



Apply the function lower to all names in column 'Name' in df. Assign these new names to a new column of df called 'Lowercase Name'. The final DataFrame should look like this:

Name Email Lowercase Name
JOHN SMITH [email protected] john smith
Jane Doe [email protected] jane doe
joe schmo [email protected] joe schmo

Sign up to start coding

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?