[英]The code is giving me an error that the name tweepy is not defined , and there occurs error in tweet.text that text attribute is not defined
from textblob import TextBlob import sys import tweepy import matplotlib.pyplot as plt import pandas as pd import numpy as np import os import nltk import pycountry import re import string #情緒分析 def percent(part,whole): return 100 * float(part) /float(whole) keyword = input("請輸入要搜索的關鍵字或標簽:") noOfTweet = int(input ("請輸入要分析的推文數量:")) tweets = tweepy.Cursor(api.search_users, q=關鍵字).items(noOfTweet) 正面 = 0 負面 = 0 中性 = 0 極性 = 0 推文列表 = [] 中性列表 = [] 負面列表 = [] 正面列表 = [] 推文中的推文:
#print(tweet.text)
tweet_list.append(tweet.data)
analysis = TextBlob(tweet.data)
score = SentimentIntensityAnalyzer().polarity_scores(tweet.text)
neg = score['neg']
neu = score['neu']
pos = score['pos']
comp = score['compound']
polarity += analysis.sentiment.polarity
negative += 1
if(pos > neg):
positive_list.append(tweet.text)
positive += 1
elif pos == neg:
neutral_list.append(tweet.text)
neutral += 1
positive = percentage(positive, noOfTweet)
negative = percentage(negative, noOfTweet)
neutral = percentage(neutral, noOfTweet)
polarity = percentage(polarity, noOfTweet)
positive = format(positive, '.1f')
negative = format(negative, '.1f')
neutral = format(neutral, '.1f')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.