How to extract first two characters from string using regex How to extract first two characters from string using regex pandas pandas

How to extract first two characters from string using regex


new answers
per comment from @Addison

# '12(?=.{4}$)' makes sure we have a 12 followed by exactly 4 something elsesdf.c_contofficeID.str.replace('^12(?=.{4}$)', '')

If ID's must have four characters, it's simpler to

df.c_contofficeID.str[-4:]

old answer
use str.replace

df.c_contofficeID.str.replace('^12', '').to_frame()

enter image description here