Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to capitalize first letter of multiple string in a column using pandas

I have a dataframe with 2 columns in it as follows,

Street                   City
8188 E PINNACLE CIR      GOLD CANYON
6701 S SOLADO PL         GOLD CANYON
5051 S DUSTY COYOTE TRL  GOLD CANYON

I am trying to solve a problem where I need to convert first letter of each string of these two column to capital letter and rest to lower case. I mean this is how it should be looking like post-conversion.

Now I doing df[‘col’].str.capitalize but I am seeing this – 8188 e pinnacle cir (one of the street column output)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Street                   City
8188 E Pinnacle Cir      Gold Canyon
6701 S Solado Pl         Gold Canyon
5051 S Dusty Coyote Trl  Gold Canyon

This is bit tricky to me, is there any better solution for it? Please suggest.

>Solution :

Use str.title():

df["Street"] = df["Street"].str.title()
df["City"] = df["City"].str.title()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading