成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

用數據分析網絡暴力有多可怕

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

這應該是一篇拖得蠻久的文章。

用數據分析網絡暴力有多可怕

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

***搞得兩邊都多多少少受到網絡暴力的影響。

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

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

還有比如自己一直關注的英雄聯盟。

上周王校長也是被帶了一波節奏,源于姿態退役后又復出的一條微博。

用數據分析網絡暴力有多可怕

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

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

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

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

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

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

一、前期工作

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

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

用數據分析網絡暴力有多可怕

主要是獲取用戶的昵稱、性別、地區、微博數、關注數、粉絲數。

另外本次的數據存儲采用MySQL數據庫。

創建數據庫。

  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() 

創建表格以及設置字段信息。

  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() 

二、數據獲取

具體代碼如下。

  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:你的參數 
  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. # 將請求頭字符串轉化為字典 
  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.         # 請求網址 
  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.         # 點贊數 
  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.             # 寫入數據庫中 
  93.             to_mysql(data) 
  94.  
  95.  
  96. if __name__ == '__main__'
  97.     get_message() 

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

用數據分析網絡暴力有多可怕

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

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

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

三、數據清洗

清洗代碼如下。

  1. import pandas as pd 
  2. import pymysql 
  3.  
  4. # 設置列名與數據對齊 
  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. # 設置顯示寬度為500,這樣就不會在IDE中換行了 
  12. pd.set_option('display.width', 2000) 
  13.  
  14. # 讀取數據 
  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. # 清洗數據 
  21. df = db['user_message'].str.split(' ', expand=True
  22. # 用戶名 
  23. df['name'] = df[0] 
  24. # 性別及地區 
  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. # 點贊數 
  33. df['praise'] = db['praise'].str.extract('(\d+)').astype("int"
  34. # 微博數,關注數,粉絲數 
  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行數據 
  49. print(df.sample(10)) 

輸出數據。

用數據分析網絡暴力有多可怕

隨機輸出十條,就大致能看出評論區是什么畫風了。

四、數據可視化

01 評論用戶性別情況

 

用數據分析網絡暴力有多可怕

 

用數據分析網絡暴力有多可怕

 

通過用戶ID對數據去重后,剩下約10萬+用戶。

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

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

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

提到了很多蔡徐坤的粉絲喜歡用帶有「坤、蔡、葵、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.     # 包含關鍵字用戶 
  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("微博評論用戶的性別情況(昵稱包含關鍵字)", 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("微博評論用戶的性別情況(昵稱包含關鍵字).html"

02 評論用戶區域分布

用數據分析網絡暴力有多可怕

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

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

更加能說明這幾個地方的網民不少。

可視化代碼如下。

  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("微博評論用戶的地區分布圖", 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('微博評論用戶的地區分布圖.html'

03 評論用戶關注數分布

用數據分析網絡暴力有多可怕

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

可視化代碼如下。

  1. def create_follows(df): 
  2.     ""
  3.     生成評論用戶關注數情況 
  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("評論用戶關注數分布情況", 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("評論用戶關注數分布情況.html"

04 評論用戶粉絲數分布

用數據分析網絡暴力有多可怕

這里發現粉絲數為「0-10」的用戶不少,估摸著應該是水軍在作怪了。

粉絲數為「50-100」的用戶最多。

可視化代碼如下。

  1. def create_follows(df): 
  2.     ""
  3.     生成評論用戶關注數情況 
  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("評論用戶關注數分布情況", 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("評論用戶關注數分布情況.html"

05 評論時間分布

用數據分析網絡暴力有多可怕

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

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

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

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

可視化代碼如下。

  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 評論詞云

用數據分析網絡暴力有多可怕

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

可視化代碼如下。

  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('生成詞云成功!'

五、總結

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

用數據分析網絡暴力有多可怕

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

評論畫風有點迷,是來攪局的嗎?

用數據分析網絡暴力有多可怕

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

大部分內容都是圍繞黑粉去說的。

用數據分析網絡暴力有多可怕

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

瘋狂與評論區互動...

用數據分析網絡暴力有多可怕

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

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

觀察了評論數最多的10名用戶,發現其中男性用戶的評論都是偏負面的,女性評論都是正面的。

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

責任編輯:未麗燕 來源: 法納斯特
相關推薦

2023-04-17 07:34:17

電商平臺ChatGPT表格

2020-05-15 15:09:51

R語言數據分析

2017-08-03 15:20:19

大數據數據分析

2019-01-15 08:50:41

泄露人臉數據

2020-07-16 11:49:49

流量焦慮移動互聯網

2017-05-02 17:22:05

數據

2016-05-04 16:20:55

多源數據大數據

2015-08-19 13:50:19

數據分析

2016-05-03 14:46:54

數據源數據分析數據融合

2024-03-10 21:00:33

2023-04-06 11:54:55

2020-09-08 12:48:19

數據分析圖表互聯網

2021-01-27 09:18:50

大數據數據收集大數據分析

2015-08-25 10:32:07

健康大數據

2019-08-05 15:07:04

2020-05-15 15:51:04

SAS數據分析

2021-01-26 11:57:46

數據挖掘數據分析大數據

2013-01-21 10:55:52

大數據Ayasdi拓撲數據

2016-12-22 10:44:30

數據分析找對象大數據

2012-08-08 09:53:23

HadoopMapReduce
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 亚洲一区二区三区在线视频 | 久久国产视频一区 | 国产一级片 | 日韩在线| 久久这里只有精品首页 | 91资源在线| 波多野结衣一区二区 | 亚洲精品一区在线观看 | 久久久久国产一区二区三区四区 | 日韩精品视频在线免费观看 | 日韩在线观看网站 | 国产日韩精品一区 | 国产精品久久久久久久久动漫 | 日韩二区| 精品91久久 | 久久精品国产99国产精品 | 中文字幕在线精品 | 色一级 | 断背山在线观看 | 一级特黄a大片 | 亚洲综合一区二区三区 | 中文在线一区 | 日韩欧美中文字幕在线观看 | 欧美一区二区三区,视频 | 91精品国产综合久久精品 | 久久久久亚洲 | 一级黄色片一级黄色片 | 91在线观看视频 | 国产免费av在线 | 中文字幕亚洲一区 | 免费视频成人国产精品网站 | 国产一二三区免费视频 | 国产精品777一区二区 | 日韩二三区 | 精品自拍视频在线观看 | 视频1区2区 | 久久精品一区二区三区四区 | 国产综合久久久久久鬼色 | 男人天堂av网站 | 日本粉嫩一区二区三区视频 | 亚洲激精日韩激精欧美精品 |