extract number from text with comma as separation between them

Viewed 35

i want to extract numbers from text with (,) for ex as separation between the numbers the dataframe is data frame i use this code

WATANIA_MTO['Numbers'] = WATANIA_MTOdf['col'].str.replace('PLATE ','').str.split('X', expand=True)

the out put is out put i want this comma in the end of number column to be between number like this Numbers 16,80,300 2,80

1 Answers

Use this :

import re
import pandas as pd

df['Numbers'] = df['DES'].apply(lambda x: re.findall(r"[-+]?\d*\.\d+|\d+", x)).tolist()
df['Numbers'] = df['Numbers'].apply(','.join)

>>> display(df)

enter image description here

Related