Reputation: 171
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
Upvotes: 1
Views: 547
Reputation: 862641
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
Upvotes: 3