This has a reference to this SO thread .
For the sake of newness, I am reproducing the dataframe with a small change:
ID Static_Text Params
1 Today, <adj1> is quite Sunny. Tomorrow, <adj2> 1-10-2020
may be little <adj3>
1 Today, <adj1> is quite Sunny. Tomorrow, <adj2> 2-10-2020
may be little <adj3>
1 Today, <adj1> is quite Sunny. Tomorrow, <adj2> Cloudy
may be little <adj3>
2 Let's have a coffee break near <adj1>, if I Balcony
don't get any SO reply by <adj2>
2 Let's have a coffee break near <adj1>, if I 30
don't get any SO reply by <adj2> mins
Now I want to replace the whole <adj> by {} where 1st occurrence of i.e. <adj1> shall be replaced by {0}. So the resultant dataframe would look like follows:
ID Static_Text Params
1 Today, {0} is quite Sunny. Tomorrow, {1} 1-10-2020
may be little {2}
1 Today, {0} is quite Sunny. Tomorrow, {1} 2-10-2020
may be little {2}
1 Today, {0} is quite Sunny. Tomorrow, {1} Cloudy
may be little {2}
2 Let's have a coffee break near {0}, if I Balcony
don't get any SO reply by {1}
2 Let's have a coffee break near {0}, if I 30
don't get any SO reply by {1} mins
I am trying the following:
def replace_angular(df):
if '<' and '>' in df['Static_Text']:
rep_txt = re.sub(r'\<[^>]*\>',{},df[Static_Text'])
return rep_txt
df = df.apply(lambda x : replace_angular(x),axis=1)
But I am not too sure about the above code snippet. Especially how to bring 0,1 etc within {}.