[英]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.
顺便说一句,我正在使用python pandas。 For example,
例如,
Column1
The apple
the Pear
Green tea
My desire result will be: 我的愿望结果将是:
Column1
The Apple
The Pear
Green Tea
You can use str.title
: 你可以使用
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: 另一个非常相似的方法是
str.capitalize
,但它仅仅首字母大写:
print (df.Column1.str.capitalize())
0 The apple
1 The pear
2 Green tea
Name: Column1, dtype: object
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.