Capitalize first letter of each word in the column Python

断了今生、忘了曾经 提交于 2019-12-30 03:46:14

问题


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

回答1:


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


来源:https://stackoverflow.com/questions/39141856/capitalize-first-letter-of-each-word-in-the-column-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!