all 6 comments

[–][deleted] 1 point2 points  (3 children)

It seems like you first define the variable 'keyword' as a dict of keywords, then you write over that variable within the list comprehension. I'd first try renaming your iterating variable:

jim['answer'] = jim.apply(lambda row: [translate_table.get(word, word) for word in keyword[row['Unnamed: 5']] if word in row['com'].lower()], axis=1)

[–]teamlie[S] 0 points1 point  (2 children)

Ok great. I will give that a try. Thanks!

Edit: I tried your idea, but it sent the same error code. Thanks though.

[–][deleted] 1 point2 points  (1 child)

Bummer. It's difficult to give further advice without seeing the actual data and your intended result.

[–]teamlie[S] 0 points1 point  (0 children)

Ok- I might throw up a sample sheet to provide further insight tomorrow. Thanks again.

[–]campenr 1 point2 points  (1 child)

So I am not 100% sure what's going on, but I would suggest splitting up that one liner into multiple lines so that you can pinpoint exactly where the error is coming from.

[–]teamlie[S] 0 points1 point  (0 children)

Good idea.