I have a pandas data frame , that has some regression equations, with bias terms at the end of each equation. (+250 , -150, +450, +250 )
df:
a b
0 [TC100]+250 [TC200]-150
1 [FC100]+450 [FC200]+250
I would like to replace the bias terms [specifically , whatever comes after the last occurrence of the character ] in each equation] . The replacement string should be based on the corresponding column name. Desired output as below
output:
a b
0 [TC100]+a1 [TC200]+b1
1 [FC100]+a2 [FC200]+b2
I tried using rsplit , df.replace , Series.str.extract but no luck. I would appreciate very much any help .