'Convert entries in column of pandas dataframe to title case only if they are all caps
I have a dataframe of user entered names and addresses. Some users enter their NAMES AND ADDRESSES IN ALL CAPS. I figured out how to convert a pandas dataframe column to title case ( df['last_name'] = df.last_name.str.title() ) but that messes up certain last names like McWhirter, which becomes Mcwhirter. Sorry if this is a noob question, but is there any way to selectively apply title case to column entries only if they are IN ALL CAPS?
Solution 1:[1]
Check all caps using str.isupper and filter according to that
df.loc[df.last_name.str.isupper(), 'last_name'] = df.last_name.str.title()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Vishnudev |
