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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

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

TMDb電影數(shù)據(jù)集探索

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

項(xiàng)目概述

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

數(shù)據(jù)集

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

項(xiàng)目重點(diǎn)

需要探索的問題

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

    經(jīng)過對數(shù)據(jù)集的探索:

    • 了解如何調(diào)查數(shù)據(jù)集中的問題,以及將數(shù)據(jù)整理成可以使用的格式
    • 并練習(xí)傳達(dá)我的分析結(jié)果。
    • 能夠在 NumPy 和 Pandas 中使用向量化運(yùn)算,以加快數(shù)據(jù)分析代碼的運(yùn)行速度
    • 熟悉 Pandas 的 Series 和 DataFrame 對象,可以使訪問數(shù)據(jù)更方便
    • 了解如何使用 Matplotlib 生成圖形,展示你的發(fā)現(xiàn)

    項(xiàng)目流程

    第一步:選擇數(shù)據(jù)集

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

    第二步:組織文件

    • 用來傳達(dá)發(fā)現(xiàn)的報告文檔
    • 用來分析數(shù)據(jù)的Python 代碼()
    • 數(shù)據(jù)集(tmdb-movies.csv)

    第三步:數(shù)據(jù)整理

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

    常規(guī)屬性

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

    查看后發(fā)現(xiàn),共包含10866組,每組數(shù)據(jù)包含21種數(shù)據(jù)。

    #了解數(shù)據(jù)的基本形態(tài) 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

    #查看重復(fù)數(shù)據(jù) df_tmdb.duplicated().sum()

    顯示有1條重復(fù)數(shù)據(jù)。

    #清除重復(fù)數(shù)據(jù)并檢查 df_tmdb.drop_duplicates(inplace=True) df_tmdb.duplicated().sum() 0 #查看空值數(shù)據(jù) 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 #了解各項(xiàng)目的數(shù)據(jù)分布 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.涉及空值的數(shù)據(jù)列為imdb_id,cast,homepage,director,tagline,keywords,overview,genres,production_companies;對于已提出的問題,僅涉及genres含有23個空值(為自變量),需要消除空值行。

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

    數(shù)據(jù)清理

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

    由10866組刪除后變?yōu)?0842組;刪除的1組為重復(fù)數(shù)據(jù),23組為’genres’的空值數(shù)據(jù)。

    #根據(jù)'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”的零值數(shù)據(jù) df_tmdb = df_tmdb[df_tmdb['budget_adj'] > 0] df_tmdb = df_tmdb[df_tmdb['popularity'] > 0]

    "popularity"實(shí)際不存在零值數(shù)據(jù)。

    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

    第四步:探索性數(shù)據(jù)分析

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

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

    # 以“genres”分組,計(jì)算各種體裁對應(yīng)的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 #根據(jù)計(jì)算出的budget平均值,做bar圖比較 budget_mean.plot(kind = 'bar',color = 'grey')plt.ylabel('Budget')plt.title('Budget of different kinds of Genres');

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

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

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

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

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

    #選取前五的體裁,生成包含體裁(genres)、上映時間(release_year)、受歡迎度(popularity)的數(shù)據(jù)表 df_popularity = df_tmdb[['genres', 'release_year', 'popularity']].set_index('genres').loc[most_popularity].reset_index('genres') #建立一個五種體裁的,根據(jù)年份的受歡迎程度表 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));

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

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

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

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

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

    #得到不同體裁的評分、受歡迎程度表 df_vote = df_tmdb[['genres', 'vote_average', 'popularity']] #根據(jù)不同體裁,做“評分”與對應(yīng)“受歡迎度”的散點(diǎn)圖 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();

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

    結(jié)論

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

    其中去除了可能產(chǎn)生影響的"budget_adj"的零值數(shù)據(jù)(異常值),因?yàn)閷?shí)際預(yù)算不可能為零因此此類零值數(shù)據(jù)不應(yīng)作為分析要素使用,當(dāng)然經(jīng)過驗(yàn)證:去除前后得到的上述結(jié)論相同。

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

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

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

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

    數(shù)據(jù)集來源

    TMDb電影數(shù)據(jù)

    總結(jié)

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

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。