Skip to content
Advertisement

Array of tuples necessary for generate_from_frequencies method in Python wordcloud

I am trying to make a word cloud in Python from the significance of strings and their corresponding data values in an Excel document. The generate_from_frequencies method takes a frequencies parameter which the docs say is supposed to take an array of tuples.

Partial code from wordcloud source code:

JavaScript

I tried using a regular list, then I tried a ndarray from numpy, but PyCharm shows warnings that the parameter type should be array.py, which I read is only supposed to take characters, integers, and floating point numbers (array.py docs):

This module defines an object type which can compactly represent an array of basic values: characters, integers, floating point numbers.

My test code:

JavaScript

If I run the code above despite the PyCharm warning, I get the following error, which I suppose is another way of telling me that it can’t accept the ndarray type:

JavaScript

Another potential problem could be that wordcloud was written in Python 2 but I am using Python 3.4, which may have rendered some of the code unusable. What type should I pass this method?

Advertisement

Answer

Thanks to J Herron and selva for the answer to use tuples instead of a list object– and I ended up with this:

JavaScript

Word cloud generated

It still came up as an error in my IDE, which was misleading, but it worked the way it was supposed to.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement