I'm trying to create a new column within one of my dataframes by combining existing columns through finding the values in a dictionary.
values["-R1-"] and values["-R2-"] are allocated a value through a listbox using pysimplegui which are a list of all column headings in the df.
If I put it the first row it works fine and created a new column.
df['Unique_ID_Test'] = df["Account Code] df["Transaction Id] df['Abs'].astype(str)
However if I try and find the value using a dictionary it gives me the below error message where it these should yield the same result.
df['Unique_ID_Test'] = df[values["-R1-"]] df[values["-R2-"]] df['Abs'].astype(str)
ValueError: Expected a 1D array, got an array with shape (5253, 5255)
Does anyone have any idea why this won't work? The error message doesn't seem to be particularly helpful (for me).
Listbox code extract for reference
[pg.Listbox(values=list, size=(60, 15), key='-Amt-')],
[pg.Listbox(values=list, size=(60, 15), key="-R1-")],
[pg.Listbox(values=list, size=(60, 15), key="-R2-")],
CodePudding user response:
Question is answered by Jason Yang above.