I am extremely new to Python. I have a huge dataframe that contains two variables in list format. It has a dimension of 1416631 x 2.
I am trying to extract the first element of the list to create another variable. However, the current code has been running for over an hour to no avail.
Here is a snippet of the dataframe MH
with two variables, col
and PMID
(which is currently empty):
col PMID
[1, Aged, Adult, Child]
[53, Humans, Kidney Injury]
[22, Diagnostic Imaging, Aged]
This is what I want it to look like (2 variables: PMID
and col
):
col PMID
[Aged, Adult, Child] 1
[Humans, Kidney Injury] 53
[Diagnostic Imaging, Aged] 22
Here is my code:
# extract PMID
for index, row in MH.iterrows():
MH["PMID"][index] = MH["col"][index][0]
This code works on a smaller dataframe, but doesn't stop running on my larger dataframe.
Please advise. Thanks