I have a string column in a dataframe and I'd like to insert a # to the begging of my pattern.
For example: My pattern is the letters 'pr' followed by any amount of numbers. If in my column there is a value 'problem in pr123', I would change it to 'problem in #pr123'.
I'm trying a bunch of code snippets but nothing is working for me.
Tried to change the solution to replace for 'pr#123' but this didn't work either.
df['desc_clean'] = df['desc_clean'].str.replace(r'([p][r])(\d+)', r'\1#\2', regex=True)
What's the best way I can replace all values in this column when I find this pattern?
df['desc_clean'] = df['desc_clean'].str.replace(r'(pr)(\d+)', r'\1#\2')if you needpr#123. To get#pr123, you needdf['desc_clean'].str.replace(r'pr\d+', r'#\g<0>'). Add a word boundary,\b, in front ofprto matchpras a whole word.