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.
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?
How do I write the .apply() method if the column name has a space?
Does df[‘Name’] = df.Name.apply(upper)
become df[‘Name’] = df[‘Name’](upper) or something…?
From my limited understanding, str.lower is the object method and () is the operator.
Here, you are using the apply function to tell Python to apply the .lower method to each of the strings within the column. You are not doing .lower() directly because the column itself is not a string. You are applying the .lower to the string content of the columns.