Q:

Split column on first occurence of '-'

I have a pandas data frame with column that contain house numbers and a suffix. The house number and suffix are seperated by a '-' although many suffixes also contain a '-'.
I have tried this:
df house_nr(x):
    y = x['house_nr'].split('-', maxsplit = 1)
    return y

df['suffix'] = df.apply(house_nr, axis=1)

Got the following error:
KeyError: ('house_nr', 'occurred at index 0')

After some other attempts I've got this working:
df2 = pd.DataFrame(df['house_nr'].str.split('-',1).tolist(),columns = ['house-number','suffix'])

And then I join the dataframe but I don't think this solution is very nice or  pythonic.

A:

Setup
df = pd.DataFrame({'house_nr': ['123-Rd-thing', '456-House', '567-House-thing']})

          house_nr
0     123-Rd-thing
1        456-House
2  567-House-thing

Using a list comprehension and split, which will be faster than pandas string methods:
pd.DataFrame([i.split('-', 1) for i in df.house_nr], columns=['num', 'suffix'])

   num       suffix
0  123     Rd-thing
1  456        House
2  567  House-thing

