開發運維專欄資源整理

情感分析代碼:

import codecsnimport renimport numpy as npnimport pymysqlnfrom snownlp import SnowNLPnimport matplotlib.pyplot as pltnfrom snownlp import sentimentnfrom snownlp.sentiment import Sentimentnncomment = []nwith open(./6.txt, mode=r, encoding=utf-8) as f:n rows = f.readlines()n for row in rows:n if row not in comment:n comment.append(row.strip(n))ndef snowanalysis(self):n sentimentslist = []n for li in self:n print(li)n s = SnowNLP(li)n print(s.sentiments)n sentimentslist.append(s.sentiments)n plt.hist(sentimentslist, bins=np.arange(0, 1, 0.01))n plt.show()nsnowanalysis(comment)n

生成詞雲代碼:

import picklenfrom os import pathnimport jiebanimport matplotlib.pyplot as pltnfrom wordcloud import WordCloud, STOPWORDS, ImageColorGeneratorndef make_worldcloud(file_path):n text_from_file_with_apath = open(file_path,r,encoding=UTF-8).read()n wordlist_after_jieba = jieba.cut(text_from_file_with_apath, cut_all=False)n wl_space_split = " ".join(wordlist_after_jieba)n print(wl_space_split)n backgroud_Image = plt.imread(./douban.jpg)n print(載入圖片成功!)n 設置詞雲樣式n stopwords = STOPWORDS.copy()n stopwords.add("哈哈")n stopwords.add("還是")#可以加多個屏蔽詞n wc = WordCloud(n width_=1024,n height=768,n background_color=white,# 設置背景顏色n mask=backgroud_Image,# 設置背景圖片n font_path=E:simsun.ttf, # 設置中文字體,若是有中文的話,這句代碼必須添加,不然會出現方框,不出現漢字n max_words=300, # 設置最大現實的字數n stopwords=stopwords,# 設置停用詞n max_font_size=400,# 設置字體最大值n random_state=50,# 設置有多少種隨機生成狀態,即有多少種配色方案n )n wc.generate_from_text(wl_space_split)#開始載入文本n img_colors = ImageColorGenerator(backgroud_Image)n wc.recolor(color_func=img_colors)#字體顏色為背景圖片的顏色n plt.imshow(wc)# 顯示詞雲圖n plt.axis(off)# 是否顯示x軸、y軸下標n plt.show()#顯示n # 獲得模塊所在的路徑的n d = path.dirname(__file__)n # os.path.join(): 將多個路徑組合後返回n wc.to_file(path.join(d, "h11.jpg"))n print(生成詞雲成功!)nnmake_worldcloud(./9.txt)n

推薦閱讀:

從 gitlab 事件中吸取的教訓
運維開發工程師的價值&前景?
大型 IT 公司如何防止運維偷窺和篡改資料庫?
運維如何入門?
系統工程師和系統運維是兩個不同的職位嗎?

TAG:运维 | DevOps | 数据分析 |