I have a problem that is tricky for me. I have a list of lists:
list_lists = [['0', 'red/c/16', 'green/c/19', 'blue/c/16'],
['1', 'red/a/14', 'green/b/15', 'blue/c/25', 'green/c/28']]
and a dataframe:
data = [['red', 'ID=2', 'red/a'], ['green', 'ID=4', 'green/b'],
['blue', 'ID=6', 'blue/c'], ['green', 'ID=7', 'green/c'],
['red', 'ID=8', 'red/c']]
df = pd.DataFrame(data, columns=['Color', 'ID', 'Startswith'])
I want to replace each element in list_lists with the respective element of the column 'ID', based on whether the beginning of the element in list_lists matches the element in the column 'Startswith'. How can this be done? Remark: The first element of each list is only the index of the list and can be ignored.