Jason Ching Yuk Jason Ching Yuk - 1 month ago 8x
Python Question

Capitalize first letter of each word in the column Python

how do you capitalize the first letter of each word in the column? I am using python pandas by the way. For example,

The apple
the Pear
Green tea

My desire result will be:

The Apple
The Pear
Green Tea


You can use str.title:

print (df.Column1.str.title())
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:

print (df.Column1.str.capitalize())
0    The apple
1     The pear
2    Green tea
Name: Column1, dtype: object