df = pd.read_excel (r'C:\Users\Desktop\train.xlsx', sheet_name='SunValley')
print (df.head(10))
from wordcloud import WordCloud
text = open(df,'r',encoding='utf-8').read()
wc =WordCloud(
max_font_size=110,
max_words=100,
font_path='C:\Windows\Fonts\simkai.ttf',
background_color="white",
width=800,
height=500,
random_state = 20).generate(str(text))
plt.figure(figsize=(10, 7))
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis('off')
plt.savefig("Wordcloud for comments.png", dpi = 300)
plt.show()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-30-710a292a210d> in <module>
1 from wordcloud import WordCloud
----> 2 text = open(df,'r',encoding='utf-8').read()
3 wc =WordCloud(
4 max_font_size=110,
5 max_words=100,
TypeError: expected str, bytes or os.PathLike object, not DataFrame
我的excel文档是中文的,想知道哪里错了,怎么改正?谢谢!!
不需要df = pd.read_excel (r'C:\Users\Wang Meiqi\Desktop\train.xlsx', sheet_name='SunValley') 这个
把excel文件的内容导出成txt文件(比如导出为r'C:\Users\Wang Meiqi\Desktop\train.txt');
然后 text = open(r'C:\Users\Wang Meiqi\Desktop\train.txt','r',encoding='utf-8').read()
from pyecharts.charts import WordCloud
words = [
("hey", 230),
("jude", 124),
("dont", 436),
("make", 255),
("it", 247),
("bad", 244),
("Take", 138),
("a sad song", 184),
("and", 12),
("make", 165),
("it", 247),
("better", 182),
("remember", 255),
("to", 150),
("let", 162),
("her", 266),
("into", 60),
("your", 82),
("heart", 173),
("then", 365),
("you", 360),
("can", 282),
("start", 273),
("make", 265),]
wc = (
WordCloud()
.add("", words))
wc.render_notebook()
用pyechart做词云图例子: