I have a dataframe with a column like that
COL1
PACK[30% /2 prod.(if fidelity)]
PACK[3.85 € /2 prod.(if fidelity)]
PACK[40% /2nd prod.]
PACK[3.5 € /2 prod.]
I want create other column as following according COL1
fidelity_perc fidelity_euro rem_perc rem_eu
30 3,85 40 3,5
using regex.
For PACK[40% /2nd prod.] I did (?<=PACK\[)\d+(?=%) but it's also walk for PACK[30% /2 prod.(if fidelity)] and I don't want this.
df['COL1'].str.extract(r'PACK\[(\d[\d.]*)%[^][()]*]', expand=False)? See regex101.com/r/3jROEh/2df['fidelity_perc'] = df['COL1'].str.extract(r'PACK\[(\d[\d.]*)%[^][()]*]', expand=False)?