<jupyter_start><jupyter_text>Tweets<jupyter_code>import pandas as pd
from textblob import TextBlob
import re

pd.set_option('display.max_colwidth',240)
TWEET_DATA_FILE = 'data/twitter-airline-sentiment/Tweets.csv'
tweets = pd.read_csv(TWEET_DATA_FILE, usecols=['text'])
tweets.columns = ['Tweet']
tweets.head(10)
tweets['At'] = tweets.Tweet.str.extract(r'^(@\S+)')
tweets.head(20)
def remove_handles(tweet):
    return re.sub(r'@\S+', '', tweet)
tweets.Tweet = tweets.Tweet.apply(remove_handles)
tweets.head(10)<jupyter_output><empty_output><jupyter_text>TextBlob<jupyter_code>sentence = "but you are Late Flight again!! Again and again! Where are the crew?"
blob = TextBlob(sentence)
blob
blob.sentiment
def get_sentiment(dataframe, column):
    text_column = dataframe[column]
    textblob_sentiment = text_column.apply(TextBlob)
    sentiment_values = [ {'Polarity': v.sentiment.polarity, 
                          'Subjectivity': v.sentiment.subjectivity}
                   for v in textblob_sentiment.values]
    return pd.DataFrame(sentiment_values)
sentiment_frame = get_sentiment(tweets, 'Tweet')
sentiment_frame.head(4)
tweets = pd.concat([tweets, sentiment_frame], axis=1)
tweets.head(10)
tweets.Subjectivity.min()
positive_tweets = tweets[tweets.Polarity > 0.5]
negative_tweets = tweets[tweets.Polarity < - 0.5]
positive_tweets.head(15)
negative_tweets.head(15)
neutral_tweets = tweets[ (tweets.Polarity > -0.1) & (tweets.Polarity < 0.1) ]
neutral_tweets<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13226452905811623, 'fraction_numerical': 0.016700066800267203, 'mean_word_length': 5.599118942731278, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '261305', 'license': 'MIT', 'n_tokens_mistral': 595, 'n_tokens_neox': 572, 'n_words': 90, 'path': 'Lesson8/Activity13.ipynb', 'repo_name': 'TrainingByPackt/Introduction-to-Natural-Language-Processing', 'size': '1497'}