I would like to ask for a little help.
I have a frame consisting of multiple columns, here in this case I just highlighted three columns, which are important for me
frame=pd.DataFrame({"String":["000111222f12","000121222f11","000131222f12","000141222f12"],"Cavity": ["Cav 2", "Cav 1", "Cav 1", "Cav 2"]})
Cavity String
0 Cav 2 011121222f12
1 Cav 1 011111222f14
2 Cav 2 011111222f16
3 Cav 2 000111222f17
What I would like to get is the following: Based on cavity column, I need to change the 4.location (counting at zero) for the string, meaning if I have Cav 2 I should have 011121222f16
The desired solution should look like this
Cavity String Corrected String
0 Cav 2 011121222f12 011121222f12
1 Cav 1 011111222f14 011111222f14
2 Cav 2 011111222f16 011121222f16
3 Cav 2 000111222f17 000121222f17
I tried to solve it with a combination of replace and slicing the string at the specific location and using np.where, but without success.
Any advice for me?
Cheers and thanks
Cav 2to2?