pythontwittertweepysentiment-analysistextblob

How to remove unexpected parameter and attribute errors while importing data for sentiment analysis from twitter?


Q) How to solve the following errors

1)Unexpected parameter: Lang

2)Unexpected parameter: tweet_node

3)line 25, in tweets = [tweet.full_text for tweet in tweet_cursor ]

AttributeError: 'Status' object has no attribute 'full_text'

CODE

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('https\S+','' , 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()

Solution

    1. lang=en should be inside of the value of search.
    2. tweet_node should be tweet_mode
    3. The full_text will only exist if the tweet_mode=extended parameter is correct, and the Tweet is more than 140 characters in text length.