Converting strings to a lower case in pandas

Feyzi Bagirov picture Feyzi Bagirov · Mar 12, 2017 · Viewed 36.8k times · Source

I have a data that contains domain names:

 url          var1
www.CNN.com   xsd
www.Nbc.com   wer
www.BBc.com   xyz
www.fOX.com   zyx
....

The data is of the Series type. I am using the following to convert url variable to lower case:

df.apply(lambda x: x.astype(str).str.lower())

However, they remain the same.

What am I doing wrong?

Answer

David picture David · Mar 12, 2017
df['url'] = df['url'].str.lower()

should operate on the series and replace it with the lower case version.