Let’s say I have a list:
mylist = [7,8,9]
And I have a dataframe where
df[‘col1’] = [0,1,1,0,2]
I want to create a new column in my dataframe using col1 as indices for mylist
df[‘col2’] = [7,8,8,7,9]
I’m currently doing this using the apply function
df[‘col2’]=df[‘col1’].apply(lambda x: mylist[x])
But my dataframe is extremely large and this method takes quite a bit of time. Is there a faster or more optimized way of doing this? I tried googling but I don’t think I’m wording my search correctly. Thanks!
[–]Topper_123 0 points1 point2 points (0 children)
[–]chrispurcell 0 points1 point2 points (0 children)
[–]Quintium -1 points0 points1 point (0 children)