utils4text.py
def compute_sentiment(subreddit_convs_clean, analyzer = SentimentIntensityAnalyzer()):
    """
    Calculate the conversation sentiment via the built sentiment analyzer.

    Args:
        subreddit_convs_clean: A dataframe containing clean conversations.
        analyzer: A built analyzer for sentiment analysis.
    Return:
        subreddit_convs_clean: A dataframe added with sentiment prediction.
    """
    # transform text column to string type
    subreddit_convs_clean['text'] = subreddit_convs_clean['text'].astype(str)

    # add one column to specify the value of sentiment
    subreddit_convs_clean['compound'] = subreddit_convs_clean['text']\
                                            .swifter.apply(lambda text: analyzer.polarity_scores(text)['compound'])
    
    # add another column for determining the type of sentiment
    subreddit_convs_clean['sentiment'] = subreddit_convs_clean['compound']\
                                            .swifter.apply(determine_pos_neu_neg)

    return subreddit_convs_clean

    Calculate the conversation sentiment via the built sentiment analyzer.

    Args:
        subreddit_convs_clean: A dataframe containing clean conversations.
        analyzer: A built analyzer for sentiment analysis.
    Return:
        subreddit_convs_clean: A dataframe added with sentiment prediction.
    
Calculate the conversation sentiment via the built sentiment analyzer.
Calculate the conversation sentiment via the built sentiment analyzer .
def compute_sentiment(subreddit_convs_clean, analyzer = SentimentIntensityAnalyzer()):
    subreddit_convs_clean['text'] = subreddit_convs_clean['text'].astype(str)
    subreddit_convs_clean['compound'] = subreddit_convs_clean['text']\
                                            .swifter.apply(lambda text: analyzer.polarity_scores(text)['compound'])
    subreddit_convs_clean['sentiment'] = subreddit_convs_clean['compound']\
                                            .swifter.apply(determine_pos_neu_neg)
    return subreddit_convs_clean
def compute_sentiment ( subreddit_convs_clean , analyzer = SentimentIntensityAnalyzer ( ) ) : subreddit_convs_clean [ 'text' ] = subreddit_convs_clean [ 'text' ] . astype ( str ) subreddit_convs_clean [ 'compound' ] = subreddit_convs_clean [ 'text' ] . swifter . apply ( lambda text : analyzer . polarity_scores ( text ) [ 'compound' ] ) subreddit_convs_clean [ 'sentiment' ] = subreddit_convs_clean [ 'compound' ] . swifter . apply ( determine_pos_neu_neg ) return subreddit_convs_clean
Calculate the conversation sentiment via the built sentiment analyzer.
Calculate the conversation sentiment via the built sentiment analyzer .
"""
    Calculate the conversation sentiment via the built sentiment analyzer.

    Args:
        subreddit_convs_clean: A dataframe containing clean conversations.
        analyzer: A built analyzer for sentiment analysis.
    Return:
        subreddit_convs_clean: A dataframe added with sentiment prediction.
    """ # transform text column to string type # add one column to specify the value of sentiment # add another column for determining the type of sentiment
subreddit_convs_clean
A dataframe containing clean conversations.
A dataframe containing clean conversations .
analyzer
A built analyzer for sentiment analysis.
A built analyzer for sentiment analysis .