how do you capitalize the first letter of each word in the column? I am using python pandas by the way. For example,
Column1 The apple the Pear Green tea
My desire result will be:
Column1 The Apple The Pear Green Tea
Applying capitalize() function We apply the str. capitalize() function to the above dataframe for the column named Day. As you can notice, the name of all the days are capitalized at the first letter.
Pandas – Convert the first and last character of each word to upper case in a series. In python, if we wish to convert only the first character of every word to uppercase, we can use the capitalize() method. Or we can take just the first character of the string and change it to uppercase using the upper() method.
How do you capitalize the first letter of a string? The first letter of a string can be capitalized using the capitalize() function. This method returns a string with the first letter capitalized. If you are looking to capitalize the first letter of the entire string the title() function should be used.
capwords() capwords() is a python function that converts the first letter of every word into uppercase and every other letter into lowercase. The function takes the string as the parameter value and then returns the string with the first letter capital as the desired output.
You can use str.title
:
df.Column1 = df.Column1.str.title() print(df.Column1) 0 The Apple 1 The Pear 2 Green Tea Name: Column1, dtype: object
Another very similar method is str.capitalize
, but it uppercases only first letters:
df.Column1 = df.Column1.str.capitalize() print(df.Column1) 0 The apple 1 The pear 2 Green tea Name: Column1, dtype: object
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With