[英]Capitalize first letter of each word in the column Python
如何将列中每个单词的首字母大写? 顺便说一句,我正在使用python pandas。 例如,
Column1
The apple
the Pear
Green tea
我的愿望结果将是:
Column1
The Apple
The Pear
Green Tea
你可以使用str.title
:
print (df.Column1.str.title())
0 The Apple
1 The Pear
2 Green Tea
Name: Column1, dtype: object
另一个非常相似的方法是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.