You have to manually re-assign the values to the columns/features that you are applying the lambda function to.
df[[‘col1’, ‘col2’]] = df[[‘col1’, ‘col2’]].apply(lambda)
PS:I was trying to do something similar with iloc instead of specifying the column names explicitly and the apply wasn’t working, because it was returning a copy image of the data set.
The lower is one of the deprecated string functions in Python 2, and in Python 3, it is removed from the string library. So importing lower from string library is no longer recommended. It is recommended to use str.lower instead.
df["column"].str.lower() is a way using the str.lower method of Pandas Series object. As a way along with this exercise that uses the .apply() method, we can also simply replace lower with str.lower as a Python built-in string method (or this, in Python 3): df["column"].apply(str.lower). In either case, from string import lower on the line 2 is no longer needed.