python六角星绘制_一小时销量破百万,Python告诉你周杰伦的《Mojito》到底有多火!...
【導(dǎo)語】:今天我們來聊聊周杰倫的新歌《Mojito》,Python技術(shù)部分請看第三部分,Show me data,用數(shù)據(jù)說話
6月12日0:00,周杰倫的最新單曲《Mojito》正式上線。對周杰倫歌迷來說,這一天簡直就是過年了。因為距離周杰倫上一次發(fā)歌,已經(jīng)過去了半年時間;而他的上一張專輯《周杰倫的床邊故事》,已經(jīng)是4年前的事情了。
這首以一種傳統(tǒng)的古巴雞尾酒命名的《Mojito》,前奏就充滿濃濃的古巴風(fēng)情和拉丁節(jié)奏,整首歌都寫出在遇見愛情時令人神往的浪漫情調(diào)。尤其是令人驚艷的rap部分,不僅讓人感嘆我的青春回來了!
《Mojito》一經(jīng)上線也是火爆全網(wǎng),300多萬人提前預(yù)約,一小時內(nèi)銷量破100萬,這也直接導(dǎo)致 QQ 音樂崩潰。
今天我們就用數(shù)據(jù)來全方位解讀一下,周杰倫的新歌《Mojito》。
1、豆瓣數(shù)據(jù)
首先我們分析整理了《Mojito》的豆瓣音樂數(shù)據(jù),目前這首歌在豆瓣共有2萬3千余人進行評價,分?jǐn)?shù)為6.9分。
數(shù)據(jù)來源:豆瓣音樂短評
https://music.douban.com/subject/35093585/comments/
數(shù)據(jù)量:498條
雖然比起周董早年音樂的分?jǐn)?shù)有一定差距,但是對比起近兩年發(fā)布的《我是如此相信》《說好不哭》在豆瓣的6.3分和5.9分,這首mojito還是不錯的。
再具體看到評分?jǐn)?shù)據(jù)可以發(fā)現(xiàn),給出3星的人最多,占比39.02%。其次是4星,21.84%。給出5星的占比16.49%。
我們進一步把給出1-2分的歸類為負(fù)向評分,把4-5分的歸為正向評分。
分別對比負(fù)向的正向的詞云,我們可以看到:
在負(fù)向評價中,提到最多的就是"失望"、"難聽"、"編曲"。正向評價中,大多數(shù)人都表示"好聽"、"有夏天"的感覺、"喜歡"。有意思的是,無論正向負(fù)向評價都提到了充滿異域風(fēng)情的《Mojito》很容易讓人聯(lián)想到當(dāng)年周董的那首《迷迭香》。
2、微博數(shù)據(jù)
接下來我們分析了周杰倫中文網(wǎng)在微博發(fā)布的mojito mv的評論數(shù)據(jù)。
微博:周杰倫中文網(wǎng)JayCn發(fā)布的《Mojito》MV
https://weibo.com/1165631310/J6cxJ67HC?filter=hot&root_comment_id=0&type=comment
數(shù)據(jù)集大小(去重之后):
- 評論數(shù)據(jù):9976條
- 粉絲數(shù)據(jù):9107條
分析發(fā)現(xiàn),評論用戶性別方面,女生占了絕大多數(shù),占比78.82%。
而用戶年齡方面,也是妥妥的90后的天下,占比高達74.91%。
微博評論中大家都在說些什么呢?
可以看到大多數(shù)人都表示"好聽"、"喜歡"、"很有夏天"的感覺。讓人"單曲循環(huán)",特別"上頭"。同時經(jīng)典的周氏rap,也是整首歌的靈魂,一聽就太有那味兒了!
3、教你用Python爬取QQ音樂評論數(shù)據(jù)
最后我們看到qq音樂的數(shù)據(jù):
QQ音樂評論信息。
https://y.qq.com/n/yqq/album/0009C3rp3Kfwg0.html
數(shù)據(jù)量:20245
我們先看到結(jié)論
首先在實時評論走勢圖上可以看到,在歌發(fā)布的12日0時,評論人數(shù)最高,之后慢慢回落。
評論中也讓人感嘆"好聽"、"青春回來了"。讓歌迷們紛紛下單支持,畢竟上線一小時突破一百萬張,讓QQ 音樂軟件一度崩潰,周董的影響力還是不容小覷的。
下面我們看到具體的步驟
我們使用Python分別獲取了QQ音樂評論、豆瓣短評和微博相關(guān)的評論數(shù)據(jù),進行了數(shù)據(jù)分析。此處我們展示QQ音樂評論分析部分。按照業(yè)務(wù)分析流程進行:
01 數(shù)據(jù)獲取
首先打開QQ音樂,搜索Mojito。翻到評論區(qū)后,使用谷歌瀏覽器的檢查功能,切換到Network部分,點擊翻頁進行網(wǎng)絡(luò)抓包,很容易發(fā)現(xiàn)發(fā)現(xiàn)評論區(qū)的內(nèi)容是被封裝在json中的,如下圖所示:
切換到headers處,找到請求URL地址,我們對請求地址進行精簡和測試,得到評論數(shù)據(jù)請求的URL地址:
https://c.y.qq.com/base/fcgi-bin/fcg_global_comment_h5.fcg?biztype=2&topid=12924001&cmd=8pagenum=0&pagesize=25
其中參數(shù)pagenum代表頁數(shù),通過遍歷即可獲取所有數(shù)據(jù),代碼如下:
# 導(dǎo)入包 import pandas as pd import time import requests import json from fake_useragent import UserAgentdef get_qq_comment(page_num):# 存儲數(shù)據(jù)df_all = pd.DataFrame()for i in range(page_num):# 打印進度print('我正在獲取第{}頁的信息'.format(i))# 獲取URLurl = 'https://c.y.qq.com/base/fcgi-bin/fcg_global_comment_h5.fcg?biztype=2&topid=12924001&cmd=8pagenum={}&pagesize=25'.format(i)# 添加headersheaders = {'user-agent': UserAgent().random}# 發(fā)起請求try:r = requests.get(url, headers=headers)except Exception as e:print(e)continue# 解析網(wǎng)頁json_data = json.loads(r.text)# 獲取數(shù)據(jù)comment_list = json_data['comment']['commentlist']# 昵稱nick_name = [i.get('nick') for i in comment_list]# 評論內(nèi)容content = [i.get('rootcommentcontent') for i in comment_list]# 評論時間comment_time = [i.get('time') for i in comment_list]# 點贊數(shù)praise_num = [i.get('praisenum') for i in comment_list]# 存儲數(shù)據(jù)df = pd.DataFrame({'nick_name': nick_name,'content': content,'comment_time': comment_time,'praise_num': praise_num})# 追加數(shù)據(jù)df_all = df_all.append(df, ignore_index=True)# 休眠一秒time.sleep(1)return df_all# 運行函數(shù) df = get_qq_comment(page_num=912)通過上述程序,共獲取到截止6.13日22217條評論信息,數(shù)據(jù)集如下所示:
df.head()02 數(shù)據(jù)讀入和數(shù)據(jù)處理
讀入數(shù)據(jù)集,并對獲取的數(shù)據(jù)集進行清洗。
# 導(dǎo)入所需包 import jieba import stylecloud from pyecharts.charts import Pie, Bar, Map, Line, WordCloud, Page from pyecharts import options as opts from pyecharts.globals import SymbolType, WarningType WarningType.ShowWarning = False# 讀入數(shù)據(jù) df = pd.read_excel('../data/QQ音樂評論數(shù)據(jù)6.13.xlsx')# 查看重復(fù)值和空值 print(df.duplicated().sum()) print(df.isnull().sum()) # 轉(zhuǎn)換函數(shù) def transform_time(time_second):time_array = time.localtime(time_second)otherStyleTime = time.strftime('%Y-%m-%d %H:%M:%S', time_array) return otherStyleTime# 時間數(shù)據(jù)處理 df['comment_time'] = df['comment_time'].apply(lambda x: transform_time(x))# content初步處理 pattern = re.compile(r'[em](.*?)[/em]') df['content'] = df.content.str.replace(pattern, '') df.head()03 數(shù)據(jù)可視化分析
Mojito評論時間走勢圖
# 日期數(shù)量 comment_num = df.comment_time.str.split(':').str[0].value_counts().sort_index() comment_num[:5] 2020-06-12 00 12673 2020-06-12 01 1185 2020-06-12 02 364 2020-06-12 03 146 2020-06-12 04 80 Name: comment_time, dtype: int64# 產(chǎn)生數(shù)據(jù) x_line1 = [i.replace('2020-','') for i in comment_num.index.to_list()] y_line1 = comment_num.values.tolist()# 繪制面積圖 line1 = Line(init_opts=opts.InitOpts(width='1350px', height='750px')) line1.add_xaxis(x_line1) line1.add_yaxis('', y_line1,markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_='max', name='最大值'),opts.MarkPointItem(type_='min', name='最小值')])) line1.set_global_opts(title_opts=opts.TitleOpts('Mojito評論人數(shù)走勢圖'), xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate='30')),visualmap_opts=opts.VisualMapOpts(max_=12673)) line1.set_series_opts(label_opts=opts.LabelOpts(is_show=False), linestyle_opts=opts.LineStyleOpts(width=3)) line1.render()QQ音樂評論詞云圖
def get_cut_words(content_series):# 讀入停用詞表stop_words = [] with open(r"stop_words.txt", 'r', encoding='utf-8') as f:lines = f.readlines()for line in lines:stop_words.append(line.strip())# 添加關(guān)鍵詞my_words = ['周杰倫', '一首歌', '好好聽', '方文山', '30多歲'] for i in my_words:jieba.add_word(i) # 自定義停用詞my_stop_words = ['歌有', '真的', '這首', '一首', '一點', '反正', '一段', '一句', '首歌', '啊啊啊', '哈哈哈', '轉(zhuǎn)發(fā)', '微博', '那段', '他會'] stop_words.extend(my_stop_words) # 分詞word_num = jieba.lcut(content_series.str.cat(sep='。'), cut_all=False)# 條件篩選word_num_selected = [i for i in word_num if i not in stop_words and len(i)>=2]return word_num_selectedtext1 = get_cut_words(content_series=df.content) text1[:5] ['致敬', '久石', '人生', '旋轉(zhuǎn)', '木馬']# 繪制詞云圖 stylecloud.gen_stylecloud(text=' '.join(text1), max_words=1000,collocations=False,font_path=r'?C:WindowsFontsmsyh.ttc',icon_name='fas fa-music',size=624,output_name='./詞云圖/QQ音樂評論詞云圖.png')CDA數(shù)據(jù)分析師 出品
作者:Mika
數(shù)據(jù):真達
后期:澤龍
總結(jié)
以上是生活随笔為你收集整理的python六角星绘制_一小时销量破百万,Python告诉你周杰伦的《Mojito》到底有多火!...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 坦克300征服者有没有无人驾驶功能
- 下一篇: 牛客网获取输入rowinput_Pyth