I want to extract the number before the text begins
column1
10units
200 mg
4000units/40mg
40 units
The below code worked for all cells except for the cell that had multiple numbers
df['newcolumn'] = df['column1'].astype('str').str.extractall('(\d+)').unstack().fillna('').sum(axis=1).astype(int)
The output looks like below
newcolumn
10
200
400040
40
Expected output
newcolumn
10
200
4000
40