I am trying to map a specific value from pandas to an existing dictionary and then add that value to my data frame.
x = {'apples':1, "pears":45, 'grapes':7777}
f = df.fruit
>>>f
0 apples
1 grapes
I would like to map df.fruit to dictionary x.
I am trying this:
df['amount'] = df['fruit'].map(x)
I am getting NaN values when I try this. What am I doing wrong here. I thought map was the correct way of doing this but now I am not sure.
df.fruit.str.strip().map(x)