1

Im new using python. I have a dataframe with 3 columns (id, name, description), My dataframe contains as example these rows ('id1', 'paul', 'tmp123'), ('id2', 'laura', 'vi34jay'). I want to replace the numeric characters of my column description by "TT".

expected output

('id1', 'paul', 'tmpTTT'), ('id2', 'laura', 'viTTjay')

Does anyone knows how to do? Thank you

1 Answer 1

3

Use Series.replace with \d for match digit:

df = pd.DataFrame({'description': ['tmp123', 'vi34jay']})

df['description'] = df['description'].replace('\d', 'T', regex=True)
print(df)
  description
0      tmpTTT
1     viTTjay
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.