Capitalize first letter of each word in the column Python

后端 未结 1 437
青春惊慌失措
青春惊慌失措 2020-12-30 23:46

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
            


        
1条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-31 00:45

    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
    

    0 讨论(0)
提交回复
热议问题