データ解析
パンダをpddata = pd.read_excel(r "bingbing.xlsx")としてインポートします data.head()
ユーザー |
性別 |
グレード |
コメント |
お気に入り |
---|
データの前処理
データの説明
data.describe()
グレード |
お気に入り |
---|
空の値を削除する
data.dropna()
ユーザー |
性別 |
グレード |
コメント |
お気に入り |
---|
1180行×5列
空の値を削除する
data.drop_duplicates()
ユーザー |
性別 |
グレード |
コメント |
お気に入り |
---|
1179行×5列
視覚化
TOP20のように
df1 = data.sort_values(by = "点赞"、ascending = False).head(20)from pyecharts import options as opts from pyecharts.charts import Bar from pyecharts.faker import Faker c1 =( 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() ) c1
グレード分布
。。データ等级.value_counts()sort_index(昇順= False)が6 165 5 502 4 312 3 138 2 63 名:等级、DTYPE:int64from pyechartsインポートオプションOPTSとして pyecharts.chartsからは、パイをインポート pyecharts.fakerインポート偽物から C2 = ( 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() ) c2
性別の分布
data.nicand.value_counts()。sort_index(ascending = False)from pyecharts import options as opts from pyecharts.charts import Pie from pyecharts.faker import Faker c4 =( 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() ) c4
ワードクラウド図を描く
from wordcloud import WordCloud import jieba from tkinter import _flatten from matplotlib.pyplot import imread from PIL import Image、ImageDraw、ImageFont import matplotlib.pyplot as pltwith 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()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私は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')my_word_cloud(data = data ["评论"]、stopWords = stopWords、img = "1.jpeg")
データ収集
追記
最近、多くの友人がプライベートメッセージを通じてPythonの学習問題について相談しました。コミュニケーションを促進するには、青をクリックしてディスカッションに参加し、自分でリソースベースに回答してください