ser.str.strip()
ser.str.strip(to_strip = None)
Removes the specified character(s) from each string in the Series from both the left and right side.
- Input:
- to_strip : string or None, default None
- A specified character/a set of characters to be removed. All combinations of this set of characters will be stripped. If not specified, removes whitespace (including newlines).
- Returns:
- Returns a Series with each element as a list of strings stripped by the specified character/set of characters.
- 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!"
comment_ser.str.strip()
- 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!"
comment_ser.str.strip('*')
- 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 how nothing changes
comment_ser.str.strip('?')
- 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!"
Remove a set of characters simultaneously. (e.g. remove both *
and whitespace)
comment_ser.str.strip('* ')
- 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!"