如何在从twitter导入情绪分析数据时删除意外的参数和属性错误



Q(如何解决以下错误

1( 意外参数:Lang

2( 意外参数:tweet_node

3( 第25行,intweets=[tweet_full_text for tweet_cursor]

AttributeError:"Status"对象没有属性"full_text">

代码

import tweepy
import textblob
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import re

api_key = 'xxxxx'
api_key_secret = 'xxxxxxx'
access_token = 'xxxxxxxxxxxxxxxx'
access_token_secret = 'xxxxxxxxxxxxxxxxxxxxxx'
authenticator = tweepy.OAuthHandler(api_key, api_key_secret)
authenticator.set_access_token(access_token, access_token_secret)
api= tweepy.API (authenticator, wait_on_rate_limit=True)
crypto_currency= "Dogecoin"
search= f'#(crypto currency) -filter: retweets'
tweet_cursor = tweepy.Cursor(api.search_tweets, q=search, Lang='en', `tweet_node='extended').items (100)`
tweets = [tweet.full_text for tweet in tweet_cursor ]
tweets_df = pd.DataFrame(tweets , columns = ['Tweets'])
for _, row in tweets_df.iterrows():
row ['tweets'] = re.sub('httpsS+','' , row['Tweets'])
row['tweets'] = re.sub('#S+', '', row['Tweets'])
row['tweets'] = re.sub('@S+', '', row['Tweets'])
row['tweets'] = re.sub('\n', '', row['Tweets'])
tweets_df['Polarity'] = tweets_df['Tweets'].map(lambda tweet:textblob.TextBlob(tweet).sentiment.polarity)
tweets_df['Result'] = tweets_df['Polarity'].map(lambda pol:'+' if pol > 0 else '-')
positive = tweets_df[tweets_df.Result == '+'].count()['Tweets']
negative = tweets_df[tweets_df.Result == '-'].count()['Tweets']
plt.bar([0,1], [positive,negative], label=['Positive', 'Negative'], color=['green', 'red'])
plt.legend
plt.show()
  1. lang=en应在search的值内
  2. tweet_node应为tweet_mode
  3. 只有当tweet_mode=extended参数正确,并且Tweet的文本长度超过140个字符时,full_text才会存在

最新更新