# Packages
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings('ignore')
text = open(r'/Users/desktop/OSI.txt',encoding='utf-8').read()
print(text)
# 从这开始就出现以下英文乱码,我只粘贴了一部分:
# {\rtf1\ansi\ansicpg1252\cocoartf1561\cocoasubrtf600
#{\fonttbl\f0\fnil\fcharset134 PingFangSC-Regular;\f1\fnil\fcharset0 Tahoma;}
#{\colortbl;\red255\green255\blue255;\red51\green51\blue51;\red191\green191\blue191;}
import jieba
Word_spilt_jieba = jieba.cut(text,cut_all = False)
word_space = ' '.join(Word_spilt_jieba)
from wordcloud import WordCloud
wc =WordCloud(
max_font_size=110,
max_words=100,
font_path='font_path = "/System/Library/Fonts/PingFang.ttc',
background_color="white",
width=800,
height=500,
random_state = 21).generate(str(text))
plt.figure(figsize=(10, 7))
plt.imshow(wc, interpolation="bilinear")
plt.axis('off')
plt.savefig("Wordcloud for comments.png", dpi = 300)
plt.show()
plt.axis("off")
plt.show()
原本是中文txt,但是读进Jupyter之后,生成了英文的Word Cloud??
想得到中文的Word Cloud 要怎么解决?非常感谢!!
在前面就报错, 说明是text变量的问题, 换种方式读取txt文件试试呢
txt里面的原来的内容,是utf8格式的吗》??