I would like to pull the numbers after the text "[Unique ID] " until the next space. I would then like to create a new column that will display each unique UID that has been pulled.
I am able to grab the first occurrence, but am not able to grab all occurrences.
Here is the code I have been using:
from pandas import DataFrame
Info = {'ID': ['1','2','3'],
'Name': ['Tom Johnson', 'Ben Thompson', 'Mike'],
'Information': ["[Age] 22 [Height] 6'2 [Unique ID] 1424 [Unique ID] 1438 [Unique ID] 1439","[Age] 21 [Height] 6'0 [Unique ID] 1101 [Unique ID] 1101","[Age] 20 [Height] 6'3 [Unique ID] 1424 [Unique ID] 1498"]}
df = DataFrame(Info,columns= ['ID', 'Name', 'Information'])
df['UID'] = [df.split("[Unique ID] ")[1].split(" ")[0] for df in df['Information']]
As you can see it will only grab the first occurrence of after "[Unique ID] ". However, I would like all occurrences.
The desired output would be,
Info2 = {'ID': ['1','1','1','2','3','3'],
'Name': ['Tom Johnson', 'Tom Johnson', 'Tom Johnson', 'Ben Thompson', 'Mike', 'Mike'],
'Information': ["[Age] 22 [Height] 6'2 [Unique ID] 1424 [Unique ID] 1438 [Unique ID] 1439",
"[Age] 22 [Height] 6'2 [Unique ID] 1424 [Unique ID] 1438 [Unique ID] 1439",
"[Age] 22 [Height] 6'2 [Unique ID] 1424 [Unique ID] 1438 [Unique ID] 1439",
"[Age] 21 [Height] 6'0 [Unique ID] 1101 [Unique ID] 1101",
"[Age] 20 [Height] 6'3 [Unique ID] 1424 [Unique ID] 1498",
"[Age] 20 [Height] 6'3 [Unique ID] 1424 [Unique ID] 1498"],
'UID': ['1424','1438', '1439', '1101', '1424', '1498']}
df2 = DataFrame(Info2,columns= ['ID','Name', 'Information', 'UID'])
As shown, it has each unique UID for each record, and if the record contains multiple of the same UID's it does not create a new record.
Thanks!