I have a dataset, df, that repeats a sequence for X amount of times. I would like to replace certain letters of this sequence and then repeat for a given max count.
Data
xy_pod xy_pod xy_pod xy_pod
xy_pod xy_pod xy_pod xy_pod
xy_pod xy_pod xy_pod xy_pod
other letters where I would like to replace the 'xy' portion with:
aa
vee
lee
Desired
xy_pod xy_pod xy_pod xy_pod
xy_pod xy_pod xy_pod xy_pod
xy_pod xy_pod xy_pod xy_pod
aa_pod aa_pod aa_pod aa_pod
aa_pod aa_pod aa_pod aa_pod
aa_pod aa_pod aa_pod aa_pod
vee_pod vee_pod vee_pod vee_pod
vee_pod vee_pod vee_pod vee_pod
vee_pod vee_pod vee_pod vee_pod
lee_pod lee_pod lee_pod lee_pod
lee_pod lee_pod lee_pod lee_pod
lee_pod lee_pod lee_pod lee_pod
Doing
df.replace(xy_pod, aa_pod, 12)
df.replace(aa_pod, vee_pod, 12)
df.replace(vee_pod, lee_pod, 12)
This is very similar to the find and replace logic that excel offers. However, I am not sure how to specify the number of repetitions that I wish to occur. Also, how would I perform this for multiple sequences so that I do not have to perform the function for every new entry? Is there a more efficient way to do this?
Any suggestion or advice is appreciated
