日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Udacity数据分析(入门)-TMDb电影数据集探索

發布時間:2023/12/31 编程问答 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Udacity数据分析(入门)-TMDb电影数据集探索 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

TMDb電影數據集探索

  • 項目概述
  • 數據集
  • 項目重點
    • 需要探索的問題
    • 目的
  • 項目流程
    • 第一步:選擇數據集
    • 第二步:組織文件
    • 第三步:數據整理
      • 常規屬性
      • 數據清理
    • 第四步:探索性數據分析
      • 研究問題 1 :哪種體裁/類型(genres)的平均預算(budget)最高?
      • 研究問題 2 :最受歡迎(popularity)前五的體裁/類型(genres),每年的受歡迎程度是如何變化的?
      • 研究問題 3 :哪種電影類型的評分(vote_average)最高;評分和受歡迎程度(popularity)有何關系?
    • 結論
  • 數據集來源

項目概述

在本項目中,將分析一個TMDb(The Movie Database:美國電影數據集),然后傳達我的發現。將使用 Python 庫 NumPy、Pandas 和 Matplotlib 來使幫助我進行分析。

數據集

本數據集中包含 10,000 條電影信息,信息來源為“電影數據庫”(TMDb,The Movie Database),包括用戶評分和票房。
“演職人員 (cast)”、“電影類別 (genres)”等數據列包含由豎線字符(|)分隔的多個數值。“演職人員 (cast) ”列中有一些奇怪的字符。以“_adj”結尾的最后兩列表示了考慮了通貨膨脹之后的相關電影的預算和收入(以2010年美元的價值來計算)。

項目重點

需要探索的問題

  • 哪種體裁/類型(genres)的平均預算(budget)最高?
  • 最受歡迎(popularity)前五的體裁/類型(genres),每年的受歡迎程度是如何變化的?
  • 哪種電影類型的評分(vote_average)最高——和受歡迎程度(popularity)有何關系?
  • 目的

    經過對數據集的探索:

    • 了解如何調查數據集中的問題,以及將數據整理成可以使用的格式
    • 并練習傳達我的分析結果。
    • 能夠在 NumPy 和 Pandas 中使用向量化運算,以加快數據分析代碼的運行速度
    • 熟悉 Pandas 的 Series 和 DataFrame 對象,可以使訪問數據更方便
    • 了解如何使用 Matplotlib 生成圖形,展示你的發現

    項目流程

    第一步:選擇數據集

    本次選取探索的數據集為“TMDb電影數據庫”,數據集中包含來自1960-2016年上映的近11,000部電影的基本信息,主要包括了電影類型、預算、票房、演職人員、時長、評分等信息。

    第二步:組織文件

    • 用來傳達發現的報告文檔
    • 用來分析數據的Python 代碼()
    • 數據集(tmdb-movies.csv)

    第三步:數據整理

    #加載要使用的庫 import pandas as pd import numpy as np import matplotlib.pyplot as plt import seaborn as sns%matplotlib inline

    常規屬性

    #導入數據 df_tmdb = pd.read_csv('tmdb-movies.csv') #查看基本信息 df_tmdb.info()

    查看后發現,共包含10866組,每組數據包含21種數據。

    #了解數據的基本形態 df_tmdb.head(3) idimdb_idpopularitybudgetrevenueoriginal_titlecasthomepagedirectortagline...overviewruntimegenresproduction_companiesrelease_datevote_countvote_averagerelease_yearbudget_adjrevenue_adj012
    135397tt036961032.9857631500000001513528810Jurassic WorldChris Pratt|Bryce Dallas Howard|Irrfan Khan|Vi...http://www.jurassicworld.com/Colin TrevorrowThe park is open....Twenty-two years after the events of Jurassic ...124Action|Adventure|Science Fiction|ThrillerUniversal Studios|Amblin Entertainment|Legenda...6/9/1555626.520151.379999e+081.392446e+09
    76341tt139219028.419936150000000378436354Mad Max: Fury RoadTom Hardy|Charlize Theron|Hugh Keays-Byrne|Nic...http://www.madmaxmovie.com/George MillerWhat a Lovely Day....An apocalyptic story set in the furthest reach...120Action|Adventure|Science Fiction|ThrillerVillage Roadshow Pictures|Kennedy Miller Produ...5/13/1561857.120151.379999e+083.481613e+08
    262500tt290844613.112507110000000295238201InsurgentShailene Woodley|Theo James|Kate Winslet|Ansel...http://www.thedivergentseries.movie/#insurgentRobert SchwentkeOne Choice Can Destroy You...Beatrice Prior must confront her inner demons ...119Adventure|Science Fiction|ThrillerSummit Entertainment|Mandeville Films|Red Wago...3/18/1524806.320151.012000e+082.716190e+08

    3 rows × 21 columns

    #查看重復數據 df_tmdb.duplicated().sum()

    顯示有1條重復數據。

    #清除重復數據并檢查 df_tmdb.drop_duplicates(inplace=True) df_tmdb.duplicated().sum() 0 #查看空值數據 df_tmdb.isnull().sum() id 0 imdb_id 10 popularity 0 budget 0 revenue 0 original_title 0 cast 76 homepage 7929 director 44 tagline 2824 keywords 1493 overview 4 runtime 0 genres 23 production_companies 1030 release_date 0 vote_count 0 vote_average 0 release_year 0 budget_adj 0 revenue_adj 0 dtype: int64 #了解各項目的數據分布 df_tmdb.describe() idpopularitybudgetrevenueruntimevote_countvote_averagerelease_yearbudget_adjrevenue_adjcountmeanstdmin25%50%75%max
    10865.00000010865.0000001.086500e+041.086500e+0410865.00000010865.00000010865.00000010865.0000001.086500e+041.086500e+04
    66066.3744130.6464461.462429e+073.982690e+07102.071790217.3996325.9750122001.3218591.754989e+075.136900e+07
    92134.0919711.0002313.091428e+071.170083e+0831.382701575.6446270.93513812.8132603.430753e+071.446383e+08
    5.0000000.0000650.000000e+000.000000e+000.00000010.0000001.5000001960.0000000.000000e+000.000000e+00
    10596.0000000.2075750.000000e+000.000000e+0090.00000017.0000005.4000001995.0000000.000000e+000.000000e+00
    20662.0000000.3838310.000000e+000.000000e+0099.00000038.0000006.0000002006.0000000.000000e+000.000000e+00
    75612.0000000.7138571.500000e+072.400000e+07111.000000146.0000006.6000002011.0000002.085325e+073.370173e+07
    417859.00000032.9857634.250000e+082.781506e+09900.0000009767.0000009.2000002015.0000004.250000e+082.827124e+09

    1.涉及空值的數據列為imdb_id,cast,homepage,director,tagline,keywords,overview,genres,production_companies;對于已提出的問題,僅涉及genres含有23個空值(為自變量),需要消除空值行。

    2.對于"budget"列,存在“零值”,為了消除影響需將所有零值數據行去除

    數據清理

    #填充'genres'中的空值數據為“NaN” df_tmdb['genres'] = df_tmdb['genres'].fillna("NaN")#獲取被填充的空值的索引 df_index = df_tmdb[df_tmdb.genres == 'NaN'].index.tolist()#刪除對應索引的行并檢查 df_tmdb = df_tmdb.drop(df_index) df_tmdb.shape (10842, 21)

    由10866組刪除后變為10842組;刪除的1組為重復數據,23組為’genres’的空值數據。

    #根據'genres'中的不同體裁類型單列成行,生成新的dataframe df_tmdb = df_tmdb.drop('genres', axis = 1).join(df_tmdb['genres'].str.split('|', expand = True).stack().reset_index(level = 1, drop = True).rename('genres')) df_tmdb.head() idimdb_idpopularitybudgetrevenueoriginal_titlecasthomepagedirectortagline...overviewruntimeproduction_companiesrelease_datevote_countvote_averagerelease_yearbudget_adjrevenue_adjgenres00001
    135397tt036961032.9857631500000001513528810Jurassic WorldChris Pratt|Bryce Dallas Howard|Irrfan Khan|Vi...http://www.jurassicworld.com/Colin TrevorrowThe park is open....Twenty-two years after the events of Jurassic ...124Universal Studios|Amblin Entertainment|Legenda...6/9/1555626.520151.379999e+081.392446e+09Action
    135397tt036961032.9857631500000001513528810Jurassic WorldChris Pratt|Bryce Dallas Howard|Irrfan Khan|Vi...http://www.jurassicworld.com/Colin TrevorrowThe park is open....Twenty-two years after the events of Jurassic ...124Universal Studios|Amblin Entertainment|Legenda...6/9/1555626.520151.379999e+081.392446e+09Adventure
    135397tt036961032.9857631500000001513528810Jurassic WorldChris Pratt|Bryce Dallas Howard|Irrfan Khan|Vi...http://www.jurassicworld.com/Colin TrevorrowThe park is open....Twenty-two years after the events of Jurassic ...124Universal Studios|Amblin Entertainment|Legenda...6/9/1555626.520151.379999e+081.392446e+09Science Fiction
    135397tt036961032.9857631500000001513528810Jurassic WorldChris Pratt|Bryce Dallas Howard|Irrfan Khan|Vi...http://www.jurassicworld.com/Colin TrevorrowThe park is open....Twenty-two years after the events of Jurassic ...124Universal Studios|Amblin Entertainment|Legenda...6/9/1555626.520151.379999e+081.392446e+09Thriller
    76341tt139219028.419936150000000378436354Mad Max: Fury RoadTom Hardy|Charlize Theron|Hugh Keays-Byrne|Nic...http://www.madmaxmovie.com/George MillerWhat a Lovely Day....An apocalyptic story set in the furthest reach...120Village Roadshow Pictures|Kennedy Miller Produ...5/13/1561857.120151.379999e+083.481613e+08Action

    5 rows × 21 columns

    #去除“budget_adj”的零值數據 df_tmdb = df_tmdb[df_tmdb['budget_adj'] > 0] df_tmdb = df_tmdb[df_tmdb['popularity'] > 0]

    "popularity"實際不存在零值數據。

    df_tmdb['genres'].value_counts() Drama 2316 Comedy 1740 Thriller 1641 Action 1428 Adventure 906 Romance 861 Crime 823 Horror 765 Science Fiction 701 Family 523 Fantasy 508 Mystery 440 Animation 260 History 183 Music 169 War 155 Western 74 Documentary 64 Foreign 35 TV Movie 9 Name: genres, dtype: int64

    第四步:探索性數據分析

    研究問題 1 :哪種體裁/類型(genres)的平均預算(budget)最高?

    要計算不同"genres"電影的"budget"均值,并經過排序得出最高的類型;并且為了消除通脹影響,計算"budget_adj"的數據。

    # 以“genres”分組,計算各種體裁對應的budget平均值,按降序排列 budget_mean = df_tmdb.groupby('genres')['budget_adj'].mean().sort_values(ascending=False) budget_mean genres Adventure 7.133755e+07 Animation 6.800557e+07 Fantasy 6.749065e+07 Family 6.337153e+07 Action 5.502584e+07 Western 5.462267e+07 Science Fiction 5.176227e+07 War 5.039431e+07 History 4.847202e+07 Thriller 3.663947e+07 Mystery 3.586516e+07 Crime 3.542695e+07 Comedy 3.470445e+07 Music 3.135773e+07 Romance 3.113657e+07 Drama 3.052799e+07 Horror 1.661574e+07 Foreign 1.277944e+07 TV Movie 5.492844e+06 Documentary 5.063684e+06 Name: budget_adj, dtype: float64 #根據計算出的budget平均值,做bar圖比較 budget_mean.plot(kind = 'bar',color = 'grey')plt.ylabel('Budget')plt.title('Budget of different kinds of Genres');

    結論1:根據降序排列畫出的圖,排第一(平均預算最高的)的為“Adventure”類型。

    研究問題 2 :最受歡迎(popularity)前五的體裁/類型(genres),每年的受歡迎程度是如何變化的?

    計算不同"genres"電影對應的"popularity"均值,降序得到前五位的類型;并作出各類型電影,“popularity"隨"release_year”(上映時間)變化的圖像。

    #計算不同體裁的影片,受歡迎程度的總平均值,降序排列 popularity_mean = df_tmdb.groupby(['genres'])['popularity'].mean().sort_values(ascending=False) #選取最受歡迎前五的體裁(獲取對應的索引表) most_popularity = popularity_mean[:5].index.tolist() most_popularity ['Adventure', 'Science Fiction', 'Fantasy', 'Animation', 'Action']

    結論2-1:最受歡迎(popularity)前五的電影類型是Adventure,Science Fiction,Fantasy,Action,Animation。

    #選取前五的體裁,生成包含體裁(genres)、上映時間(release_year)、受歡迎度(popularity)的數據表 df_popularity = df_tmdb[['genres', 'release_year', 'popularity']].set_index('genres').loc[most_popularity].reset_index('genres') #建立一個五種體裁的,根據年份的受歡迎程度表 df_popularity_year = pd.pivot_table(df_popularity, values='popularity', index='release_year', columns='genres') #作圖,橫軸為年份,縱軸為受歡迎程度 df_popularity_year.plot(kind='line',subplots=True, sharex=True, sharey=True, figsize=(20,20));

    結論2-2:1960-2016期間最受歡迎的前五類電影類型中,除"Animation"外均在2010年后有了進一步提升。

    研究問題 3 :哪種電影類型的評分(vote_average)最高;評分和受歡迎程度(popularity)有何關系?

    計算"vote_average"的平均值并選出最高的類型(“genres”);根據作出的"vote_average"(評分)和"popularity"(受歡迎程度)散點圖了解相關關系。

    # 得到vote_average均值最大的體裁類型 df_tmdb.groupby('genres')['vote_average'].mean().sort_values(ascending=False).index[0] 'Documentary'

    結論3-1:Documentary體裁的平均評分最高。

    #得到不同體裁的評分、受歡迎程度表 df_vote = df_tmdb[['genres', 'vote_average', 'popularity']] #根據不同體裁,做“評分”與對應“受歡迎度”的散點圖 df_vote_scatter = sns.FacetGrid(df_vote, col='genres', col_wrap=4, hue='vote_average') df_vote_scatter.map(plt.scatter, 'vote_average', 'popularity', alpha=.7) df_vote_scatter.add_legend();

    結論3-2:除去Western、Documentary、TV Movie、Foreign數據較少;可以發現隨著平均評分由低到高,均存在較低的受歡迎度(popularity),而隨著受歡迎度增加,對應的平均評分也相應提高。

    結論

    1.以根據通脹后的預算(budget)數據來比較,"Adventure"類型的電影1960-2016期間的平均預算最高。

    其中去除了可能產生影響的"budget_adj"的零值數據(異常值),因為實際預算不可能為零因此此類零值數據不應作為分析要素使用,當然經過驗證:去除前后得到的上述結論相同。

    2.1960-2016最受歡迎(popularity)前五的電影類型是Adventure,Science Fiction,Fantasy,Action,Animation;其中Adventure,Science Fiction,Action在2010年后受歡迎度有明顯提升。

    有3種電影類型,由于對"budget_adj"異常值的處理 以及 本身的數據缺失,導致1985年以前的數據不連貫,因此5種最受歡迎類型的直接比較僅適用于1985年之后的變化。

    3.1960-2016的數據中Documentary類型的平均評分最高;更高的受歡迎度,伴隨更高的評分,但高評分不代表受歡迎。

    不同類型下的"popularity"均存在數值較大的數據,但不了解實際打分依據就無法真正判定是否為異常值,因此未做處理;另外根據Western、Documentary、TV Movie、Foreign四種類型,無法得出上述結論,可能由于數據量有限的緣故。

    數據集來源

    TMDb電影數據

    總結

    以上是生活随笔為你收集整理的Udacity数据分析(入门)-TMDb电影数据集探索的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。