【发布时间】:2020-10-18 01:49:31
【问题描述】:
在这里,我想打印一个词云。我有一个不同的解决方案,但我想知道我的错误是什么。有人可以检查一下吗?我收到类型错误:图像数据无法转换为浮点数。
def calculate_frequencies(file_contents):
# Here is a list of punctuations and uninteresting words you can use to process your text
punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
uninteresting_words = ["the", "a", "to", "if", "is", "it", "of", "and", "or", "an", "as", "i", "me", "my", \
"we", "our", "ours", "you", "your", "yours", "he", "she", "him", "his", "her", "hers", "its", "they", "them", \
"their", "what", "which", "who", "whom", "this", "that", "am", "are", "was", "were", "be", "been", "being", \
"have", "has", "had", "do", "does", "did", "but", "at", "by", "with", "from", "here", "when", "where", "how", \
"all", "any", "both", "each", "few", "more", "some", "such", "no", "nor", "too", "very", "can", "will", "just"]
new_list= ""
new_list2= ""
my_dict= {}
file_contents1=file_contents.split()
for letters in file_contents:
if letters.isalpha():
letters+=new_list2
for letters in new_list2:
if letters not in uninteresting_words or letters not in punctuations:
letters+=new_list
file_content = new_list.lower()
for word in file_content:
if word in my_dict:
my_dict[word] += 1
else:
my_dict[word] = 1
return my_dict
print(new_list2)
#wordcloud
cloud = wordcloud.WordCloud()
cloud.generate_from_frequencies(my_dict)
return cloud.to_array()
myimage = calculate_frequencies(file_contents)
plt.imshow(myimage, interpolation = 'nearest')
plt.axis('off')
plt.show()
【问题讨论】:
标签: python dictionary debugging word-count