<jupyter_start><jupyter_text>Create a dataframe for the scrape news article<jupyter_code>df = pd.read_csv('news_datasets_dated.csv',keep_default_na=False)
print(df.head())<jupyter_output>date                                              Title  \
0  2018-03-05  Ripple Price Rises as new Fake Coinbase Listin...   
1  2018-01-14  ETH Blockchain Processes Over $23B in Transact...   
2  2018-01-07  Bitcoin Cash Price Weekly Analysis – Can BCH/U...   
3  2018-01-04  Bitcoin Gold Technical Analysis – BTG/USD to D...   
4  2018-07-10  Cryptocurrency Market Update: ‘Ethereum Killer...   

                                                Text  year          author  \
0   There are always interesting developments to ...  2018      JP Buntinx   
1   Comparing different blockchain-based ecosyste...  2018      JP Buntinx   
2   Key PointsBitcoin cash price is struggling to...  2018   Aayush Jindal   
3   Key PointsBitcoin gold price failed to move a...  2018   Aayush Jindal   
4   FOMO MomentsAnother red day in crypto land, E...  2018    <NAME>   

  category   source  
0  altcoin  newsbtc  
1  altcoin  newsbtc  
2  altcoin  newsbtc  
3  altcoin  newsbtc  
4  altcoin  [...]<jupyter_text>Sentiment Analysis NLTK<jupyter_code>def percentage(part,whole):
    return 100 * float(part)/float(whole)

# NLTK

def apply_analysis(tweet):
    return SentimentIntensityAnalyzer().polarity_scores(tweet)
# Article Text
text = df
text[['neg','neu','pos','compound']] = df['Text'].apply(apply_analysis).apply(pd.Series)
# Article Title
title = df
title[['neg','neu','pos','compound']] = df['Title'].apply(apply_analysis).apply(pd.Series)

def sentimental_analysis(df):
    if df['neg'] > df['pos']:
        return 'Negative'
    elif df['pos'] > df['neg']:
        return 'Positive'
    elif df['pos'] == df['neg']:
        return 'Neutral'

text['Sentiment_NLTK'] = text.apply(sentimental_analysis, axis = 1)
title['Sentiment_NLTK'] = title.apply(sentimental_analysis, axis = 1)<jupyter_output><empty_output><jupyter_text>TextBlob<jupyter_code>def getSubjectivity(twt):
    return TextBlob(twt).sentiment.subjectivity
def getPolarity(twt):
    return TextBlob(twt).sentiment.polarity
def getSentiment(score):
    if score<0:
        return 'Negative'
    elif score==0:
        return 'Neutral'
    else:
        return 'Positive'
    
text['Subjectivity']=text['Text'].apply(getSubjectivity)
text['Polarity']=text['Text'].apply(getPolarity)    
text['Sentiment_TB']=text['Polarity'].apply(getSentiment)

title['Subjectivity']=title['Title'].apply(getSubjectivity)
title['Polarity']=title['Title'].apply(getPolarity)    
title['Sentiment_TB']=title['Polarity'].apply(getSentiment)<jupyter_output><empty_output><jupyter_text>Save dataframe as CSV<jupyter_code>text.to_csv('news_datasets_text.csv', encoding='utf-8-sig',index= False)
title.to_csv('news_datasets_title.csv', encoding='utf-8-sig',index= False)

print('Done')<jupyter_output>Done
{'fraction_non_alphanumeric': 0.1268325946130242, 'fraction_numerical': 0.029321513808387316, 'mean_word_length': 3.732258064516129, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '567266', 'license': 'MIT', 'n_tokens_mistral': 1041, 'n_tokens_neox': 973, 'n_words': 212, 'path': '[Codes]Sentiment_Analysis/News_Article_Sentiment_Analysis.ipynb', 'repo_name': 'sss2107/MSBA_DBA5102_Project', 'size': '2939'}