Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

926
Views
Converting strings to a lower case in pandas

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?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

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

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

over 4 years ago · Santiago Trujillo Report

0

I think you need assign output back, better is omit apply if works only with column url:

df = pd.DataFrame({'url': ['www.CNN.com', 'www.Nbc.com', 'www.BBc.com', 'www.fOX.com'], 
                   'var1': ['XSD', 'wer', 'xyz', 'zyx']})

print (df)
           url var1
0  www.CNN.com  XSD
1  www.Nbc.com  wer
2  www.BBc.com  xyz
3  www.fOX.com  zyx

#if types of column is str, astype is not necessary
df.url = df.url.astype(str).str.lower()
print (df)
           url var1
0  www.cnn.com  XSD
1  www.nbc.com  wer
2  www.bbc.com  xyz
3  www.fox.com  zyx

But if need convert all columns of df to lowercase strings:

df = df.astype(str).apply(lambda x: x.str.lower())
print (df)
           url var1
0  www.cnn.com  xsd
1  www.nbc.com  wer
2  www.bbc.com  xyz
3  www.fox.com  zyx
over 4 years ago · Santiago Trujillo Report

0

To convert a single column we can use,

df.column_name.str.lower()

or

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

Hope this helps !

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!