ser.str.replace()
ser.str.replace(old, new)
Substitutes all occurences old
with new
for every element of the Series.
- Input:
- old : string
- String to replace.
- new : string
- Replacement string.
- Returns:
- Returns a Series where each occurence of the string
old
replaced bynew
. - 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.replace('dog', 'cat')
- 0" There are no bad cats, 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 cat thinks you are."
- 5"No, thank you!"
- 6"No, thank you!"
- 7"No, thank you!"
Replaced multiple strings.
comment_ser.str.replace('dog', 'cat').str.replace('birthday', '🍰')
- 0" There are no bad cats, only bad owners."
- 1"My best 🍰 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 cat thinks you are."
- 5"No, thank you!"
- 6"No, thank you!"
- 7"No, thank you!"