Ad
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)
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.
Ad
Answer
Use str.title()
:
df["Street"] = df["Street"].str.title()
df["City"] = df["City"].str.title()
Ad
source: stackoverflow.com
Related Questions
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Can't turn off Javascript using Selenium
- → WebDriver click() vs JavaScript click()
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module
Ad