Dec-19-2019, 09:38 AM
Hi. I have a column of text with inputs like,
From regex101.com, I confirm the following captures any of these for all my examples:
Thanks!
3" deep, 4 inches deep, 5" depth
. I wanted to extract just the value and put this in a new column. From regex101.com, I confirm the following captures any of these for all my examples:
r'(\d)\"\s*deep|(\d)\"\s*depth|(\d)\sinches\sdeep'However, when I try to use this regex pattern with str.extract as follows
df['depth']=df['text'].str.extract(r'(\d)\"\s*deep|(\d)\"\s*depth|(\d)\sinches\sdeep')
Error:ValueError: Wrong number of items passed 3, placement implies 1
The docs say it should just return the first match. I tried str.extractall
just in case, but this produces Error:TypeError: incompatible index of inserted column with frame index
How do I pass regex OR patterns to str.extract? Or, how should I match each of these cases to create a new column?Thanks!