I am trying to extract integers of varying length from a data frame column ($description) that precedes a known string. For example, I wish to extract the integers that appear before the string “yard” in the following (each line represents a separate entry in the dataframe column):
(3:18) B.Green-Ellis left end to NE 28 for -1 yards (A.Ross).
(1:07) (No Huddle Shotgun) B.Green-Ellis right guard to NYG 27 for 4 yards (C.Blackburn).
(14:00) B.Green-Ellis right end pushed ob at NYG 33 for 17 yards (K.Phillips).
What makes it problematic is that the integer can vary in length (i.e. 4 or 17), but it can also be negative.
I really have tried everything I can think of, and have been searching all day for a related thread!
A very simple solution would be
now you just have to put this in a loop and apply to every row, i.e
you can also do this in one step, as @joshua suggested!