I have two lists of lists that I am trying to map to another value in my dataframe.
Example of the list:
Potential_Cond_lst = [['Any Muscle Dis'], ['Type 2 fun','My happy place','Any Endo','Any Muscle Dis'],
['Mad people outiside','Ox tail','Hyper T','Wu Tang'],
['Type 2', 'Any Endo'],
['Other friends', 'Encounter for friends'],
['Any Endo', 'Any Muscle D', 'Major Frank'],
['Other friends', 'Any Muscle Disease'],.....]
Confidence_lvl_lst = [['50.8%'],
['96.3%', '94.1%', '94.0%', '61.5%'],
['99.0%', '99.0%', '93.6%', '45.5%'],
['99.0%', '89.4%'],
['70.0%', '31.5%'],
['92.6%', '70.7%', '20.0%'],
['88.1%', '59.2%'], ....]
I am trying to map these two list so they they would look like this:
Complete_lst = [['Any Muscle Dis': '50.8%'],
['Type 2 fun': '96.3%','My happy place':'94.1%','Any Endo':'94.0%','Any Muscle Dis':'61.5%'], ['Mad people outiside': '99.0%','Ox tail':'99.0%','Hyper T':'93.6%','Wu Tang': '45.5%'], .....]
This way when I create a dataframe the output will look like this:
ID Reason Test Date of Reason Name of Test Done Potential Conditions with Confidence Level
0 87435 [Hanks Finger (11), Hanks left Finger (13), Hanks Right Finger (48] 2022-03-24 [Hanks Finger (13), Hanks Left Finger (11)] ([Any Muscle D: 50.8%])
1 49370 Franks and Beans (45) 2022-07-05 [Fransk and Beans (45)] ([Type 2 fun: 96.3%, My happy place:94.1% ,Any End: 94.0%, Any Muscle D: 61.5%])
This should do it. To be clear, this will create a list of dictionaries not a list of lists, although, based off what you have written, I'm not sure which one of those you want. For a list of lists, change
dict1 = {}tolist1 = [],dict1[Potential_Cond_lst[i][n]] = Confidence_lvl_lst[i][n]tolist1.append(Potential_Cond_lst[i][n]+':'+Confidence_lvl_lst[i][n]), andComplete_lst.append(dict1)toComplete_lst.append(list1).EDIT: My original script did not perform the proper behavior, so I have edited it such that it now should. I would also like to note, just to be clear, that the syntax of your expected output is invalid;
['Any Muscle Dis': '50.8%'], an example I took from the output that you wrote you are hoping for, will throw errors because values in lists are separated from each other with commas, not colons. The two closest syntaxes that I could think of for what you desire are a list of dictionaries (what the above code outputs) in the form[{'key':'val'},{...}]and a list of lists in the form[['key : val'],[...]], which can be output by making the changes that I referenced above.