python - 在 WordCloud 中使用 Include_Numbers 功能时出现类型错误
问题描述
我正在尝试在 python 中使用 WordCloud 包,并且在尝试使用 include_numbers 参数时遇到错误。我已经复制了包的 github 链接,具体的参数定义(我已经尝试了正确的拼写并注意到了不正确的拼写),我得到了以下错误
https://amueller.github.io/word_cloud/generated/wordcloud.WordCloud.html
incldue_numbers:bool, default=False 是否包含数字作为短语。
TypeError: init () got an unexpected keyword argument 'include_numbers'
我正在尝试运行的部分:
import numpy as np # linear algebra
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
##%matplotlib inline
from subprocess import check_output
from wordcloud import WordCloud, STOPWORDS
#mpl.rcParams['figure.figsize']=(8.0,6.0) #(6.0,4.0)
mpl.rcParams['font.size']=12 #10
mpl.rcParams['savefig.dpi']=100 #72
mpl.rcParams['figure.subplot.bottom']=.1
stopwords = set(STOPWORDS)
data = pd.read_csv("C:\\Users\\chris\\Documents\\testing\\wc_ad_copy_test.csv")
##test below
#data['dupe_copy'] = data['dupe_copy'].astype(str)
##end test
wordcloud = WordCloud(
background_color='white',
stopwords=stopwords,
max_words=200,
max_font_size=40,
random_state=42,
include_numbers=True,
#collocations=True,
normalize_plurals=False
).generate(str(data['scored_copy']))
print(wordcloud)
fig = plt.figure(1)
plt.imshow(wordcloud)
plt.axis('off')
plt.show()
fig.savefig("ad_copy_cloud_image.png", dpi=900)
wc = WordCloud(
background_color='white',
stopwords=stopwords,
max_words=200,
max_font_size=40,
random_state=42,
include_numbers=True,
#collocations=True,
normalize_plurals=False
)
word_dict = wc.process_text(str(data['scored_copy']))
df = pd.DataFrame.from_dict(word_dict, orient='index')
df = df.reset_index()
df.columns = ['word', 'word_count']
df = df.sort_values(by='word_count', ascending=False)
df.to_csv("word_count_list.csv", index=False)
include_numbers 在运行为“False”时会引发相同的错误
我希望这可以运行并将数字输出到 wordcloud
解决方案
我查看了wordcloud源代码,问题似乎是github上的代码和pip安装的pypi包不一样。pip安装时得到的版本不包含include_numbers参数。
我在这里在 github 上提交了这个问题:https ://github.com/amueller/word_cloud/issues/482如果你想关注并看看开发人员怎么说。
推荐阅读
- django - 虚拟环境转移
- reactjs - 通过字符串名称动态导入和组件渲染
- reactjs - 缓存包含多个满足要求的令牌
- android - 我可以/应该在 Kotlin 中按顺序编写这些相互依赖的 Volley 调用吗?
- html - Margin-top 不会根据媒体查询而改变
- python - 情节:情节表达 add_vrect 到图的问题
- excel - Excel PageSetup 多张工作表
- node.js - Firebase 推送令牌只工作几次
- flutter - 如何创建带有嵌入文本的文本边框以及如何在框中添加多个文本字段?
- javascript - 变量本身改变 Angular 的值