I have the following data in Python:
list1=[[ENS_ID1,ENS_ID2,ENS_ID3], [ENS_ID10,ENS_ID24,ENS_ID30] , ....]
mapping (a dataframe where in the first column I have an Ensemble gene ID and in the second column the corresponding MGI gene ID)
ENS_ID | MGI_ID |
---|---|
ENS_ID1 | MGI_ID1 |
ENS_ID2 | MGI_ID2 |
I'm trying to obtain another list of lists where instead of the ENS_ID I have the MGI_ID. To map the IDs I'm using a for cycle nested inside another one, but obviously, it's really slow as an approach. How can I speed it up? Here's the code:
for l in ens_lists:
mgi = []
for i in l:
mgi.append(mapping['MGI_ID'][mapping[mapping['ENSEMBL_ID']==i].index].values[0])
mgi_lists.append(mgi)