I have a single alphanumeric string column that has to be split into two different columns: numbers and alphabet.
But the thing is we just need to split the first part of numbers from string and the remaining alphanumeric should remain same in 2nd column
|2 200 jibs50|
|8 Certs 20|
I have tried out, It works correctly but fails when the string is just a 4 digit number with space.
code: df_tab["Col A"].str.extract(r'(\d+)(?: (\S.+))?$')
The output I get is below table:
Small change in the regex works
df["Col A"].str.extract(r'([\d\s]+)(?: (\S.+))?$')
Previous your regex was matching only digits. Changed it to match digits and numbers.
2 Nutsx20mm 2 200 jibs50 3 200 NaN 5 NaN 8 Certs 20