I have a nested for loop something like:
for x in df['text']:
for i in x:
if i in someList:
count++
Where df['text'] is a series of lists containing words such as ['word1', 'word2', 'etc']
I know I can just use the for format but I want to convert it into a lambda function.
I tried doing:
df['in'] = df['text'].apply(lambda x: [count++ for i in x if i in someList])
but it is not proper syntax. How can I modify to get the function to what I desire?
I feel like you need expend the row and doing with isin , since with pandas , we usually try not use for loop .
df['in']=pd.DataFrame(df['text'].tolist(),index=df.index).isin(someList).sum(1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With