Exemplo n.º 1
0
def remove_stop_words(column):
    '''gets rid of any words that are on the stop word list'''
    cleaned_responses = []
    for response in column:
        cleaned_response = TextBlob('').words
        for word in response:
            if word not in stop_words:
                cleaned_response.append(word)
        cleaned_responses.append(cleaned_response)
    return cleaned_responses
Exemplo n.º 2
0
def column_lemmatize(column):
    '''Lemmatizes down an entire column'''
    lemmatized_goals = []
    for response in column.apply(lambda goal: goal.tags):
        lemmatized_words = TextBlob('').words
        for word_and_tag in response:
            corrected_tag = _penn_to_wordnet(word_and_tag[1])
            lemmatized_words.append(word_and_tag[0].lemmatize(corrected_tag))
        lemmatized_goals.append(lemmatized_words)
    return lemmatized_goals
score.sentiment

import pandas as pd
df = pd.DataFrame()

tweets = []
for i in public_tweets:
    tweets.append(i.text)
df['Tweets'] = tweets
df

sentiment = []
for i in public_tweets:
    s = (TextBlob(i.text)).sentiment
    sentiment.append(s)
df['Sentiments'] = sentiment
df

score = []
for i in public_tweets:
    s = (TextBlob(i.text)).sentiment
    if s[0] > 0:
        score.append("Postive")
    elif s[0] < 0:
        score.append("Negative")
    else:
        score.append("Neutral")
df['Score'] = score

df
Exemplo n.º 4
0
import pandas as pd
data = pd.DataFrame()

# Extract the 15 tweets
tweets = []
for i in public_tweets:
    tweets.append(i.text)
data['Tweets'] = tweets
print(data)

# Calculating the score for 15 tweets
score = []
for i in public_tweets:
    s = (TextBlob(i.text)).sentiment
    score.append(s)
data['Sentiments'] = score
print(data)

metrics = []
for i in public_tweets:
    s = (TextBlob(i.text)).sentiment
    if s[0] > 0:
        metrics.append("Positive")
    elif s[0] < 0:
        metrics.append("Negative")
    else:
        metrics.append("Neutral")
data['Metric'] = metrics
print(data)