Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Please help :)
#1
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

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
Reply


Messages In This Thread
Please help :) - by crystalteoh92 - Oct-09-2017, 03:54 AM
RE: Please help :) - by buran - Oct-09-2017, 06:31 AM
RE: Please help :) - by crystalteoh92 - Oct-09-2017, 07:06 AM
RE: Please help :) - by buran - Oct-09-2017, 07:13 AM
RE: Please help :) - by crystalteoh92 - Oct-09-2017, 08:13 AM
RE: Please help :) - by buran - Oct-09-2017, 08:23 AM
RE: Please help :) - by crystalteoh92 - Oct-09-2017, 08:43 AM
RE: Please help :) - by buran - Oct-09-2017, 08:59 AM
RE: Please help :) - by crystalteoh92 - Oct-09-2017, 09:20 AM
RE: Please help :) - by buran - Oct-09-2017, 10:10 AM
RE: Please help :) - by snippsat - Oct-09-2017, 11:49 AM
RE: Please help :) - by buran - Oct-09-2017, 02:00 PM
RE: Please help :) - by crystalteoh92 - Oct-10-2017, 01:04 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020