I'm trying to count the number of words in two different columns and safe the result of the addition in an extra column.
Example of the data and desired result:
id question answer word_count
1 Lorem ipsum dolor sit amet Lorem ipsum dolor 8
2 Lorem ipsum ipsum 3
3 Lorem ipsum dolor sit Lorem 5
Following code is not working:
df['word_count'] = df[['question', 'answer']].apply(lambda x: len(str(x).split(" ")))