I have a dictionary with key and value pairs. I also have a data frame with a column containing strings that contain the various keys. If a key appears in the column in the data frame, I'd like to append the corresponding value in the adjacent column
my_dict = {'elon' : 'is awesome', 'jeff' : 'is not so awesome, but hes ok, ig', 'mustard' : 'is gross', 'pigs' : 'can fly'}
my_dict
import pandas as pd
import numpy as np
pd.DataFrame({'Name (Key)' : ['elon musk', 'jeff bezos and elon musk', 'jeff bezos', 'she bought mustard for elon'], 'Corresponding Value(s)' : [np.nan, np.nan, np.nan, np.nan]})
Desired output:
# Desired output:
pd.DataFrame({'Name (Key)' : ['elon musk', 'jeff bezos and elon musk', 'jeff bezos', 'she bought mustard for elon'],
'Corresponding Value(s)' : [['is awesome'], ['is not so awesome, but hes ok, ig', 'is awesome'], ['is not so awesome, but hes ok, ig'], ['is gross', 'is awesome']]})
I am new to python, but assume there will be the apply function used in this. Or perhaps map()? Would an if statement be plausible, or is there a better way to approach this?