3
如何将列中每个单词的首字母大写?顺便说一句,我正在使用python熊猫。例如,将列中每个单词的首字母大写Python
Column1
The apple
the Pear
Green tea
我的愿望的结果将是:
Column1
The Apple
The Pear
Green Tea
如何将列中每个单词的首字母大写?顺便说一句,我正在使用python熊猫。例如,将列中每个单词的首字母大写Python
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
@jezrael谢谢!奇迹般有效! –
@JasonChingYuk - 很高兴能帮到你! – jezrael