The capital letter of each word in a Python column

how do you use the first letter of each word in a column? By the way, I am using python pandas. For instance,

         Column1
         The apple
         the Pear
         Green tea

My result will be:

         Column1
         The apple
         the Pear
         Green tea
+4
source share
1 answer

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 contains only the first letters:

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

Source: https://habr.com/ru/post/1652437/


All Articles