You can use .str.extract
with regex
pattern containing named capturing groups:
code = r'^(?P<code>d+)?.*?(?P<name>[A-Za-z]+)'
bus = r'^(?P<bus>d+)s(?P<directions>.*?)-(?P<zone>[^-]+)s(?P<time>d+)'
df['BUS'].str.extract(bus).join(df['CODE'].str.extract(code))
bus directions zone time code name
0 150 H.S.London lon3 11 NaN GERI
1 400 Airport Luton ptr5 12 24 JTR
2 005 Plaza-cata md6 08 78 TDE
See the regex demo for code
pattern here
and for bus
pattern here
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…