I have a pandas column like this:
LOD-NY-EP-ADM
LOD-NY-EC-RUL
LOD-NY-EC-WFL
LOD-NY-LSM-SER
LOD-NY-PM-MOB
LOD-NY-PM-MOB
LOD-NY-RMK
LOD-NY-EC-TIM
I want the output in new column as
EP
EC
EC
LSM
PM
PM
RMK
EC
I tried this:
pattern=df.column[0:10].str.extract(r"\w*-NY-(.*?)-\w*",expand=False)
While it works for everything but it fails to get RMK out and gives NaN since there is nothing after that and it looks for -\w zero or more times. But then that should work if there is nothing after RMK.
Any idea whats going wrong?
We can just use a array of these and use regular expression if pandas syntax is not familiar.
^\w+-NY-(.*?)(?:-\w+)?$