crawler
crawler

Reputation: 43

Using regex to map values in dataframe using python

have a df with values :


name   number     addition

tom    123        this is tom , number is [[number]]
mark   1234       this is mark , number is [[number]]

using regex how to map value in number column with [[number]] in addition column like this


name   number     addition

tom    123        this is tom , number is 123
mark   1234       this is mark , number is 1234

Upvotes: 1

Views: 225

Answers (1)

Code Different
Code Different

Reputation: 93141

You can use apply:

df['addition'] =  df.apply(lambda row: row['addition'].replace('[[number]]', str(row['number'])), axis=1)

Upvotes: 3

Related Questions