Oct-09-2017, 03:54 AM
Hi all, I am new to Python and currently doing NLTK sentiment analysis on customer reviews. I have a SAS data set that stores all customer review and i import it into Python and it turn into Data Frame. I try to convert the dataframe into list and apply Sentiment Intensity Analyzer, but it doesn't seem to work.
Can anyone please help? Thanks
Currently I'm getting this error
Can anyone please help? Thanks
mydata = pd.read_sas('C:\\Users\\00124118\\Desktop\\call_center_data.sas7bdat') dfList = mydata['DESCRIPTION'].tolist() import nltk from nltk.sentiment.vader import SentimentIntensityAnalyzer analyzer = SentimentIntensityAnalyzer() call = [] vs_compound = [] vs_pos = [] vs_neu = [] vs_neg = [] for i in range(0, len(dflist)): call.append(dflist[i]['text']) vs_compound.append(analyzer.polarity_scores(dflist[i]['text'])['compound']) vs_pos.append(analyzer.polarity_scores(dflist[i]['text'])['pos']) vs_neu.append(analyzer.polarity_scores(dflist[i]['text'])['neu']) vs_neg.append(analyzer.polarity_scores(dflist[i]['text'])['neg']) from pandas import Series, DataFrame final = DataFrame({'Call': call, 'Compound': vs_compound, 'Positive': vs_pos, 'Neutral': vs_neu, 'Negative': vs_neg}) final = final[['Call', 'Compound','Positive', 'Neutral', 'Negative']]
Currently I'm getting this error
Error: File "<ipython-input-119-00c678e5dcd7>", line 2, in <module>
call.append(dflist[i]['text'])
TypeError: byte indices must be integers or slices, not str