I have a pandas DataFrame with a column which has the following values in a column:
Identifier
[1;12;7;3;0]
[4;5;2;6;0]
I want to convert the values in square brackets in this column to 5 new columns. Essentially, I want to split those values into 5 new columns, while keeping the index for new columns same as the original column.
Identifier,a,b,c,d,e
[1;12;7;3;0],1,12,7,3,0
[4;5;2;6;0],4,5,2,6,0
pattern = re.compile(r'(\d+)')
for g in raw_data["Identifier"]:
new_id = raw_data.Identifier.str.findall(pattern) # this converts the Identifier into a list of the 5 values
raw_data.append({'a':new_id[0],'b':new_id[1],'c':new_id[2],'d':new_id[3],'d':new_id[4]}, ignore_index=True)
The above code adds the extracted values from the column "identifier" to the end of the DataFrame and not to the corresponding rows. How can I add the values extracted to the same row/index as the original column ('Identifier')?