text_html_output_1.png
from collections import Counter

from nltk.corpus import stopwords, wordnet

from wordcloud import WordCloud

import matplotlib.pyplot as plt

import pandas as pd

import re

import string

data = pd.read_csv('../input/sentiment-analysis-for-financial-news/all-data.csv', names=['Sentiment', 'Tweet'], encoding='latin-1')

temp = data.groupby('Sentiment').count()['Tweet'].reset_index().sort_values(by='Tweet', ascending=False)
temp.style.background_gradient(cmap='Purples')

text = ' '.join([x for x in data.Tweet])
wordcloud = WordCloud(background_color='white').generate(text)
plt.axis('off')

STOPWORDS = set(stopwords.words('english'))
def remove_stopword_punctuation(x):
    return [y for y in x if y not in STOPWORDS and len(y) > 2]
data['list_mots'] = data['list_mots'].apply(lambda x: remove_stopword_punctuation(x))

data = data.drop(['list_mots'], axis=1)

def remove_punct(text):
    """fonction pour supprimer la ponctuation"""
    text = ''.join([char for char in text if char not in string.punctuation])
    text = re.sub('[0-9]+', '', text)
    return text
def remove_stopwords(text, STOPWORDS):
    """fonction pour supprimer les stopwords"""
    return ' '.join([word for word in str(text).split() if word not in STOPWORDS])
def stem_words(text, stemmer):
    """fonction pour extraire les racines des mots"""
    return ' '.join([stemmer.stem(word) for word in text.split()])
def remove_freqwords(text, FREQWORDS):
    """fonction pour supprimer les mots fréquents"""
    return ' '.join([word for word in str(text).split() if word not in FREQWORDS])

count = Counter()
for text in data['Tweet_stemmed'].values:
    for word in text.split():
        count[word] += 1
count.most_common(10)