Reputation: 1569
I would like to apply a function while mapping a dataframe with the key's from a dictionary
col1 col2
foo 0
baa 1
wen 2
dict: {
'foo':a,
'baa':b,
'wen':c
}
def function(value1,value2):
return value1+value2
output
col1 col2
fooa 0
baab 1
wenc 2
thanks
Upvotes: 0
Views: 63
Reputation: 199
df["col1"] = df["col1"].apply(lambda x: x + (dict[x]))
Should do the trick
.apply will let you apply a function to the whole column, and you can make a fast, anonymous function with lambda. Here's the docs on this: pandas.Series.apply
Upvotes: 1