将Python列中每个单词的首字母大写 [英] Capitalize first letter of each word in the column Python
本文介绍了将Python列中每个单词的首字母大写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您如何将列中每个单词的首字母大写?顺便说一下,我正在使用python熊猫.例如
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
我的愿望结果将是:
Column1
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
另一个非常相似的方法是 str.capitalize
,但只将首字母大写:
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
这篇关于将Python列中每个单词的首字母大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文