Www.edgehill.ac.uk



Code snippet 1import nltknltk.download()Code snippet 2import pandasdf = pandas.read_csv('Video_games_reviews.csv', delimiter='\t', header=None)print(df)Code snippet 3import pandasdf = pandas.read_csv('Video_games_reviews.csv', delimiter='\t', header=None)video_review_texts = df[2]print(video_review_texts)Code snippet 4import pandasdf = pandas.read_csv('Video_games_reviews.csv', delimiter='\t', header=None)video_review_texts = df[2]from textblob import TextBlobfor index, review_text in enumerate(video_review_texts): blob = TextBlob(review_text) print('Analysing review:\t', review_text) for sentence in blob.sentences: print('-----SENTIMENT FOR SENTENCE-----') print(sentence, '\t', sentence.sentiment.polarity) print('-----END-----')Code snippet 5import pandasdf = pandas.read_csv('Video_games_reviews.csv', delimiter='\t', header=None)video_review_texts = df[2]print(video_review_texts)from textblob import TextBlobsentiment_classification_labels = []for index, review_text in enumerate(video_review_texts): blob = TextBlob(review_text) number_of_sentences = 0 sum_of_sentiment_polarities = 0.0 print('-----DOCUMENT-----') for sentence in blob.sentences: polarity = sentence.sentiment.polarity if polarity > 0: label='positive' else: label = 'negative' print(sentence, '\t', polarity, '\t', label) sum_of_sentiment_polarities += polarity number_of_sentences += 1 avg_polarity = sum_of_sentiment_polarities/number_of_sentences; if avg_polarity > 0: label='positive' else: label = 'negative' print() print('average sentiment polarity:\t', avg_polarity, '\t', label) print('-----END-----') print() ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download