I have a dataset (df) with 2 columns of arbitrary length, and I need to split it up based on the value.
| BUS | CODE |
|---|---|
| 150 H.S.London-lon3 11£150 H.S.London-lon3 16£150 H.S.London-lon3 120 | GERI |
| 400 Airport Luton-ptr5 12£400 Airport Luton-ptr5 15£400 Airport Luton-ptr5 17 | 24£JTR |
| 005 Plaza-cata-md6 08£005 Plaza-cata-md6 012£005 Plaza-cata-md6 18 | 78£TDE |
I've been trying to split it to look like this:
| bus | directions | zone | time | code | name |
|---|---|---|---|---|---|
| 150 | H.S.London | lon3 | 11 | NaN | GERI |
| 400 | Airport Luton | ptr5 | 12 | 24 | JTR |
| 005 | Plaza-cata | md6 | 08 | 78 | TDE |
So far, I tried to split by patterns, but isn't working and I'm out of ideas or how to split it in other way.
bus = '(?P<bus>[\d]+) (?P<direction>[\w\W]+)-(?P<zone>[\w]+)'
code = '(?P<code>[\S]+)£(?P<name>\d+)
df.BUS.str.extract(bus)).join(df.CODE.str.extract(code)
I was wondering if anyone had a good solution to this.