I have a function:
def lookup(group, name):
try:
#sql query with group and name
return answer
except:
return 'NULL'
And a pandas Dataframe:
+------------+------+
| group | name |
+------------+------+
| redteam | paul |
| blueteam | pat |
| yellowteam | mike |
+------------+------+
I want to feed the group and name of each row into my 'lookup' function, and return the answer for the row as a cell in a 3rd column: 'value'
I've looked at this and this question. but they're not quite what I'm doing.
I've also looked at THIS question. Which IS what I'm doing. but it also didn't succeed for me.
I've tried this:
df['value'] = lookup(df[0],df[1])
and this:
df['value'] = df.apply(lambda x: lookup(x[0], x[1]), axis=1)
but it just makes the value column all 'NULL'
Any suggestions from here are much appreciated.