資料分析
import pandas as pd1
data = pd.read_excel(r"bingbing.xlsx")data.head()12
使用者性別等級評論點贊0食貧道男6[呆][呆][呆]你來了嘿!1584571畢導THU男6我是冰冰僅有的3個關注之一[tv_doge]我和冰冰貼貼1484392老師好我叫何同學男6[熱詞系列_知識增加]896343央視網快看保密6冰冰來了!我們要失業了嗎[doge][doge]1183704廈門大學保密5哇歡迎冰冰!!!66196
資料預處理資料描述data.describe()1
等級點贊count1180.0000001180.000000mean4.4813562200.617797std1.04137910872.524850min2.0000001.00000025%4.0000004.00000050%5.0000009.00000075%5.000000203.750000max6.000000158457.000000
刪除空值data.dropna()1
使用者性別等級評論點贊0食貧道男6[呆][呆][呆]你來了嘿!1584571畢導THU男6我是冰冰僅有的3個關注之一[tv_doge]我和冰冰貼貼1484392老師好我叫何同學男6[熱詞系列_知識增加]896343央視網快看保密6冰冰來了!我們要失業了嗎[doge][doge]1183704廈門大學保密5哇歡迎冰冰!!!66196..................1175黑旗魚保密511小時一百萬,好快[驚訝]51176是你的益達哦男6冰冰粉絲上漲速度:11小時107.3萬,平均每小時上漲9.75萬,每分鐘上漲1625,每秒鐘...51177快樂風男崔斯特男4軍訓的時候去了趟廁所,出來忘記是哪個隊伍了。看了up的影片才想起來,是三連[doge][滑稽]51178很認真的大熊男5我覺得冰冰主持春晚應該問題不大吧。[OK]51179飛拖鞋呀吼保密5《論一個2級號如何在2020年最後一天成為百大up主》5
1180 rows × 5 columns
刪除空值data.drop_duplicates()1
使用者性別等級評論點贊0食貧道男6[呆][呆][呆]你來了嘿!1584571畢導THU男6我是冰冰僅有的3個關注之一[tv_doge]我和冰冰貼貼1484392老師好我叫何同學男6[熱詞系列_知識增加]896343央視網快看保密6冰冰來了!我們要失業了嗎[doge][doge]1183704廈門大學保密5哇歡迎冰冰!!!66196..................1175黑旗魚保密511小時一百萬,好快[驚訝]51176是你的益達哦男6冰冰粉絲上漲速度:11小時107.3萬,平均每小時上漲9.75萬,每分鐘上漲1625,每秒鐘...51177快樂風男崔斯特男4軍訓的時候去了趟廁所,出來忘記是哪個隊伍了。看了up的影片才想起來,是三連[doge][滑稽]51178很認真的大熊男5我覺得冰冰主持春晚應該問題不大吧。[OK]51179飛拖鞋呀吼保密5《論一個2級號如何在2020年最後一天成為百大up主》5
1179 rows × 5 columns
視覺化點贊TOP20df1 = data.sort_values(by="點贊",ascending=False).head(20)1
from pyecharts import options as optsfrom pyecharts.charts import Barfrom pyecharts.faker import Fakerc1 = ( Bar() .add_xaxis(df1["評論"].to_list()) .add_yaxis("點贊數", df1["點贊"].to_list(), color=Faker.rand_color()) .set_global_opts( title_opts=opts.TitleOpts(title="評論熱度Top20"), datazoom_opts=[opts.DataZoomOpts(), opts.DataZoomOpts(type_="inside")], ) .render_notebook())c1123456789101112131415
等級分佈data.等級.value_counts().sort_index(ascending=False)1
6 1655 5024 3123 1382 63Name: 等級, dtype: int64123456
from pyecharts import options as optsfrom pyecharts.charts import Piefrom pyecharts.faker import Fakerc2 = ( Pie() .add( "", [list(z) for z in zip([str(i) for i in range(2,7)], [63,138,312,502,165])], radius=["40%", "75%"], ) .set_global_opts( title_opts=opts.TitleOpts(title="等級分佈"), legend_opts=opts.LegendOpts(orient="vertical", pos_top="15%", pos_left="2%"), ) .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}")) .render_notebook())c212345678910111213141516171819
性別分佈data.性別.value_counts().sort_index(ascending=False)1
from pyecharts import options as optsfrom pyecharts.charts import Piefrom pyecharts.faker import Fakerc4 = ( Pie() .add( "", [list(z) for z in zip(["男","女","保密"], ["404",'103','673'])], radius=["40%", "75%"], ) .set_global_opts( title_opts=opts.TitleOpts(title="性別分佈"), legend_opts=opts.LegendOpts(orient="vertical", pos_top="15%", pos_left="2%"), ) .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}")) .render_notebook() )c41234567891011121314151617181920
繪製詞雲圖from wordcloud import WordCloudimport jiebafrom tkinter import _flattenfrom matplotlib.pyplot import imreadfrom PIL import Image, ImageDraw, ImageFontimport matplotlib.pyplot as plt123456
with open('stoplist.txt', 'r', encoding='utf-8') as f: stopWords = f.read()with open('停用詞.txt','r',encoding='utf-8') as t: stopWord = t.read()total = stopWord.split() + stopWords.split()12345
def my_word_cloud(data=None, stopWords=None, img=None): dataCut = data.apply(jieba.lcut) # 分詞 dataAfter = dataCut.apply(lambda x: [i for i in x if i not in stopWords]) # 去除停用詞 wordFre = pd.Series(_flatten(list(dataAfter))).value_counts() # 統計詞頻 mask = plt.imread(img) plt.figure(figsize=(20,20)) wc = WordCloud(scale=10,font_path='C:/Windows/Fonts/STXINGKA.TTF',mask=mask,background_color="white",) wc.fit_words(wordFre) plt.imshow(wc) plt.axis('off')12345678910
my_word_cloud(data=data["評論"],stopWords=stopWords,img="1.jpeg")1
資料收集
透過之前部落格的學習,想必大家已經對Python網路爬蟲有了瞭解,希望大家動手實踐,這裡就不放程式碼啦,建議參考:
推薦閱讀:
使用xpath爬取資料jupyter notebook使用BeautifulSoup爬取豆瓣電影Top250一篇文章帶你掌握requests模組Python網路爬蟲基礎–BeautifulSoup到這裡就結束了,如果對你有幫助你,歡迎點贊關注,你的點贊對我很重要