Generating WordCloud for a numerical column

I want to know if it is possible to generate a wordcloud on a numerical dataframe column whose values could be useful to interpret in a wordcloud.

I tried to do this :

text = df['tag'].value_counts().to_dict()

wordcloud = WordCloud().generate_from_frequencies(text)

but got this error :

TypeError: argument of type ‘int’ is not iterable

Anyone can help ? Thanks

Answer

Convert your tag column to string: .astype(str)

import pandas as pd
from wordcloud import WordCloud
import matplotlib.pyplot as plt

df = pd.DataFrame({'tag': [1, 1, 2, 3, 3, 3]})

text = df['tag'].astype(str).value_counts().to_dict()
wc = WordCloud().generate_from_frequencies(text)

plt.imshow(wc)
plt.show()

Tag from numbers