Imagine that you have a data frame of tweets and you want to create a word cloud. You can do it using the wordcloud library. In this example the data variable is a Pandas dataframe which has a columns Tweet.

from wordcloud import WordCloud, STOPWORDS
import matplotlib.pyplot as plt
text = data.Tweet.values
wordcloud = WordCloud(
    width = 3000,
    height = 2000,
    background_color = 'black',
    stopwords = STOPWORDS).generate(str(text))
fig = plt.figure(
    figsize = (40, 30),
    facecolor = 'k',
    edgecolor = 'k')
plt.imshow(wordcloud, interpolation = 'bilinear')
plt.axis('off')
plt.tight_layout(pad=0)
plt.show()

In real life, you should do some preprocessing and remove words which should not appear in the output plot. In case of tweets, you may need to remove not only the stopwords but also URLs and nicknames.

Want to build AI systems that actually work?

Download my expert-crafted GenAI Transformation Guide for Data Teams and discover how to properly measure AI performance, set up guardrails, and continuously improve your AI solutions like the pros.

Older post

Scala structural types with generics

A short example of defining a structural type which matches a generic class

Newer post

Monte Carlo simulation in Python

How to make business decisions using the Monte Carlo simulation?

Are you looking for an experienced AI consultant? Do you need assistance with your RAG or Agentic Workflow?
Book a Quick Consultation, send me a message on LinkedIn. Book a Quick Consultation or send me a message on LinkedIn

>