I'm working with two dataframes:
1. name_basics:
nconst primaryName
0 nm0000001 Fred Astaire
1 nm0000002 Lauren Bacall
2 nm0000003 Brigitte Bardot
3 nm0000004 John Belushi
4 nm0000005 Ingmar Bergman
2. title_directors:
tconst directors
0 tt0000574 nm0846879
1 tt0000591 nm0141150
2 tt0000679 nm0091767,nm0877783
3 tt0001184 nm0063413,nm0550220
4 tt0001258 nm0088881
What i'm looking for is something like this:
tconst directors
0 tt0000574 name1
1 tt0000591 name2
2 tt0000679 name3,name4
3 tt0001184 name5,name6
4 tt0001258 name7
I tried to do so by defining a function getNames and then doing
title_directors['directors'] = title_directors['directors'].apply(getNames)
def getNames(nconsts):
nconstList = nconsts.split(',')
retString = ''
for nconst in nconstList:
df = name_basics[name_basics['nconst'] == nconst]['primaryName']
if not df.empty:
retString += df.iloc[0] + ', '
return retString[:-2]
getNames('nm0063413,nm0550220')
'Ricardo de Baños, Alberto Marro'
But this is way too slow (it would take like 80hrs on my computer). I was wondering what is the correct way to do this.
Thank you very much