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

Issue

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)

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()

Answered By – Tim Biegeleisen

Answer Checked By – Jay B. (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *