Supposed address is letters and spaces only and rest is space separated while building number always starts with a number, this could be achieved the following way:
import re
s = ['Iso Omena 8 a 2', 'Xstreet 2', 'Isö Ømenå 8 a 2']
for addr in s:
street = re.findall('[^\d]*', addr)[0].strip()
rest = addr[len(street):].strip().split(' ')
print(street, rest)
# Iso Omena ['8', 'a', '2']
# Xstreet ['2']
# Isö Ømenå ['8', 'a', '2']
Or if you want to have everything in one dataframe:
df = pd.DataFrame()
df['address'] = ['Iso Omena 8 a 2', 'Xstreet 2', 'Asdf 7 c', 'Isö Ømenå 8 a 2']
df['street'] = None; df['building'] = None; df['door'] = None; df['appartment'] = None
import re
for i, s in enumerate(df['address']):
street = re.findall('[^\d]*', s)[0].strip()
df.loc[i,('street')] = street
for col, val in zip(['building', 'door', 'appartment'], s[len(street):].strip().split(' ')):
df.loc[i,(col)] = val
# address street building door appartment
# 0 Iso Omena 8 a 2 Iso Omena 8 a 2
# 1 Xstreet 2 Xstreet 2 None None
# 2 Asdf 7 c Asdf 7 c None
# 3 Isö Ømenå 8 a 2 Isö Ømenå 8 a 2
EDIT: Building number only left of '-'sign:
you could just replace df.loc[i,(col)] = val
by
df.loc[i,(col)] = re.findall('[^-]*', val)[0]
if this suits also door and appartment. Otherwise you'd have to if-test against col=='building' to only then use this version.