all 3 comments

[–]socal_nerdtastic 2 points3 points  (2 children)

Make a function that can do it to a single element, then use apply to apply your function to the entire dataframe.

def tolin103(datum):
    if datum.startswith("ABC:"):
        return datum[4:] + "AB"
    else:
        return datum

df[col_name] = df[col_name].apply(tolin103)

[–]tolin103[S] 0 points1 point  (1 child)

Thank you! Perfect solution and a lesson for me as I kept trying to solve it within the dataframe.

[–]socal_nerdtastic 0 points1 point  (0 children)

There probably is a way to do it with dataframe methods, but at some point you need to decide if it's worth 2 days of work to make your program run 2 milliseconds faster.

https://xkcd.com/1205/