I am trying to make a word cloud from my dataframe, below
Borough Minor Text 2019
Bexley Arson 4
Bexley Burglary - Business 11
Bexley Burglary - Residential 130
Bexley Drug Trafficking 5
I want to visualise the most frequent items in the Minor Text column in a wordcloud but the problem is, the frequency is in the '2019' column as an integer. The actual dataframe is quite large but follows the same format as above. Can anyone suggest how I can transform my 'Minor Text' column so that I can accurate create a word cloud?
Thanks
CodePudding user response:
I don't know the visualization criteria. For example PowerBI's wordcloud does not accept an integer value to control the size of the word, but it bases it on how many items it is repetead. Therefore, the way I deal with it is by transforming the text into a list and then multiplying it by the integer (hence repeating the text the number of times the integer says) and then PowerBI sees row 3 is repetead 130 times while row 4 only 5 times, making row 3's text 26 times larger than row 4's text.
Having explained this, this is the line of code I use:
df['Visual text'] = df['Minor Text'].map(lambda x: [x]) * df['2019']