網易雲音樂歐美歌單數據分析
一、 選題背景
如今聽音樂成為我們日常生活中的一部分,聽音樂方式從磁帶→光盤、黑膠唱片→數字專輯。目前主流音樂平台有:網易雲音樂、QQ音樂、酷狗音樂、酷我音樂。網易雲音樂,是一款由網易開發的音樂產品,是網易杭州研究院的成果,依托專業音樂人、DJ、好友推薦及社交功能,在線音樂服務主打歌單、社交、大牌推薦和音樂指紋,以歌單、DJ節目、社交、地理位置為核心要素,主打發現和分享。本次作業選擇對網易雲音樂平台進行爬取並數據可視化分析。
二、主題式網絡爬蟲設計方案
1 .主題式爬蟲名稱
名稱:網易雲音樂歌單爬蟲系統
2. 主題式網絡爬蟲爬取內容與數據特征分析
爬取內容:歌單、播放數、收藏數、標簽、歌曲數
數據特征分析:網頁文本
3. 主題式網絡爬蟲設計方案概述
(一)思路
1.對網頁進行解析
2.將數據儲存
3.查看網頁結構
4.查看網頁爬取內容的位置
5.取出數據
6.遍歷數據
(二) 技術難點
1.異常處理
2.網頁內容讀取
3.數據遍歷
4.數據批量存儲
5.整體系統設計
三、主題頁面的結構特征分析
(1)主題頁面的結構特征與特征分析
()Htmls 頁面解析
第一個頁面只需要獲取歌單的url
url:'https://music.163.com/discover/playlist/?cat=歐美&order=hot&limit=35&offset=' + str(i)
第二個頁面需要獲取歌單名、播放數、收藏數、評論數、歌曲數。
查找節點:
通過F12定位元素、使用Beatifulsoup.select()獲取標簽定位
1 title = soup.select('h2')[0].get_text().replace(',', ',') 2 # 獲取標簽 3 tags = [ ] 4 tags_message = soup.select('.u-tag i') 5 text = '無' 6 # 獲取歌單收藏量 7 collection = soup.select('#content-operation i')[1].get_text().replace('(', '').replace(')', '') 8 # 歌單播放量 9 play = soup.select('.s-fc6')[0].get_text() 10 # 歌單內歌曲數 11 songs = soup.select('#playlist-track-count')[0].get_text() 12 # 歌單評論數 13 comments = soup.select('#cnt_comment_count')[0].get_text()
遍歷方法:
內容取出用for循環
四、網絡爬蟲程序設計
(一)數據爬取與采集
1 保存url: 2 url='https://music.163.com/discover/playlist/?cat=歐美&order=hot&limit=35&offset=' + str(i) 3 response = requests.get(url=url, headers=headers) 4 html = response.text 5 soup = BeautifulSoup(html, 'html.parser') 6 # 獲取包含歌單詳情頁網址的標簽 7 ids = soup.select('.dec a') 8 # 獲取包含歌單索引頁信息的標簽 9 lis = soup.select('#m-pl-container li') 10 print(len(lis)) 11 for j in range(len(lis)): 12 # 獲取歌單詳情頁地址 13 url = ids[j]['href'] 14 print(url) 15 # 將信息寫入CSV文件中 16 with open('playlist.csv', 'a+', encoding='utf-8-sig') as f: 17 f.write(url + '\n') 18 保存歌單內容: 19 for i in data['url']: 20 # time.sleep(2) 21 url = 'https://music.163.com' + str(i) 22 print(url) 23 response = requests.get(url=url, headers=headers) 24 html = response.text 25 soup = BeautifulSoup(html, 'html.parser') 26 # 獲取歌單標題 27 title = soup.select('h2')[0].get_text().replace(',', ',') 28 # 獲取標簽 29 tags = [] 30 tags_message = soup.select('.u-tag i') 31 for p in tags_message: 32 tags.append(p.get_text()) 33 # 對標簽進行格式化 34 if len(tags) > 1: 35 tag = '-'.join(tags) 36 else: 37 tag = tags[0] 38 # 獲取歌單介紹 39 text = '無' 40 # 獲取歌單收藏量 41 collection = soup.select('#content-operation i')[1].get_text().replace('(', '').replace(')', '') 42 # 歌單播放量 43 play = soup.select('.s-fc6')[0].get_text() 44 # 歌單內歌曲數 45 songs = soup.select('#playlist-track-count')[0].get_text() 46 # 歌單評論數 47 comments = soup.select('#cnt_comment_count')[0].get_text() 48 # 輸出歌單詳情頁信息 49 print(title, tag, text, collection, play, songs, comments) 50 # 將詳情頁信息寫入CSV文件中 51 with open('muslist_message.csv', 'a', encoding='utf-8-sig') as f: 52 f.write( 53 title + ',' + tag + ',' + text + ',' + collection + ',' + play + ',' + songs + ',' + comments + '\n')
爬蟲系統運行演示
(二)對數據進行清洗和處理
1.導入數據
1 import numpy as np 2 import pandas as pd 3 import matplotlib.pyplot as plt 4 muc = pd.read_csv(r'C:/Users/Bling/Desktop/muslist_message1.csv')
2.數據清洗
1 # 重復值處理 2 muc = muc.drop_duplicates('title') 3 # Nan處理 4 muc = muc.dropna(axis = 0) 5 #刪除無效行 6 muc = muc.drop(['text'], axis = 1) 7 #替換值 8 muc.replace('評論', '0',inplace = True) 9 muc.replace('收藏', '0',inplace = True)
3.文本分析
1 # 詞雲 2 import numpy as np 3 import wordcloud as wc 4 from PIL import Image 5 import matplotlib.pyplot as plt 6 7 bk = np.array(Image.open("wyymuc.jpg")) 8 mask = bk 9 # 定義尺寸 10 word_cloud = wc.WordCloud( 11 mask = mask, 12 background_color='mintcream', 13 font_path='msyhbd.ttc', 14 max_font_size=300, 15 random_state=50, 16 ) 17 text = muc["tag"] 18 text = " ".join(text) 19 word_cloud.generate(text) 20 plt.imshow(word_cloud) 21 plt.show()
1 標簽分析: 2 import squarify 3 import pandas as pd 4 import matplotlib.pyplot as plt 5 6 df = pd.read_csv(r'C:/Users/Bling/Desktop/muslist_message1.csv', header=None) 7 # 處理標簽信息 8 tags = [] 9 dom2 = [] 10 for i in df[1]: 11 c = i.split('-') 12 for j in c: 13 if j not in tags: 14 tags.append(j) 15 else: 16 continue 17 for item in tags: 18 num = 0 19 for i in df[1]: 20 type2 = i.split('-') 21 for j in range(len(type2)): 22 if type2[j] == item: 23 num += 1 24 else: 25 continue 26 dom2.append(num) 27 # 數據創建 28 data = {'tags': tags, 'num': dom2} 29 frame = pd.DataFrame(data) 30 df1 = frame.sort_values(by='num', ascending=False) 31 name = df1['tags'][:10] 32 income = df1['num'][:10] 33 # 繪圖details 34 colors = ['#FFB6C1', '#B0C4DE', '#FFFF00', '#FF4500', '#DCDCDC', '#009966', '#FF6600', '#FF0033', '#009999', '#333366'] 35 plot = squarify.plot(sizes=income, label=name, color=colors, alpha=1, value=income, edgecolor='white', linewidth=1.5) 36 # 設置圖片顯示屬性,字體及大小 37 plt.rcParams['font.sans-serif'] = ['Microsoft YaHei'] 38 plt.rcParams['font.size'] = 8 39 plt.rcParams['axes.unicode_minus'] = False 40 # 設置標簽大小為1 41 plt.rc('font', size=6) 42 # 設置標題大小 43 plot.set_title('網易雲音樂歐美歌單標簽圖', fontsize=13, fontweight='light') 44 # 除坐標軸 45 plt.axis('off') 46 # 除上邊框和右邊框刻度 47 plt.tick_params(top=False, right=False) 48 # 圖形展示 49 plt.show()
4.數據分析與可視化
柱狀圖
1 # 設置圖片顯示屬性,字體及大小 2 plt.rcParams['font.sans-serif'] = ['STXihei'] 3 plt.rcParams['font.size'] = 12 4 plt.rcParams['axes.unicode_minus'] = False 5 # 設置圖片顯示屬性 6 fig = plt.figure(figsize=(16, 8), dpi=80) 7 ax = plt.subplot(1, 1, 1) 8 ax.patch.set_color('white') 9 # 設置坐標軸屬性 10 lines = plt.gca() 11 plt.ylabel("播放/萬")#縱坐標名字 12 plt.xticks([]) 13 # 繪制直方圖,設置直方圖顏色 14 ax.hist(muc['play'], bins=30, alpha=0.7, color='plum') 15 ax.set_title('歐美歌單播放數量分布情況', fontsize=20) 16 # 顯示圖片 17 plt.show()
1 # 設置圖片顯示屬性,字體及大小 2 plt.rcParams['font.sans-serif'] = ['STXihei'] 3 plt.rcParams['font.size'] = 12 4 plt.rcParams['axes.unicode_minus'] = False 5 # 設置圖片顯示屬性 6 fig = plt.figure(figsize=(16, 8), dpi=80) 7 ax = plt.subplot(1, 1, 1) 8 ax.patch.set_color('white') 9 # 設置坐標軸屬性 10 lines = plt.gca() 11 plt.ylabel("播放量/萬")#縱坐標名字 12 plt.xticks([]) 13 # 繪制直方圖,設置直方圖顏色 14 ax.hist(muc['comments'], bins=30, alpha=0.7, color='wheat') 15 ax.set_title('歐美歌單評論數分布情況', fontsize=20) 16 # 顯示圖片 17 plt.show()
1 # 設置圖片顯示屬性,字體及大小 2 plt.rcParams['font.sans-serif'] = ['STXihei'] 3 plt.rcParams['font.size'] = 12 4 plt.rcParams['axes.unicode_minus'] = False 5 # 設置圖片顯示屬性 6 fig = plt.figure(figsize=(16, 8), dpi=80) 7 ax = plt.subplot(1, 1, 1) 8 ax.patch.set_color('white') 9 # 設置坐標軸屬性 10 lines = plt.gca() 11 plt.ylabel("播放量/萬")#縱坐標名字 12 plt.xticks([]) 13 # 繪制直方圖,設置直方圖顏色 14 ax.hist(muc['collection'], bins=30, alpha=0.7, color='m') 15 ax.set_title('歐美歌單收藏數分布情況', fontsize=20) 16 # 顯示圖片 17 plt.show()
水平圖
1 # 水平圖 2 plt.rcParams['font.sans-serif'] = ['STXihei'] 3 fig = plt.figure(figsize=(16, 8), dpi=80) 4 ax = plt.subplot(1, 1, 1) 5 ax.patch.set_color('white') 6 x=muc['collection'].head(20) 7 y=muc['title'].head(20) 8 plt.barh(y,x, alpha=0.2,color='tan',label="熱度", lw=3) 9 plt.xticks(rotation=90) 10 plt.title("網易雲歐美歌單趨勢",fontsize=18,) 11 plt.legend(loc = "best")#圖例 12 plt.show()
1 # 降序排列 2 muc.sort_values(by='collection', inplace=True,ascending=False) 3 muc 4 # 水平圖 5 plt.rcParams['font.sans-serif'] = ['STXihei'] 6 fig = plt.figure(figsize=(16, 8), dpi=80) 7 ax = plt.subplot(1, 1, 1) 8 ax.patch.set_color('white') 9 x=muc['collection'].head(10) 10 y=muc['title'].head(10) 11 plt.barh(y,x, alpha=0.2,color='pink',label="熱度", lw=3) 12 plt.xticks(rotation=90) 13 plt.title("網易雲歐美歌單最受歡迎Top10",fontsize=18) 14 plt.legend(loc = "best")#圖例 15 plt.show()
散點圖
1 #散點圖 2 x=muc['collection'] 3 y=muc['play'] 4 fig = plt.figure(figsize=(18,7)) 5 plt.scatter(x,y,color='lightgreen',marker='o',s=40,alpha=0.5) 6 plt.xticks(rotation=90) 7 plt.title("網易雲歌單散點圖")
盒圖
1 #盒圖 2 plt.boxplot(y) 3 plt.title("網易雲歌單盒圖") 4 plt.show()
5.線性回歸方程
散點圖
1 #散點圖 2 import seaborn as sns 3 import matplotlib.pyplot as plt 4 import pandas as pd 5 import numpy as np 6 import warnings 7 warnings.filterwarnings("ignore") 8 four=pd.DataFrame(pd.read_csv('C:/Users/Bling/Desktop/muslist_message1.csv')) 9 sns.regplot(x='play',y='songs',data=four,color='r')
構建線性回歸模型
1 #構建線性回歸模型 2 from sklearn import datasets 3 from sklearn.linear_model import LinearRegression 4 import pandas as pd 5 import numpy as np 6 import seaborn as sns 7 predict_model = LinearRegression() 8 three=pd.DataFrame(pd.read_csv('C:/Users/Bling/Desktop/muslist_message1.csv')) 9 X = three['play'].values 10 X = X.reshape(-1,1) 11 predict_model.fit(X , three['songs']) 12 np.set_printoptions(precision = 3, suppress = True) 13 a = predict_model.coef_ 14 b = predict_model.intercept_ 15 print("回歸方程系數{}".format(predict_model.coef_)) 16 print("回歸方程截距{0:2f}".format(predict_model.intercept_)) 17 print("線性回歸預測模型表達式為{}*x+{}".format(predict_model.coef_,predict_model.intercept_))
6.數據持久化
7.代碼匯總
1 4.5.1 爬蟲系統 2 from bs4 import BeautifulSoup 3 import requests 4 import time 5 import pandas as pd 6 7 8 def playlist (): 9 headers = { 10 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36' 11 } 12 count = 1 13 for i in range(0, 1330, 35): 14 print("正在爬取第{}頁.".format(count)) 15 time.sleep(2) 16 url = 'https://music.163.com/discover/playlist/?cat=歐美&order=hot&limit=35&offset=' + str(i) 17 response = requests.get(url=url, headers=headers) 18 html = response.text 19 soup = BeautifulSoup(html, 'html.parser') 20 # 獲取包含歌單詳情頁網址的標簽 21 ids = soup.select('.dec a') 22 # 獲取包含歌單索引頁信息的標簽 23 lis = soup.select('#m-pl-container li') 24 print(len(lis)) 25 for j in range(len(lis)): 26 # 獲取歌單詳情頁地址 27 url = ids[j]['href'] 28 print(url) 29 # 將信息寫入CSV文件中 30 with open('playlist.csv', 'a+', encoding='utf-8-sig') as f: 31 f.write(url + '\n') 32 count += 1 33 34 35 36 def singlist(): 37 file = open("muslist_message.csv", "a",encoding='utf-8-sig') 38 file.write("title" + "," + "tag" + "," + "text" + "," + "collection" + "," + "play" + "," + "songs" + "," + "comments" + "," + '\n') 39 file = file.close() 40 data = pd.read_csv('playlist.csv', header=None, error_bad_lines=False, names=['url']) 41 42 headers = { 43 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36' 44 } 45 for i in data['url']: 46 # time.sleep(2) 47 url = 'https://music.163.com' + str(i) 48 print(url) 49 response = requests.get(url=url, headers=headers) 50 html = response.text 51 soup = BeautifulSoup(html, 'html.parser') 52 # 獲取歌單標題 53 title = soup.select('h2')[0].get_text().replace(',', ',') 54 # 獲取標簽 55 tags = [] 56 tags_message = soup.select('.u-tag i') 57 for p in tags_message: 58 tags.append(p.get_text()) 59 # 對標簽進行格式化 60 if len(tags) > 1: 61 tag = '-'.join(tags) 62 else: 63 tag = tags[0] 64 # 獲取歌單介紹 65 text = '無' 66 # 獲取歌單收藏量 67 collection = soup.select('#content-operation i')[1].get_text().replace('(', '').replace(')', '') 68 # 歌單播放量 69 play = soup.select('.s-fc6')[0].get_text() 70 # 歌單內歌曲數 71 songs = soup.select('#playlist-track-count')[0].get_text() 72 # 歌單評論數 73 comments = soup.select('#cnt_comment_count')[0].get_text() 74 # 輸出歌單詳情頁信息 75 print(title, tag, text, collection, play, songs, comments) 76 # 將詳情頁信息寫入CSV文件中 77 with open('muslist_message.csv', 'a', encoding='utf-8-sig') as f: 78 f.write( 79 title + ',' + tag + ',' + text + ',' + collection + ',' + play + ',' + songs + ',' + comments + '\n') 80 81 if __name__ == '__main__': 82 # playlist() 83 singlist() 84 85 86 4.5.2 數據分析 87 import numpy as np 88 import pandas as pd 89 import matplotlib.pyplot as plt 90 muc = pd.read_csv(r'C:/Users/Bling/Desktop/muslist_message1.csv') 91 muc 92 # 重復值處理 93 muc = muc.drop_duplicates('title') 94 # Nan處理 95 muc = muc.dropna(axis = 0) 96 #刪除無效行 97 muc = muc.drop(['text'], axis = 1) 98 #替換值 99 muc.replace('評論', '0',inplace = True) 100 muc.replace('收藏', '0',inplace = True) 101 # 降序排列 102 muc.sort_values(by=["play"],inplace=True,ascending=[False]) 103 muc 104 # 設置圖片顯示屬性,字體及大小 105 plt.rcParams['font.sans-serif'] = ['STXihei'] 106 plt.rcParams['font.size'] = 12 107 plt.rcParams['axes.unicode_minus'] = False 108 # 設置圖片顯示屬性 109 fig = plt.figure(figsize=(16, 8), dpi=80) 110 ax = plt.subplot(1, 1, 1) 111 ax.patch.set_color('white') 112 # 設置坐標軸屬性 113 lines = plt.gca() 114 plt.ylabel("播放/萬")#縱坐標名字 115 plt.xticks([]) 116 # 繪制直方圖,設置直方圖顏色 117 ax.hist(muc['play'], bins=30, alpha=0.7, color='plum') 118 ax.set_title('歐美歌單播放數量分布情況', fontsize=20) 119 # 顯示圖片 120 plt.show() 121 # 對播放數取對數 122 # 設置圖片顯示屬性,字體及大小 123 plt.rcParams['font.sans-serif'] = ['STXihei'] 124 plt.rcParams['font.size'] = 12 125 plt.rcParams['axes.unicode_minus'] = False 126 # 設置圖片顯示屬性 127 fig = plt.figure(figsize=(16, 8), dpi=80) 128 ax = plt.subplot(1, 1, 1) 129 ax.patch.set_color('white') 130 # 設置坐標軸屬性 131 lines = plt.gca() 132 plt.ylabel("播放量/萬")#縱坐標名字 133 plt.xticks([]) 134 # 繪制直方圖,設置直方圖顏色 135 ax.hist(muc['comments'], bins=30, alpha=0.7, color='wheat') 136 ax.set_title('歐美歌單評論數分布情況', fontsize=20) 137 # 顯示圖片 138 plt.show() 139 # 設置圖片顯示屬性,字體及大小 140 plt.rcParams['font.sans-serif'] = ['STXihei'] 141 plt.rcParams['font.size'] = 12 142 plt.rcParams['axes.unicode_minus'] = False 143 # 設置圖片顯示屬性 144 fig = plt.figure(figsize=(16, 8), dpi=80) 145 ax = plt.subplot(1, 1, 1) 146 ax.patch.set_color('white') 147 # 設置坐標軸屬性 148 lines = plt.gca() 149 plt.ylabel("播放量/萬")#縱坐標名字 150 plt.xticks([]) 151 # 繪制直方圖,設置直方圖顏色 152 ax.hist(muc['collection'], bins=30, alpha=0.7, color='m') 153 ax.set_title('歐美歌單收藏數分布情況', fontsize=20) 154 # 顯示圖片 155 plt.show() 156 # 水平圖 157 plt.rcParams['font.sans-serif'] = ['STXihei'] 158 fig = plt.figure(figsize=(16, 8), dpi=80) 159 ax = plt.subplot(1, 1, 1) 160 ax.patch.set_color('white') 161 x=muc['collection'].head(20) 162 y=muc['title'].head(20) 163 plt.barh(y,x, alpha=0.2,color='tan',label="熱度", lw=3) 164 plt.xticks(rotation=90) 165 plt.title("網易雲歐美歌單趨勢",fontsize=18,) 166 plt.legend(loc = "best")#圖例 167 plt.show() 168 # 降序排列 169 muc.sort_values(by='collection', inplace=True,ascending=False) 170 muc 171 # 水平圖 172 plt.rcParams['font.sans-serif'] = ['STXihei'] 173 fig = plt.figure(figsize=(16, 8), dpi=80) 174 ax = plt.subplot(1, 1, 1) 175 ax.patch.set_color('white') 176 x=muc['collection'].head(10) 177 y=muc['title'].head(10) 178 plt.barh(y,x, alpha=0.2,color='pink',label="熱度", lw=3) 179 plt.xticks(rotation=90) 180 plt.title("網易雲歐美歌單最受歡迎Top10",fontsize=18) 181 plt.legend(loc = "best")#圖例 182 plt.show() 183 #散點圖 184 x=muc['collection'] 185 y=muc['play'] 186 fig = plt.figure(figsize=(18,7)) 187 plt.scatter(x,y,color='lightgreen',marker='o',s=40,alpha=0.5) 188 plt.xticks(rotation=90) 189 plt.title("網易雲歌單散點圖") 190 #盒圖 191 plt.boxplot(y) 192 plt.title("網易雲歌單盒圖") 193 plt.show() 194 import squarify 195 import pandas as pd 196 import matplotlib.pyplot as plt 197 198 df = pd.read_csv(r'C:/Users/Bling/Desktop/muslist_message1.csv', header=None) 199 #線性回歸方程散點圖 200 import seaborn as sns 201 import matplotlib.pyplot as plt 202 import pandas as pd 203 import numpy as np 204 import warnings 205 warnings.filterwarnings("ignore") 206 four=pd.DataFrame(pd.read_csv('C:/Users/Bling/Desktop/muslist_message1.csv')) 207 sns.regplot(x='play',y='songs',data=four,color='r') 208 #建立線性回歸方程模型 209 from sklearn import datasets 210 from sklearn.linear_model import LinearRegression 211 import pandas as pd 212 import numpy as np 213 import seaborn as sns 214 predict_model = LinearRegression() 215 three=pd.DataFrame(pd.read_csv('C:/Users/Bling/Desktop/muslist_message1.csv')) 216 X = three['play'].values 217 X = X.reshape(-1,1) 218 predict_model.fit(X , three['songs']) 219 np.set_printoptions(precision = 3, suppress = True) 220 a = predict_model.coef_ 221 b = predict_model.intercept_ 222 print("回歸方程系數{}".format(predict_model.coef_)) 223 print("回歸方程截距{0:2f}".format(predict_model.intercept_)) 224 print("線性回歸預測模型表達式為{}*x+{}".format(predict_model.coef_,predict_model.intercept_)) 225 # 處理標簽信息 226 tags = [] 227 dom2 = [] 228 for i in df[1]: 229 c = i.split('-') 230 for j in c: 231 if j not in tags: 232 tags.append(j) 233 else: 234 continue 235 for item in tags: 236 num = 0 237 for i in df[1]: 238 type2 = i.split('-') 239 for j in range(len(type2)): 240 if type2[j] == item: 241 num += 1 242 else: 243 continue 244 dom2.append(num) 245 # 數據創建 246 data = {'tags': tags, 'num': dom2} 247 frame = pd.DataFrame(data) 248 df1 = frame.sort_values(by='num', ascending=False) 249 name = df1['tags'][:10] 250 income = df1['num'][:10] 251 # 繪圖details 252 colors = ['#FFB6C1', '#B0C4DE', '#FFFF00', '#FF4500', '#DCDCDC', '#009966', '#FF6600', '#FF0033', '#009999', '#333366'] 253 plot = squarify.plot(sizes=income, label=name, color=colors, alpha=1, value=income, edgecolor='white', linewidth=1.5) 254 # 設置圖片顯示屬性,字體及大小 255 plt.rcParams['font.sans-serif'] = ['Microsoft YaHei'] 256 plt.rcParams['font.size'] = 8 257 plt.rcParams['axes.unicode_minus'] = False 258 # 設置標簽大小為1 259 plt.rc('font', size=6) 260 # 設置標題大小 261 plot.set_title('網易雲音樂歐美歌單標簽圖', fontsize=13, fontweight='light') 262 # 除坐標軸 263 plt.axis('off') 264 # 除上邊框和右邊框刻度 265 plt.tick_params(top=False, right=False) 266 # 圖形展示 267 plt.show() 268 # 詞雲 269 import numpy as np 270 import wordcloud as wc 271 from PIL import Image 272 import matplotlib.pyplot as plt 273 274 bk = np.array(Image.open("wyymuc.jpg")) 275 mask = bk 276 # 定義尺寸 277 word_cloud = wc.WordCloud( 278 mask = mask, 279 background_color='mintcream', 280 font_path='msyhbd.ttc', 281 max_font_size=300, 282 random_state=50, 283 ) 284 text = muc["tag"] 285 text = " ".join(text) 286 word_cloud.generate(text) 287 plt.imshow(word_cloud) 288 plt.show()
五、總結
1.經過對主題數據的分析與可視化,可以得到哪些結論?是否達到預期的目標?
通過分析播放量、收藏量、評論量可以讓我們清楚的得知一個歌單的受歡迎程度,達到了預期的目標。
2.在完成此設計過程中,得到哪些收獲?以及要改進的建議?
在本次設計過程中,使我在數據處理方面有了很大的收獲,能夠達到自己的想要的效果。對數據分析有一定認知的同時,讓我對數據分析所要用到的程序語言更加熟悉。
需要改進的地方可能就是不能夠自主的編寫程序,需要借鑒網絡或者書本來編寫程序;編寫程序的效率不夠高,花費的時間比較長。