Simple word cloud on msg array

 

from wordcloud import WordCloud


def plt_word_cloud(text):
    wordcloud = WordCloud().generate(text)
    # take relative word frequencies into account, lower max_font_size
    wordcloud = WordCloud(background_color="white",max_words=120,max_font_size=40, relative_scaling=1).generate(text)
    fig = plt.figure(figsize=(10,8))
    plt.imshow(wordcloud)
    plt.axis("off")
    plt.show()

def prepare_cloud_text(df, name='None'):

    df['message']= df['message'].str.replace('omitted', ' ')
    df['message']= df['message'].str.replace('media', ' ')

    text=''

    if name=='None':
        k = df['message']
    else:
        k = df[df['name']==name]['message']

    for i in k:
        text = text+i

    text = (text.encode('ascii', 'ignore')).decode('ascii')
    return text

text = prepare_cloud_text(df)
plt_word_cloud(text)

names = ['Gaurav Meena']
text = prepare_cloud_text(df, name=names[0])
plt_word_cloud(text)

Comments

Popular posts from this blog

Type of Common Charts used in visualization

बैगन

Building a Better Future: Pathways Over Chariots