0

I have a pandas dataframe with N rows.

Every row N has many words.

I am trying to plot wordloud for each column.

df:

    prediction                    text
0           1  [menu, food, food and chicken...
1           2  [transfer, money, transfer, transfer, trans...
2           0  [cold,cold,cold,hot,love...

code

import matplotlib.pyplot as plt
from wordcloud import WordCloud, STOPWORDS

def show_wordcloud(data, title):

        wordcloud = WordCloud(
        background_color='white',
        max_words=200,
        max_font_size=40,
        scale=3,
    ).generate(str(data))


    fig = plt.figure(1, figsize=(12, 12))
    plt.axis('off')

    if title:
        fig.suptitle(title, fontsize=20)
        fig.subplots_adjust(top=2.3)


    plt.imshow(wordcloud)
    plt.savefig('cluster{}.png'.format(title))
    plt.show()


for row in df.iterrows():
    show_wordcloud(row['text'], row["prediction"])

But What I get is the blank images for all the columns except for the lat one.

How do I fix this?

Thanks

user2510479
  • 1,528
  • 13
  • 17
Jerry George
  • 335
  • 1
  • 7
  • 23

0 Answers0