I have a DataFrame that looks like this
Unit ID Shipping to:
90 With x
91 With y
92 With z
116 Shipped to x 01/04/16. / Shipped to y - 09/08/18.
233 Shipped to z 03/01/17
265 Shipped to x 03/01/17 returned shipped to x 02/05/17
280 Shipped to x 06/01/17 Shipped to y 03/05/17 Shipped to z 12/12/17
I would like to be able to extract all occurrences of x,y or z and the date that follows it if there is one. I can't confirm how many occurrences of z,y or z there will be but I would like an end result that looks something like this:
Unit ID Occurrence 1 Occurrence 2 Occurrence 3 Shipping to:
90 x With x
91 y With y
92 z With z
116 x 01/04/16 y 09/08/18 Shipped to x 01/04/16. / Shipped to y - 09/08/18.
233 z 03/01/17 Shipped to z 03/01/17
265 x 03/01/17 Shipped to x 03/01/17 returned shipped to x 02/05/17
280 x 06/01/17 y 03/05/17 z 12/12/17 Shipped to x 06/01/17 Shipped to y 03/05/17 Shipped to z 12/12/17
so far I've only managed to extract the first date that appears in every column using this
date_col = []
for row in df['Shipping to:']:
match = re.search('\d{2}/\d{2}/\d{2}',str(row),re.IGNORECASE)
date_col.append(match)
df['dates'] = date_col
\d{2}/\d{2}/\d{2}, I would say that is quite specific.