I am trying to train the model for recommendation for movie. I have a dataset which has list of all the casts, movie details with description. based on the occurance of name of cast in movie description, I am trying to map it.
df_castes:
name
0 Mark Wahlberg
1 Leonardo DiCaprio
2 Kate Mara
3 Ben Affleck
df_movies:
name description released
0 Departed South Boston cop Billy Costigan (Leonardo DiCaprio) goes under cover, detective (Mark Wahlberg) who ... 2006
1 Shooter A top Marine sniper, Bob Lee Swagger (Mark Wahlberg), who leaves the military, Sarah (Kate Mara) the widow of... 2007
2 Triple Frontier Former Special Forces operative Tom (Ben Affleck) and his team ...... 2019
I am doing something like this in python to create the expected data frame below:
c_list = list()
m_list = list()
for index_m, row_m in df_movies.iterrows():
for index_c, row_c in df_castes.iterrows():
caste = row_c['name']
movie = row_m['name'] # need to add name of the movie in output if caste is mentioned in description
if caste in row_m['description']:
c_list.append(caste)
m_list.append(movie)
output = {"caste_name": c_list, "movie_name": m_list}
df_output = pd.DataFrame(data=output)
print(df_output)
expected output:
caste_name movie_name
0 Mark Wahlberg Departed
1 Leonardo DiCaprio Departed
2 Mark Wahlberg Shooter
3 Kate Mara Shooter
4 Ben Affleck Triple Frontier
I am trying to do it in scala way using map or filter and create new expected dataframe. Any idea on how can use filter or map to do this?