I have the following DF (with desired result hardcoded)
dfo = pd.DataFrame({"list1": [["test1", "test2"], ["test1", "test2", "test3"], ["test1", "test2"]],
"list2": [["notatest", "test3"], ["notatest"], ["notatest", "Test3"]],
"desired": [["test1", "test2", "test3"], ["test1", "test2", "test3"], ["test1", "test2", "Test3"]]})
In which I want to add/append the very last element of list2 (list2[-1]) to list1 if it == "test3".
Tried the following to no avail:
dfo["list1_test3_added"] = dfo["list1"].apply(lambda x: x.append([i for i in x["list2"][-1] if i == "test3"]))
Could also be the case that at some point someone loses their mind and it's not "test3" but "Test3", so maybe a regex match would be needed.