community
cancel
Showing results for 
Search instead for 
Did you mean: 

Alteryx designer Discussions

Find answers, ask questions, and share expertise about Alteryx Designer.

Sentiment scoring using Python - NO API needed!

Highlighted
Alteryx
Alteryx

Hi All,

 

Between @DavidM and myself we have shown numerous weird and wonderful ways to extract text from PDF and Word docs using a mix of Python or R.

 

Once you have the raw text what else could you do with it......

 

Recently I was speaking to a few Banking customers, they love the idea of carrying out sentiment scoring on their data but due to security they are unable to do this easily without pushing their sensitive data out via an API - Which obviously is not a viable option.

 

I thought this is a great challenge and set out to build an offline sentiment scoring macro. It also ties in with the previous parsing examples built to extract text from pdf/word docs.

 

Trawling through the web and talking to our very own good Dr, @NickJ I came across this: http://t-redactyl.io/blog/2017/04/using-vader-to-handle-sentiment-analysis-with-social-media-text.ht...

 

It allows for sentiment scoring without having to use 3rd party API's - perfect!!

 

So to get this working you need the following python package to be installed: vaderSentiment

 

To help you on your way I have attached my completed workflow along with the macro and a test file.

 

sentiment.jpg

 

Happy scoring!!

 

Kind regards

 

Shaan

Alteryx
Alteryx

Top work Shaan!

 

We definitely needed to catch up. I was doing a very similar thing using TextBlob.

 

I have kept the python minimal, just appending the polarity and subjectivity. You can work out the sentiment then in Alteryx, rather than Python

 

My original use case was Twitter data. Hence the reference in the code, but should be very straight forward to change the name of the columns.

 

from ayx import Alteryx
Package.installPackages(['textblob']) from textblob import TextBlob tweetdata = Alteryx.read("#1") polarityval = [] i = 0 while (i<len(tweetdata)): p = TextBlob(tweetdata.iloc[i]['Tweet']) polarityval.append(p.polarity) i = i+1 tweetdata["polarity"] = polarityval subjectivityval = [] i = 0 while (i<len(tweetdata)): s = TextBlob(tweetdata.iloc[i]['Tweet']) subjectivityval.append(s.subjectivity) i = i+1 tweetdata["subjectivity"] = subjectivityval Alteryx.write(tweetdata,1)

Also, everyone remember, to install new packages you need to make sure Alteryx is running under admin privileges.

 

TextBlob.png

Alteryx
Alteryx

@JoeS very cool example!!

Alteryx
Alteryx

@ChrisHe and I made some changes to allow you to feed in data, rather than a file.  This would seem handy attaching to some social media tools.

 

Sorry no floating @ShaanM head in this one.

Scott Jones
Solutions Consultant
Alteryx, Inc.
Labels