I have a dataframe that contains a string column with several different 4 character that can be separated by | or &, but not always. I am trying to map a dictionary to each discrete 4 character item but am running into issues. pandas ver 23.4
The basic code I am trying to use:
df = df.replace(dict, regex=True)
or if trying to select a specific col:
df['Col'] = df['Col'].replace(dict, regex=True)
Both raise the following error:
ValueError: The truth value of an array with more that one element is ambiguous. Use a.any() or a.all()
The values of the dictionary are type list. Is this something that would be an issue with performing the .replace?
Update With Sample df and dict
ID Code
ABCD 00FQ
JKFA 8LK9|4F5H
QWST 2RLA|R1T5&8LK9
dict={'00FQ':['A','B'], '8LK9':['X'], '4F5H':['U','Z'], '2RLA':['H','K'], 'R1T5':['B','G'] }
The dict will have more elements in it than in the dataframe.
Update with expected output
ID Code Logic
ABCD 00FQ ['A','B']
JKFA 8LK9|4F5H ['X'] | ['U','Z']
QWST 2RLA|R1T5&8LK9 ['H','K'] | ['B','G'] & ['X']
The overall goal is to perform this replace on two dataframes, and then compare the ID's on both sides for equivalence.