I currently have this df where the rect column is all strings. I need to extract the x, y, w and h from it into separate columns. The dataset is very large so I need an effi
Use str.extract, which extracts groups from regex into columns:
df['rect'].str.extract(r'\((?P\d+),(?P\d+)\),(?P\d+) by (?P\d+)', expand=True)
Result:
x y w h 0 120 168 260 120 1 120 168 260 120 2 120 168 260 120 3 120 168 260 120 4 120 168 260 120