image_output_1.png
from nltk.corpus import stopwords

from nltk.stem import WordNetLemmatizer

from sklearn.feature_extraction.text import CountVectorizer

from wordcloud import WordCloud

import json

import matplotlib.pyplot as plt

import pandas as pd

import re

import string

n_common_words = 50
wnl = WordNetLemmatizer()
engstopwords = stopwords.words('english')
engstopwordsV2 = re.sub('[' + re.escape(string.punctuation) + ']', '', ' '.join(engstopwords)).split()
with open('../input/mbtiadditionalwords/additional-stopwords.json') as file:
    additional_stopwords = json.load(file)
engstopwords.extend(additional_stopwords)
engstopwords = set(engstopwords).union(set(engstopwordsV2))
str_punc = string.punctuation
filename = '../input/mbti-type/mbti_1.csv'
cv = CountVectorizer(stop_words='english')
plt.rcParams['figure.dpi'] = 300
wc = WordCloud(stopwords=engstopwords, background_color='white', colormap='Dark2', max_font_size=150, random_state=42, width=800, height=400)

dataset = pd.read_csv(filename)
dataset = dataset.groupby(['type'])['posts'].apply(lambda x: '. '.join(x)).reset_index()
dataset.head(16)