Pandas srt.lower () not working on dataframe column

I am working with the Titanic dataset available from Kaggle. I have this in a dataframe and I want to change the case of the "sex" column to lower case. I am using the following code

import pandas as pd

df = pd.read_csv('titanic.csv')
print dfFull['sex'].unique()
df.sex.str.lower()

#check if it worked
print df['sex'].unique()

      

and also try

df['sex'].str.lower()

but when i run df['sex'].unique()

i get three unique values [male, female, Female]

.

Why is my code not decreasing the case of strings and saving it back to the dataframe so I am getting [male, female]

from the method .unique

?

+3


source to share


1 answer


str.lower()

does not modify an existing column. It just returns a new series with the string transform applied. If you want to overwrite the original column, you need to return the result to it:



df['sex'] = df.sex.str.lower()

      

+8


source







All Articles