Skip to content
Advertisement

Running a for loop or .apply with a pandas series

I’m trying to run a for loop or .apply using lambdas for my pandas series. Here’s the code:

JavaScript

What I’m trying to achieve is for each word in df['Filtered_text'], apply the analyzer.polartiy_scores(x['Filtered_text']) through the column.

An example of what is stored in df['Filtered_text']:

JavaScript

So for every one of those words, I’d like it to be applied to the analyzer.polarity_scores

I’ve also tried this:

JavaScript

But I get this error:

AttributeError: 'list' object has no attribute 'encode'

and this:

JavaScript

Thanks

Advertisement

Answer

I would use a list comprehension to solve this:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement