FAQ: Modifying DataFrames - Performing Column Operations

This community-built FAQ covers the “Performing Column Operations” exercise from the lesson “Modifying DataFrames”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Data Science

Data Analysis with Pandas

FAQs on the exercise Performing Column Operations

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Hello.
Tried same code as in this excercise on IDLE. There is an error

ImportError: cannot import name ‘lower’ from ‘string’ (C:\Miniconda\lib\string.py)

What can I do to get rid of this?
Thank you

2 Likes

I have the same problem. I see you haven’t got an answer yet though…

I had the same problem. I have written simply:

df[‘Lowercase Name’] = df.Name.str.lower()

2 Likes

I searched a little about this. This is probably a problem with the difference between Python 2 and Python 3. The lower is one of the deprecated string functions in Python 2. Instead, the one defined as String Methods is recommended. In Python 3, the lower is removed from the string library. So in Python 3, the code from string import lower don’t work and we need to use str.lower() as you’ve suggested.

As a way along with this exercise that uses the .apply() method, we can also simply replace lower with str.lower:

df['Lowercase Name'] = df.Name.apply(str.lower)

Now we don’t need to import string.

The exercise demonstrated passing upper and lower functions through columns in Pandas - but what if I simply want to follow conventional English syntax, with the first letter of first and last names capitalized?

1 Like

In that case you can use str.title().