偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

用數(shù)據(jù)分析網(wǎng)絡(luò)暴力有多可怕

大數(shù)據(jù) 數(shù)據(jù)分析
故事源于潘長江在某個綜藝節(jié)目上沒認出蔡徐坤,然后潘長江老師的微博評論區(qū)就炸鍋了。最后搞得兩邊都多多少少受到網(wǎng)絡(luò)暴力的影響。直至今日,這條微博的評論區(qū)還在更新著。不得不說微博的黑粉,強行帶節(jié)奏,真的很可怕。

這應(yīng)該是一篇拖得蠻久的文章。

用數(shù)據(jù)分析網(wǎng)絡(luò)暴力有多可怕

故事源于潘長江在某個綜藝節(jié)目上沒認出蔡徐坤,然后潘長江老師的微博評論區(qū)就炸鍋了。

***搞得兩邊都多多少少受到網(wǎng)絡(luò)暴力的影響。

直至今日,這條微博的評論區(qū)還在更新著。

不得不說微博的黑粉,強行帶節(jié)奏,真的很可怕。

還有比如自己一直關(guān)注的英雄聯(lián)盟。

上周王校長也是被帶了一波節(jié)奏,源于姿態(tài)退役后又復(fù)出的一條微博。

用數(shù)據(jù)分析網(wǎng)絡(luò)暴力有多可怕

本來是一句很普通的調(diào)侃回復(fù),「離辣個傳奇adc的回歸,還遠嗎?[二哈]」。

然后就有人開始帶王校長的節(jié)奏,直接把王校長給惹毛了。

上面這些事情,對于我這個吃瓜群眾,也沒什么好說的。

只是希望以后能沒有那么多無聊的人去帶節(jié)奏,強行給他人帶來壓力。

本次通過獲取潘長江老師那條微博的評論用戶信息,來分析一波。

一共是獲取了3天的評論,共14萬條。

一、前期工作

微博評論信息獲取就不細說,之前也講過了。

這里提一下用戶信息獲取,同樣從移動端下手。

用數(shù)據(jù)分析網(wǎng)絡(luò)暴力有多可怕

主要是獲取用戶的昵稱、性別、地區(qū)、微博數(shù)、關(guān)注數(shù)、粉絲數(shù)。

另外本次的數(shù)據(jù)存儲采用MySQL數(shù)據(jù)庫。

創(chuàng)建數(shù)據(jù)庫。

  1. import pymysql 
  2.  
  3. db = pymysql.connect(host='127.0.0.1'user='root'password='774110919', port=3306) 
  4. cursor = db.cursor() 
  5. cursor.execute("CREATE DATABASE weibo DEFAULT CHARACTER SET utf8mb4"
  6. db.close() 

創(chuàng)建表格以及設(shè)置字段信息。

  1. import pymysql 
  2.  
  3. db = pymysql.connect(host='127.0.0.1'user='root'password='774110919', port=3306, db='weibo'
  4. cursor = db.cursor() 
  5. sql = 'CREATE TABLE IF NOT EXISTS comments (user_id VARCHAR(255) NOT NULL, user_message VARCHAR(255) NOT NULL, weibo_message VARCHAR(255) NOT NULL, comment VARCHAR(255) NOT NULL, praise VARCHAR(255) NOT NULL, date VARCHAR(255) NOT NULL, PRIMARY KEY (comment, date))' 
  6. cursor.execute(sql) 
  7. db.close() 

二、數(shù)據(jù)獲取

具體代碼如下。

  1. from copyheaders import headers_raw_to_dict 
  2. from bs4 import BeautifulSoup 
  3. import requests 
  4. import pymysql 
  5. import re 
  6.  
  7. headers = b""
  8. accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8 
  9. accept-encoding:gzip, deflate, br 
  10. accept-language:zh-CN,zh;q=0.9 
  11. cache-control:max-age=0 
  12. cookie:你的參數(shù) 
  13. upgrade-insecure-requests:1 
  14. user-agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36 
  15. ""
  16.  
  17. # 將請求頭字符串轉(zhuǎn)化為字典 
  18. headers = headers_raw_to_dict(headers) 
  19.  
  20.  
  21. def to_mysql(data): 
  22.     ""
  23.     信息寫入mysql 
  24.     ""
  25.     table = 'comments' 
  26.     keys = ', '.join(data.keys()) 
  27.     values = ', '.join(['%s'] * len(data)) 
  28.     db = pymysql.connect(host='localhost'user='root'password='774110919', port=3306, db='weibo'
  29.     cursor = db.cursor() 
  30.     sql = 'INSERT INTO {table}({keys}) VALUES ({values})'.format(table=table, keys=keys, values=values
  31.     try: 
  32.         if cursor.execute(sql, tuple(data.values())): 
  33.             print("Successful"
  34.             db.commit() 
  35.     except
  36.         print('Failed'
  37.         db.rollback() 
  38.     db.close() 
  39.  
  40.  
  41. def get_user(user_id): 
  42.     ""
  43.     獲取用戶信息 
  44.     ""
  45.     try: 
  46.         url_user = 'https://weibo.cn' + str(user_id) 
  47.         response_user = requests.get(url=url_user, headers=headers) 
  48.         soup_user = BeautifulSoup(response_user.text, 'html.parser'
  49.         # 用戶信息 
  50.         re_1 = soup_user.find_all(class_='ut'
  51.         user_message = re_1[0].find(class_='ctt').get_text() 
  52.         # 微博信息 
  53.         re_2 = soup_user.find_all(class_='tip2'
  54.         weibo_message = re_2[0].get_text() 
  55.         return (user_message, weibo_message) 
  56.     except
  57.         return ('未知''未知'
  58.  
  59.  
  60. def get_message(): 
  61.     # ***頁有熱門評論,拿取信息較麻煩,這里偷個懶~ 
  62.     for i in range(2, 20000): 
  63.         data = {} 
  64.         print('第------------' + str(i) + '------------頁'
  65.         # 請求網(wǎng)址 
  66.         url = 'https://weibo.cn/comment/Hl2O21Xw1?uid=1732460543&rl=0&page=' + str(i) 
  67.         response = requests.get(url=url, headers=headers) 
  68.         html = response.text 
  69.         soup = BeautifulSoup(html, 'html.parser'
  70.         # 評論信息 
  71.         comments = soup.find_all(class_='ctt'
  72.         # 點贊數(shù) 
  73.         praises = soup.find_all(class_='cc'
  74.         # 評論時間 
  75.         date = soup.find_all(class_='ct'
  76.         # 獲取用戶名 
  77.         name = re.findall('id="C_.*?href="/.*?">(.*?)</a>', html) 
  78.         # 獲取用戶ID 
  79.         user_ids = re.findall('id="C_.*?href="(.*?)">(.*?)</a>', html) 
  80.  
  81.         for j in range(len(name)): 
  82.             # 用戶ID 
  83.             user_id = user_ids[j][0] 
  84.             (user_message, weibo_message) = get_user(user_id) 
  85.             data['user_id'] = " ".join(user_id.split()) 
  86.             data['user_message'] = " ".join(user_message.split()) 
  87.             data['weibo_message'] = " ".join(weibo_message.split()) 
  88.             data['comment'] = " ".join(comments[j].get_text().split()) 
  89.             data['praise'] = " ".join(praises[j * 2].get_text().split()) 
  90.             data['date'] = " ".join(date[j].get_text().split()) 
  91.             print(data) 
  92.             # 寫入數(shù)據(jù)庫中 
  93.             to_mysql(data) 
  94.  
  95.  
  96. if __name__ == '__main__'
  97.     get_message() 

***成功獲取評論信息。

用數(shù)據(jù)分析網(wǎng)絡(luò)暴力有多可怕

3天14萬條評論,著實可怕。

有時我不禁在想,到底是誰天天會那么無聊去刷評論。

職業(yè)黑粉,職業(yè)水軍嗎?好像還真的有。

三、數(shù)據(jù)清洗

清洗代碼如下。

  1. import pandas as pd 
  2. import pymysql 
  3.  
  4. # 設(shè)置列名與數(shù)據(jù)對齊 
  5. pd.set_option('display.unicode.ambiguous_as_wide'True
  6. pd.set_option('display.unicode.east_asian_width'True
  7. # 顯示10列 
  8. pd.set_option('display.max_columns', 10) 
  9. # 顯示10行 
  10. pd.set_option('display.max_rows', 10) 
  11. # 設(shè)置顯示寬度為500,這樣就不會在IDE中換行了 
  12. pd.set_option('display.width', 2000) 
  13.  
  14. # 讀取數(shù)據(jù) 
  15. conn = pymysql.connect(host='localhost'user='root'password='774110919', port=3306, db='weibo', charset='utf8mb4'
  16. cursor = conn.cursor() 
  17. sql = "select * from comments" 
  18. db = pd.read_sql(sql, conn) 
  19.  
  20. # 清洗數(shù)據(jù) 
  21. df = db['user_message'].str.split(' ', expand=True
  22. # 用戶名 
  23. df['name'] = df[0] 
  24. # 性別及地區(qū) 
  25. df1 = df[1].str.split('/', expand=True
  26. df['gender'] = df1[0] 
  27. df['province'] = df1[1] 
  28. # 用戶ID 
  29. df['id'] = db['user_id'
  30. # 評論信息 
  31. df['comment'] = db['comment'
  32. # 點贊數(shù) 
  33. df['praise'] = db['praise'].str.extract('(\d+)').astype("int"
  34. # 微博數(shù),關(guān)注數(shù),粉絲數(shù) 
  35. df2 = db['weibo_message'].str.split(' ', expand=True
  36. df2 = df2[df2[0] != '未知'
  37. df['tweeting'] = df2[0].str.extract('(\d+)').astype("int"
  38. df['follows'] = df2[1].str.extract('(\d+)').astype("int"
  39. df['followers'] = df2[2].str.extract('(\d+)').astype("int"
  40. # 評論時間 
  41. df['time'] = db['date'].str.split(':', expand=True)[0] 
  42. df['time'] = pd.Series([i+'時' for i in df['time']]) 
  43. df['day'] = df['time'].str.split(' ', expand=True)[0] 
  44. # 去除無用信息 
  45. df = df.ix[:, 3:] 
  46. df = df[df['name'] != '未知'
  47. df = df[df['time'].str.contains("日")] 
  48. # 隨機輸出10行數(shù)據(jù) 
  49. print(df.sample(10)) 

輸出數(shù)據(jù)。

用數(shù)據(jù)分析網(wǎng)絡(luò)暴力有多可怕

隨機輸出十條,就大致能看出評論區(qū)是什么畫風(fēng)了。

四、數(shù)據(jù)可視化

01 評論用戶性別情況

 

用數(shù)據(jù)分析網(wǎng)絡(luò)暴力有多可怕

 

用數(shù)據(jù)分析網(wǎng)絡(luò)暴力有多可怕

 

通過用戶ID對數(shù)據(jù)去重后,剩下約10萬+用戶。

***張圖為所有用戶的性別情況,其中男性3萬+,女性7萬+。

這確實也符合蔡徐坤的粉絲群體。

第二張圖是因為之前看到「Alfred數(shù)據(jù)室」對于蔡徐坤粉絲群體的分析。

提到了很多蔡徐坤的粉絲喜歡用帶有「坤、蔡、葵、kun」的昵稱。

所以將昵稱包含這些字的用戶提取出來。

果不其然,女性1.2萬+,男性900+,更加符合了蔡徐坤的粉絲群體。

可視化代碼如下。

  1. from pyecharts import Pie, Map, Line 
  2.  
  3.  
  4. def create_gender(df): 
  5.     # 全部用戶 
  6.     # df = df.drop_duplicates('id'
  7.     # 包含關(guān)鍵字用戶 
  8.     df = df[df['name'].str.contains("坤|蔡|葵|kun")].drop_duplicates('id'
  9.     # 分組匯總 
  10.     gender_message = df.groupby(['gender']) 
  11.     gender_com = gender_message['gender'].agg(['count']) 
  12.     gender_com.reset_index(inplace=True
  13.  
  14.     # 生成餅圖 
  15.     attr = gender_com['gender'
  16.     v1 = gender_com['count'
  17.     # pie = Pie("微博評論用戶的性別情況", title_pos='center', title_top=0) 
  18.     # pie.add("", attr, v1, radius=[40, 75], label_text_color=None, is_label_show=True, legend_orient="vertical", legend_pos="left", legend_top="%10"
  19.     # pie.render("微博評論用戶的性別情況.html"
  20.     pie = Pie("微博評論用戶的性別情況(昵稱包含關(guān)鍵字)", title_pos='center', title_top=0) 
  21.     pie.add("", attr, v1, radius=[40, 75], label_text_color=None, is_label_show=True, legend_orient="vertical", legend_pos="left", legend_top="%10"
  22.     pie.render("微博評論用戶的性別情況(昵稱包含關(guān)鍵字).html"

02 評論用戶區(qū)域分布

用數(shù)據(jù)分析網(wǎng)絡(luò)暴力有多可怕

廣東以8000+的評論用戶居于首位,隨后則是北京、山東,江蘇,浙江,四川。

這里也與之前網(wǎng)易云音樂評論用戶的分布有點相似。

更加能說明這幾個地方的網(wǎng)民不少。

可視化代碼如下。

  1. def create_map(df): 
  2.     # 全部用戶 
  3.     df = df.drop_duplicates('id'
  4.     # 分組匯總 
  5.     loc_message = df.groupby(['province']) 
  6.     loc_com = loc_message['province'].agg(['count']) 
  7.     loc_com.reset_index(inplace=True
  8.  
  9.     # 繪制地圖 
  10.     value = [i for i in loc_com['count']] 
  11.     attr = [i for i in loc_com['province']] 
  12.     map = Map("微博評論用戶的地區(qū)分布圖", title_pos='center', title_top=0) 
  13.     map.add("", attr, value, maptype="china", is_visualmap=True, visual_text_color="#000", is_map_symbol_show=False, visual_range=[0, 7000]) 
  14.     map.render('微博評論用戶的地區(qū)分布圖.html'

03 評論用戶關(guān)注數(shù)分布

用數(shù)據(jù)分析網(wǎng)絡(luò)暴力有多可怕

整體上符合常態(tài),不過我也很好奇那些關(guān)注上千的用戶,是什么樣的一個存在。

可視化代碼如下。

  1. def create_follows(df): 
  2.     ""
  3.     生成評論用戶關(guān)注數(shù)情況 
  4.     ""
  5.     df = df.drop_duplicates('id'
  6.     follows = df['follows'
  7.     bins = [0, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000] 
  8.     level = ['0-10''10-20''20-50''50-100''100-200''200-500''500-1000''1000-2000''2000-5000''5000-10000''10000以上'
  9.     len_stage = pd.cut(follows, bins=bins, labels=level).value_counts().sort_index() 
  10.     # 生成柱狀圖 
  11.     attr = len_stage.index 
  12.     v1 = len_stage.values 
  13.     bar = Bar("評論用戶關(guān)注數(shù)分布情況", title_pos='center', title_top='18', width=800, height=400) 
  14.     bar.add("", attr, v1, is_stack=True, is_label_show=True, xaxis_interval=0, xaxis_rotate=30) 
  15.     bar.render("評論用戶關(guān)注數(shù)分布情況.html"

04 評論用戶粉絲數(shù)分布

用數(shù)據(jù)分析網(wǎng)絡(luò)暴力有多可怕

這里發(fā)現(xiàn)粉絲數(shù)為「0-10」的用戶不少,估摸著應(yīng)該是水軍在作怪了。

粉絲數(shù)為「50-100」的用戶最多。

可視化代碼如下。

  1. def create_follows(df): 
  2.     ""
  3.     生成評論用戶關(guān)注數(shù)情況 
  4.     ""
  5.     df = df.drop_duplicates('id'
  6.     follows = df['follows'
  7.     bins = [0, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000] 
  8.     level = ['0-10''10-20''20-50''50-100''100-200''200-500''500-1000''1000-2000''2000-5000''5000-10000''10000以上'
  9.     len_stage = pd.cut(follows, bins=bins, labels=level).value_counts().sort_index() 
  10.     # 生成柱狀圖 
  11.     attr = len_stage.index 
  12.     v1 = len_stage.values 
  13.     bar = Bar("評論用戶關(guān)注數(shù)分布情況", title_pos='center', title_top='18', width=800, height=400) 
  14.     bar.add("", attr, v1, is_stack=True, is_label_show=True, xaxis_interval=0, xaxis_rotate=30) 
  15.     bar.render("評論用戶關(guān)注數(shù)分布情況.html"

05 評論時間分布

用數(shù)據(jù)分析網(wǎng)絡(luò)暴力有多可怕

潘老師是在17時發(fā)出微博的,但是那時并沒有大量的評論出現(xiàn),那個小時一共有1237條評論。

直到蔡徐坤在18時評論后,微博的評論一下就上去了,24752條。

而且目前一半的評論都是在蔡徐坤的回復(fù)底下評論,點贊數(shù)多的也大多都在其中。

不得不說蔡徐坤的粉絲力量真大,可怕可怕~

可視化代碼如下。

  1. def creat_date(df): 
  2.     # 分組匯總 
  3.     date_message = df.groupby(['time']) 
  4.     date_com = date_message['time'].agg(['count']) 
  5.     date_com.reset_index(inplace=True
  6.  
  7.     # 繪制走勢圖 
  8.     attr = date_com['time'
  9.     v1 = date_com['count'
  10.     line = Line("微博評論的時間分布", title_pos='center', title_top='18', width=800, height=400) 
  11.     line.add("", attr, v1, is_smooth=True, is_fill=True, area_color="#000", xaxis_interval=24, is_xaxislabel_align=True, xaxis_min="dataMin", area_opacity=0.3, mark_point=["max"], mark_point_symbol="pin", mark_point_symbolsize=55) 
  12.     line.render("微博評論的時間分布.html"

06 評論詞云

用數(shù)據(jù)分析網(wǎng)絡(luò)暴力有多可怕

大體上言論還算好,沒有很偏激。

可視化代碼如下。

  1. from wordcloud import WordCloud, ImageColorGenerator 
  2. import matplotlib.pyplot as plt 
  3. import jieba 
  4.  
  5.  
  6. def create_wordcloud(df): 
  7.     ""
  8.     生成評論詞云 
  9.     ""
  10.     words = pd.read_csv('chineseStopWords.txt', encoding='gbk', sep='\t', names=['stopword']) 
  11.     # 分詞 
  12.     text = '' 
  13.     for line in df['comment']: 
  14.         line = line.split(':')[-1] 
  15.         text += ' '.join(jieba.cut(str(line), cut_all=False)) 
  16.     # 停用詞 
  17.     stopwords = set(''
  18.     stopwords.update(words['stopword']) 
  19.     backgroud_Image = plt.imread('article.jpg'
  20.     wc = WordCloud( 
  21.         background_color='white'
  22.         mask=backgroud_Image, 
  23.         font_path='C:\Windows\Fonts\華康儷金黑W8.TTF'
  24.         max_words=2000, 
  25.         max_font_size=150, 
  26.         min_font_size=15, 
  27.         prefer_horizontal=1, 
  28.         random_state=50, 
  29.         stopwords=stopwords 
  30.     ) 
  31.     wc.generate_from_text(text) 
  32.     img_colors = ImageColorGenerator(backgroud_Image) 
  33.     wc.recolor(color_func=img_colors) 
  34.     # 高詞頻詞語 
  35.     process_word = WordCloud.process_text(wc, text) 
  36.     sort = sorted(process_word.items(), key=lambda e: e[1], reverse=True
  37.     print(sort[:50]) 
  38.     plt.imshow(wc) 
  39.     plt.axis('off'
  40.     wc.to_file("微博評論詞云.jpg"
  41.     print('生成詞云成功!'

五、總結(jié)

***,照例來扒一扒哪位用戶評論最多。

用數(shù)據(jù)分析網(wǎng)絡(luò)暴力有多可怕

這位男性用戶,一共評論了90條,居于首位。

評論畫風(fēng)有點迷,是來攪局的嗎?

用數(shù)據(jù)分析網(wǎng)絡(luò)暴力有多可怕

這位女性用戶,一共評論了80條。

大部分內(nèi)容都是圍繞黑粉去說的。

用數(shù)據(jù)分析網(wǎng)絡(luò)暴力有多可怕

這位女性用戶,一共評論了71條。

瘋狂與評論區(qū)互動...

用數(shù)據(jù)分析網(wǎng)絡(luò)暴力有多可怕

這位男性用戶,一共評論了68條。

也在與評論區(qū)互動,不過大多數(shù)評論情感傾向都是偏消極的。

觀察了評論數(shù)最多的10名用戶,發(fā)現(xiàn)其中男性用戶的評論都是偏負面的,女性評論都是正面的。

好了,作為一名吃瓜群眾,我是看看就好,也就不發(fā)表什么言論了。

責(zé)任編輯:未麗燕 來源: 法納斯特
相關(guān)推薦

2023-04-17 07:34:17

電商平臺ChatGPT表格

2017-08-03 15:20:19

大數(shù)據(jù)數(shù)據(jù)分析

2020-05-15 15:09:51

R語言數(shù)據(jù)分析

2019-01-15 08:50:41

泄露人臉數(shù)據(jù)

2020-07-16 11:49:49

流量焦慮移動互聯(lián)網(wǎng)

2017-05-02 17:22:05

數(shù)據(jù)

2016-05-03 14:46:54

數(shù)據(jù)源數(shù)據(jù)分析數(shù)據(jù)融合

2016-05-04 16:20:55

多源數(shù)據(jù)大數(shù)據(jù)

2015-08-19 13:50:19

數(shù)據(jù)分析

2023-04-06 11:54:55

2024-03-10 21:00:33

2015-08-25 10:32:07

健康大數(shù)據(jù)

2019-08-05 15:07:04

2020-05-15 15:51:04

SAS數(shù)據(jù)分析

2021-01-27 09:18:50

大數(shù)據(jù)數(shù)據(jù)收集大數(shù)據(jù)分析

2020-09-08 12:48:19

數(shù)據(jù)分析圖表互聯(lián)網(wǎng)

2021-01-26 11:57:46

數(shù)據(jù)挖掘數(shù)據(jù)分析大數(shù)據(jù)

2013-01-21 10:55:52

大數(shù)據(jù)Ayasdi拓撲數(shù)據(jù)

2015-08-14 10:28:09

大數(shù)據(jù)

2022-08-03 14:30:52

大數(shù)據(jù)數(shù)據(jù)分析數(shù)據(jù)收集
點贊
收藏

51CTO技術(shù)棧公眾號