Skip to main content

ser.str.capitalize()

ser.str.capitalize()

Capitalizes the first character of each string in the Series.

Returns:
Returns a Series with each element's first character capitalized.
Return Type:
Series

comment_ser = pets.get('Owner_Comment')
comment_ser
  • 0" There are no bad dogs, only bad owners."
  • 1"My best birthday present ever!!!"
  • 2"****All you need is love and a cat.****"
  • 3"Love is a wet nose and a wagging tail."
  • 4"Be the person your dog thinks you are."
  • 5"No, thank you!"
  • 6"No, thank you!"
  • 7"No, thank you!"


Notice that ser.str.capitalize() only works when there are no special characters before the first letter in the string.

comment_ser.str.capitalize()
  • 0" there are no bad dogs, only bad owners."
  • 1"My best birthday present ever!!!"
  • 2"****all you need is love and a cat.****"
  • 3"Love is a wet nose and a wagging tail."
  • 4"Be the person your dog thinks you are."
  • 5"No, thank you!"
  • 6"No, thank you!"
  • 7"No, thank you!"


After removing special characters, ser.str.capitalize() will work. This is also an example of how to use multiple ser.str methods on a bpd Series.

comment_ser.str.strip().str.capitalize()
  • 0"There are no bad dogs, only bad owners."
  • 1"My best birthday present ever!!!"
  • 2"****all you need is love and a cat.****"
  • 3"Love is a wet nose and a wagging tail."
  • 4"Be the person your dog thinks you are."
  • 5"No, thank you!"
  • 6"No, thank you!"
  • 7"No, thank you!"