之前利用Python的request和BeautifulSoup工具包爬取了IMDB網(wǎng)站上美國電影票房歷史排名前1000的電影數(shù)據(jù)堤撵,本文以此數(shù)據(jù)為基礎仁讨,作相關的數(shù)據(jù)分析。分析步驟大致與猴子哥live中介紹的方法一致:分為提出問題--理解數(shù)據(jù)--數(shù)據(jù)清洗--數(shù)據(jù)可視化实昨。猴子哥live中有一步是構(gòu)建模型洞豁,我把這部分融合到了數(shù)據(jù)可視化環(huán)節(jié)中。
1. 提出問題
本文使用的數(shù)據(jù)是IMDB美國票房排名前1000的電影數(shù)據(jù)荒给,數(shù)據(jù)包含了電影名稱丈挟,票房金額,上映年份志电,演職人員曙咽,IMDB評分,電影類型等信息挑辆,數(shù)據(jù)中的很多電影大家也比較熟悉例朱。
相信不少人都有這樣的經(jīng)歷金刁,當想要看一部電影的時候改含,會去百度一下誰是導演产徊,誰是主演律想。如果導演是克里斯托弗·諾蘭焊唬,心里已經(jīng)給電影打了個8分以上的評分了季惩。而阿湯哥的動作片寸认,預期也都能腎上腺素飆升纵顾。對于已上映的電影洁奈,不少人會去豆瓣搜索現(xiàn)時的評分间唉,或是前作的評價,若是豆瓣高分睬魂、高評論數(shù)终吼,也會按奈不住去蹭下熱度。如果要去電影院觀看的話氯哮,想必不少人會更傾向選擇動作片或者科幻大片這類特效豐富际跪,影音沖擊強烈的電影。近幾年特效技術和3D動畫的日漸成熟喉钢,影院觀影已經(jīng)是越來越多人的第一選擇姆打。所以結(jié)合以上信息,可以針對IMDB電影數(shù)據(jù)提出以下問題:
- 電影年份的分布如何肠虽?近幾年特效豐富的電影(以動作片幔戏、動畫片為主)是否在更加流行?
- 電影類型的分布如何税课?哪類電影的平均分較高闲延?
- 動作片或者科幻片等特效豐富的電影比例是否更高痊剖?
- 電影時長的分布如何?時長是否和評分有相關性垒玲?
- IMDB評分是否和票房有相關性陆馁?
- 哪些導演的電影更受觀眾喜愛?
- 哪些演員的電影總票房更高合愈?
2. 理解數(shù)據(jù)
數(shù)據(jù)分析的第二部分是理解數(shù)據(jù)叮贩,這里要先讀取數(shù)據(jù)并查看數(shù)據(jù)的內(nèi)容,了解數(shù)據(jù)的組成和包含的信息佛析。根據(jù)數(shù)據(jù)的內(nèi)容和類型益老,考慮下一步的數(shù)據(jù)清洗,例如刪除重復項寸莫,填充缺失值等捺萌。
# 導入相關模塊
import pandas as pd
import numpy as np
# 讀取存儲的csv文件
df = pd.read_csv('us_box_top1000.csv')
# 查看數(shù)據(jù)的行列數(shù)
df.shape
# 計算重復行數(shù)據(jù)
sum(df.duplicated())
讀取的數(shù)據(jù)有1000行,13列储狭,沒有重復行互婿。由于爬取的是美國歷史票房排名前1000的電影數(shù)據(jù),目前來看數(shù)據(jù)符合預期辽狈。
# 查看數(shù)據(jù)的列標題
df.columns
Index(['rank', 'title', 'year', 'certificate', 'runtime', 'genre', 'imdb_rate',
'metascore', 'votes', 'gross', 'director', 'stars', 'intro'],
dtype='object')
對比IMDB網(wǎng)頁內(nèi)容慈参,列標題基本上涵蓋了每部電影的完整信息。
[圖片上傳失敗...(image-fa0757-1538492803170)]
# 查看更多的列信息和每列數(shù)據(jù)類型
df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1000 entries, 0 to 999
Data columns (total 13 columns):
rank 1000 non-null object
title 1000 non-null object
year 1000 non-null object
certificate 1000 non-null object
runtime 1000 non-null object
genre 1000 non-null object
imdb_rate 1000 non-null float64
metascore 981 non-null float64
votes 1000 non-null object
gross 1000 non-null object
director 1000 non-null object
stars 1000 non-null object
intro 1000 non-null object
dtypes: float64(2), object(11)
memory usage: 101.6+ KB
可見數(shù)據(jù)相對完整刮萌,只有一列存在19個缺失值驮配,即metascore
。根據(jù)谷歌的信息着茸,可以知道imdb上的metascore來源于網(wǎng)站Metacritic壮锻,是根據(jù)專業(yè)媒體人士的評論生成的得分,更多信息可以參考這里:鏈接
# 查看數(shù)據(jù)的統(tǒng)計信息
df.describe()
- 由于只有
imdb_rate
評分和metascore
評分兩列數(shù)據(jù)是numeric型的涮阔,所以df.describe()
只顯示這兩列的統(tǒng)計信息猜绣。如果要顯示所有列的統(tǒng)計信息,可以使用df.describe(include='all')
敬特。 - 對比10分制的imdb評分和100分制的metascore評分掰邢,可見imdb評分相對波動范圍較小,最高分9.2分伟阔,最低分3.2分辣之,而metascore評分最高分100分,最低分低至12分皱炉。之后可以使用直方圖比較二者的評分分布情況怀估。
# 查看前5行數(shù)據(jù)
df.head()
- 前5行數(shù)據(jù)對應美國票房最高的5部電影,首位的是《星球大戰(zhàn):原力覺醒》,第二位是《阿凡達》多搀,第三名出人意料地被今年上映的漫威電影《黑豹》拿下歧蕉,力壓排在第四位的漫威同門大作《復仇者聯(lián)盟:無限戰(zhàn)爭》,第五名是家喻戶曉的經(jīng)典愛情電影《泰坦尼克號》康铭。
- 根據(jù)顯示的信息廊谓,可以知道13列數(shù)據(jù)對應的數(shù)據(jù)信息。分別是rank: 票房排名麻削,title: 電影名,year: 上映年份春弥,certificate: 電影分級呛哟,runtime: 電影時長,genre: 電影類型匿沛,imdb_rate: imdb評分扫责,metascore: metascore評分,votes: 投票人數(shù)逃呼,gross: 票房鳖孤,director: 導演,stars: 主演明星抡笼,intro: 簡介苏揣。
- 部分數(shù)據(jù)列需要清洗并轉(zhuǎn)換數(shù)據(jù)類型。
rank
列的數(shù)據(jù)是排名數(shù)據(jù)推姻,都應該是整數(shù)平匈,清洗時需要刪掉整數(shù)后面多余的點號”.“并轉(zhuǎn)換成int
類型。year
年份藏古,runtime
電影時長(分鐘數(shù))和votes
投票人數(shù)也應該轉(zhuǎn)換成整數(shù)增炭。gross
票房數(shù)據(jù)帶美金符號和字母M
,含兩位小數(shù)拧晕,清洗后需要轉(zhuǎn)換成float
類型隙姿。genre
電影類型和intro
簡介兩列數(shù)據(jù)開頭含有冗余的\n
,需要刪除厂捞。 -
genre
電影類型和stars
主演明星含有多個值输玷,director
導演數(shù)據(jù)可能也存在有兩個或以上導演名的情況,后面需要考慮做適當處理蔫敲。
3. 數(shù)據(jù)清洗
根據(jù)上述分析饲嗽,按照列標題順序?qū)?shù)據(jù)進行清洗,每一步都使用df[col_name].head()
或者其他合適的方法檢查清洗后的數(shù)據(jù)奈嘿。
# 清洗rank列貌虾,刪除多余的”.“號并轉(zhuǎn)換成int類型
df['rank'] = df['rank'].str.replace('.', '').astype(int)
此時報錯:ValueError: invalid literal for int() with base 10: '1,000'
,原因是1,000
中含有千位符裙犹,無法轉(zhuǎn)換成int
類型尽狠,需要把千位符刪除衔憨。修改代碼如下:
# 使用兩次str.replace()
df['rank'] = df['rank'].str.replace('.', '').str.replace(',', '').astype(int)
df['rank'].head()
# 檢查year列數(shù)據(jù)的唯一值
df['year'].unique()
array(['(2015)', '(2009)', '(2018)', '(1997)', '(2012)', '(2017)',
'(2008)', '(2016)', '(1999)', '(2004)', '(1982)', '(2013)',
'(2006)', '(2010)', '(2002)', '(1993)', '(I) (2013)', '(2011)',
'(2003)', '(2005)', '(I) (2015)', '(2014)', '(2007)', '(I) (2010)',
'(1994)', '(I) (2017)', '(1977)', '(2001)', '(1983)', '(1996)',
'(1980)', '(1990)', '(2000)', '(1975)', '(1989)', '(I) (2016)',
'(1981)', '(1984)', '(1973)', '(1991)', '(1992)', '(1998)',
'(1985)', '(1939)', '(1995)', '(I) (2008)', '(1978)', '(1937)',
'(1986)', '(I) (2005)', '(II) (2015)', '(I) (1995)', '(1988)',
'(I) (2011)', '(1987)', '(I) (2009)', '(1965)', '(I) (2014)',
'(1961)', '(1967)', '(IX) (2016)', '(I) (1998)', '(1972)',
'(I) (2012)', '(1974)', '(1976)', '(1970)', '(1979)', '(1942)',
'(1969)', '(1964)', '(II) (2016)', '(1971)', '(1956)', '(1955)',
'(1953)', '(III) (2015)', '(1950)', '(1940)', '(I) (1999)'],
dtype=object)
年份數(shù)據(jù)很亂,不少年份信息前面還含有冗余字符袄膏,例如(III)等践图。通過觀察可發(fā)現(xiàn),年份的四位數(shù)字出現(xiàn)在倒數(shù)第五個字符至倒數(shù)第二個字符沉馆,可以通過str[:]
方法選取這四位字符再轉(zhuǎn)換成int
類型码党。此外,榜單中有不少電影年代久遠斥黑,考慮到數(shù)據(jù)可比性揖盘,只保留1980年以后的電影。
# 清洗year列锌奴,使用str[:]選取年份數(shù)字并轉(zhuǎn)換成int類型兽狭,使用df.unique()方法檢查數(shù)據(jù)
df['year'] = df['year'].str[-5:-1].astype(int)
df['year'].unique()
array([2015, 2009, 2018, 1997, 2012, 2017, 2008, 2016, 1999, 2004, 1982,
2013, 2006, 2010, 2002, 1993, 2011, 2003, 2005, 2014, 2007, 1994,
1977, 2001, 1983, 1996, 1980, 1990, 2000, 1975, 1989, 1981, 1984,
1973, 1991, 1992, 1998, 1985, 1939, 1995, 1978, 1937, 1986, 1988,
1987, 1965, 1961, 1967, 1972, 1974, 1976, 1970, 1979, 1942, 1969,
1964, 1971, 1956, 1955, 1953, 1950, 1940])
# 保留1980年以后的電影
df = df[df['year'] >= 1980]
# 檢查certificate列,查看數(shù)據(jù)分布
df['certificate'].value_counts()
PG-13 429
PG 239
R 233
G 46
Name: certificate, dtype: int64
結(jié)合維基百科--美國電影分級制度可知鹿蜀,PG-13, PG, R, G都是現(xiàn)有的電影分級符號箕慧。
# 清洗runtime電影時長列數(shù)據(jù),可使用str.split()方法
df['runtime'] = df['runtime'].str.split(' ').str.get(0).astype(int)
df['runtime'].head()
0 136
1 162
2 134
3 149
4 194
Name: runtime, dtype: int64
# 清洗genre電影類型數(shù)據(jù)茴恰,去掉前面的'\n'和可能存在的空格
df['genre'] = df['genre'].str.replace('\n', '').str.strip()
df['genre'].head()
0 Action, Adventure, Fantasy
1 Action, Adventure, Fantasy
2 Action, Adventure, Sci-Fi
3 Action, Adventure, Fantasy
4 Drama, Romance
Name: genre, dtype: object
每個的電影類型數(shù)據(jù)含有多個值颠焦,這里可以通過分析電影內(nèi)容來判斷電影類型,選取一個值作為電影的主題往枣。先查看票房前20的電影信息蒸健。
df.head(20)
根據(jù)前20行電影數(shù)據(jù),genre
列的數(shù)據(jù)中婉商,每部電影都有兩個或三個電影類型似忧,第一個電影類型最符合電影的內(nèi)容。所以選取第一個電影類型作為電影的首要類型丈秩。
df['main_genre'] = df['genre'].str.split(', ').str.get(0)
df['main_genre'].head()
0 Action
1 Action
2 Action
3 Action
4 Drama
Name: main_genre, dtype: object
# 清洗votes投票人數(shù)數(shù)據(jù)盯捌,去掉千分位符號并轉(zhuǎn)換成int類型
df['votes'] = df['votes'].str.replace(',', '').astype(int)
df['votes'].head()
0 753597
1 1001946
2 389075
3 484431
4 909482
Name: votes, dtype: int64
# 清洗gross票房金額數(shù)據(jù),刪除美金符號$和結(jié)尾的M蘑秽,并轉(zhuǎn)換成float類型
df['gross'] = df['gross'].str.replace('$', '').str.replace('M', '').astype(float)
df['gross'].head()
0 936.66
1 760.51
2 700.06
3 678.82
4 659.33
Name: gross, dtype: float64
# 清洗intro電影簡介列饺著,刪除前面的'\n'和可能存在的字符串兩側(cè)的空格
df['intro'] = df['intro'].str.replace('\n', '').str.strip()
df['intro'].head()
0 Three decades after the Empire's defeat, a new...
1 A paraplegic marine dispatched to the moon Pan...
2 T'Challa, heir to the hidden but advanced king...
3 The Avengers and their allies must be willing ...
4 A seventeen-year-old aristocrat falls in love ...
Name: intro, dtype: object
初步的清洗工作完畢,使用df.info()
和df.head()
確認數(shù)據(jù)清洗后的效果肠牲。
df.info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 947 entries, 0 to 999
Data columns (total 14 columns):
rank 947 non-null int64
title 947 non-null object
year 947 non-null int64
certificate 947 non-null object
runtime 947 non-null int64
genre 947 non-null object
imdb_rate 947 non-null float64
metascore 940 non-null float64
votes 947 non-null int64
gross 947 non-null float64
director 947 non-null object
stars 947 non-null object
intro 947 non-null object
main_genre 947 non-null object
dtypes: float64(3), int64(4), object(7)
memory usage: 111.0+ KB
df.head()
清洗后的數(shù)據(jù)看起來不錯幼衰!由于在數(shù)據(jù)清洗中,去掉了部分列數(shù)中包含的數(shù)據(jù)單位信息缀雳,例如電影時長的單位'min'渡嚣,因此可以通過修改列標題將單位信息添加到列標題上,方便讀者理解數(shù)據(jù)。
# 重命名部分列標題
df.rename(columns={'runtime': 'runtime_min', 'gross': 'gross_million_dollar'}, inplace=True)
df.columns
Index(['rank', 'title', 'year', 'certificate', 'runtime_min', 'genre',
'imdb_rate', 'metascore', 'votes', 'gross_million_dollar', 'director',
'stars', 'intro', 'main_genre'],
dtype='object')
由于df['metascore']
列存在部分缺失值识椰,首先查看缺失值的行數(shù)據(jù)再決定處理方法绝葡。
# 查看缺失值所在的行
condition = df['metascore'].isnull()
df[condition]
這些電影大部分是票房相對低的電影,所以舍棄這部分的電影腹鹉。
# 只保留含有metascore得分的電影
df = df[df['metascore'].notnull()]
4. 數(shù)據(jù)可視化
根據(jù)第一部分提出的問題藏畅,探索數(shù)據(jù)并進行數(shù)據(jù)可視化。數(shù)據(jù)建模部分包含在這個模塊功咒。
4.1 電影年份的分布
4.1.1 電影數(shù)量在不同年份的分布
# 導入并設置數(shù)據(jù)可視化相關模塊
import matplotlib.pyplot as plt
import seaborn as sns
%config InlineBackend.figure_format = 'retina'
%matplotlib inline
sns.set(color_codes=True)
sns.set_style('white')
sns.set_palette('tab20')
# 根據(jù)電影年份數(shù)據(jù)作直方圖
fig, ax = plt.subplots()
df['year'].hist(range=(1980,2020), bins=40, color=(114/255,158/255,206/255))
ax.set_title('The Year Distribution of US Top Box Office Movies')
# 只保留底部坐標軸
ax.spines['top'].set_visible(False)
ax.spines['left'].set_visible(False)
ax.spines['right'].set_visible(False)
# 設定xy軸標簽和網(wǎng)格愉阎,方便閱讀數(shù)據(jù)
ax.set_yticklabels([0, 10, 20, 30, 40, 50])
ax.set_xticklabels(np.arange(1975, 2025, 5))
ax.grid(alpha=0.5)
數(shù)據(jù)顯示總體上每年的高票房電影呈現(xiàn)逐漸增多的趨勢,以每個9到10年為范圍力奋,則呈現(xiàn)階梯上升的趨勢诫硕。1998年起至2003年,高票房電影數(shù)量快速增加刊侯,此后基本保持在每年30部以上高票房電影的水平(不考慮不是完整年份的2018年)。
4.1.2 不同電影類型的年份累計分析
# 統(tǒng)計不同年份锉走、不同類型電影的數(shù)量
cumsum = df.groupby(['main_genre', 'year']).title.count()
# 使用累加功能統(tǒng)計1980年起不同年份不同電影類型的累計數(shù)量滨彻,對于中間出現(xiàn)的缺失值,使用前值填充
genre_cumsum = cumsum.unstack(level=0).cumsum().ffill()
# 只選取總數(shù)量大于50的電影類型數(shù)據(jù)
genre_cumsum = genre_cumsum.loc[:,genre_cumsum.iloc[-1,:] >= 50]
# 根據(jù)電影類型統(tǒng)計數(shù)據(jù)作圖
fig, ax2 = plt.subplots(figsize=(12,6))
genre_cumsum.plot(ax=ax12, legend=False, linewidth=3)
# 添加數(shù)據(jù)標簽
for i in last_row.iteritems():
if i[0] == 'Adventure' or i[0] == 'Biography' or i[0] == 'Horror':
ax2.annotate('{} {}'.format(int(i[1]), i[0]), xy=(2018.5, i[1]-5), fontsize=12)
else:
ax2.annotate('{} {}'.format(int(i[1]), i[0]), xy=(2018.5, i[1]+5), fontsize=12)
# 美化圖表
ax2.set_title('The Aggregate Movies of Different Genres Over Years', fontsize=16)
ax2.spines['top'].set_visible(False)
ax2.spines['right'].set_visible(False)
ax2.spines['left'].set_visible(False)
ax2.tick_params(bottom=True, labelleft=False)
ax2.set_xlabel('')
plt.tight_layout()
從上圖可見挪蹭,前五大電影類型分別是動作片Action
亭饵,喜劇片Comedy
,動畫片Animation
梁厉,劇情片Drama
辜羊,冒險片Adventure
。1995年之前词顾,動作片和喜劇片都是影院觀眾最喜愛的電影類型八秃,對應的高票房數(shù)量不分伯仲,劇情片是另一相對流行的電影類型肉盹。1995年后昔驱,高票房的動作片快速增長,甩開了喜劇片上忍。喜劇片隨仍是高票房數(shù)量第二多的電影類型骤肛,但近幾年增速明顯放緩。高票房動畫片進入榜單的時間最晚窍蓝,但在1998年前后迎來明顯增長腋颠,此后的十年里完成了對劇情片和冒險片的超越。如果動畫片保持目前的增速吓笙,有望在之后的十幾二十年里超越喜劇片淑玫,成為高票房數(shù)量第二的電影類型。
據(jù)以上不同電影類型的高票房電影數(shù)量的變化數(shù)據(jù),可以判斷最近20年來特效技術混移、3D及動畫技術的發(fā)展和不斷完善祠墅,助推了動作片、動畫片的票房歌径,因為這兩類電影是這些新技術的最大受益者毁嗦。
4.2 電影類型的分布如何?哪類電影的平均分較高回铛?
# 獲得電影類型的分布和平均得分數(shù)據(jù)
genre_data = df.groupby('main_genre')['title', 'imdb_rate'].agg({'title': 'count', 'imdb_rate': 'mean'}).sort_values(by='title', ascending=False)
genre_data
# 根據(jù)main_genre列數(shù)據(jù)作圖
# 繪制不同電影類型的數(shù)量分布
fig, ax2 = plt.subplots(figsize=(14,7))
plt.title('The Number and Average IMDB Rating of Different Genres', fontsize=18)
genre_data['title'].plot(kind='bar', width=0.8, color=(255/255,187/255,120/255))
# 設置坐標軸格式
ax2.set_xlabel('')
ax2.set_xticklabels(genre_data.index, rotation=0, fontsize=12)
ax2.tick_params(axis='x', rotation=0)
ax2.spines['top'].set_visible(False)
ax2.spines['left'].set_visible(False)
ax2.spines['right'].set_visible(False)
ax2.tick_params(bottom=False, left=False, right=False, labelleft=False, color='white')
# 標記不同電影類型的數(shù)量數(shù)據(jù)
x2 = np.arange(df['main_genre'].nunique())
y2 = df['main_genre'].value_counts().values
for x,y in zip(x2, y2):
ax2.annotate(y, xy=(x,y+5), color=(255/255,158/255,74/255), fontsize=12, weight='bold', ha='center', va='center')
# 繪制不同電影的平均IMDB分數(shù)
ax3 = ax2.twinx()
ax3.axhline(df['imdb_rate'].mean(), color='slateblue', linestyle='--', linewidth=2, alpha=0.5)
genre_data['imdb_rate'].plot(color=(114/255,158/255,206/255), marker='o', markersize=30, linewidth=3)
# 設置坐標軸格式
ax3.set_ylim(0, 10)
ax3.spines['top'].set_visible(False)
ax3.spines['left'].set_visible(False)
ax3.spines['right'].set_visible(False)
ax3.spines['bottom'].set_visible(False)
ax3.tick_params(bottom=False, left=False, right=False, labelright=False, labelbottom=False)
# 標記IMDB評分數(shù)據(jù)
x3 = np.arange(df['main_genre'].nunique())
y3 = genre_data['imdb_rate'].values
for x,y in zip(x3, y3):
ax3.annotate(round(y,1), xy=(x,y-0.05), color='white', fontsize=12, weight='bold', ha='center', va='center')
# 繪制所有IMDB電影平均得分參考線
ax3.annotate('Average IMDB \nRating of All Movies', xy=(11, df['imdb_rate'].mean()-0.4), color='b', fontsize=12, ha='center', va='center')
ax3.text(12-0.1, df['imdb_rate'].mean(), round(df['imdb_rate'].mean(),1), color='b', fontsize=14, ha='center', va='center')
進入榜單的電影類型總共有12種狗准,除了之前已經(jīng)討論過的前5大電影類型,按數(shù)量由多到少分別是犯罪片Crime
茵肃,傳記片Biography
腔长,恐怖片Horror
,懸疑片Mystery
验残,奇幻片Fantasy
捞附,家庭片Family
和科幻片Sci-Fi
。犯罪片您没、傳記片和恐怖片合計占據(jù)了1/10的比例鸟召,懸疑片,奇幻片氨鹏、家庭片和科幻片合計只有14部欧募,比例非常小。
榜單電影的IMDB平均分為6.8分仆抵。一大特征是上榜數(shù)量多的電影類型跟继,得分反而相對低。動作片平均分剛剛達到平均線镣丑,數(shù)量排第二的喜劇片在平均得分上墊底舔糖,動畫片和冒險片則接近平均線。得分高的是數(shù)量相對少的劇情片莺匠,犯罪片和傳記片剩盒,都超過了7分。相對于靠特效慨蛙、打斗辽聊、場面支撐的動作片、冒險片期贫,這三類影片均是靠劇情和故事內(nèi)容吸引觀眾的跟匆。所以好的故事還是感動觀眾的最重要因素。
4.3 電影時長的分布如何通砍?時長是否和評分有相關性玛臂?
fig, ax4 = plt.subplots()
df['runtime_min'].hist(range=(70,210), bins=14, color=(114/255,158/255,206/255))
ax4.set_title('The Runtime Distribution of US Top Box Office Movies')
ax4.spines['top'].set_visible(False)
ax4.spines['left'].set_visible(False)
ax4.spines['right'].set_visible(False)
ax4.set_xticklabels(np.arange(70,220,10))
ax4.set_xticks(np.arange(70,220,10))
ax4.grid()
這些高票房電影時長主要分布在90分鐘到140分鐘區(qū)間烤蜕,這也是目前相對流行的影院電影時長。
# 繪制時長和IMDB評分相關性
fig = plt.figure(figsize=(14,7))
sns.lmplot(data=df, x='runtime_min', y='imdb_rate')
sns.despine()
時長和IMDB評分呈一定的相關性迹冤,時長短的電影既有高分也有低分讽营,但時長超過160分鐘的電影基本都能獲得6分以上的分數(shù),時長最長的兩部電影甚至得到了接近9分的超高得分泡徙,IMDB評分接近或低于4分的電影時長均小于130分鐘橱鹏。豐富的劇情和長長的故事也許也是一種容易感染觀眾的方式,這也和之前提到的好的故事打動觀眾相呼應堪藐。
4.4 IMDB評分和metascore評分的分布及相關性
# 比較IMDB得分和metascore得分的分布
fig = plt.figure()
fig.suptitle('The Distribution of IMDB Rating and Metascore')
ax5 = fig.add_subplot(1,2,1)
df['imdb_rate'].hist(range=(0,10), bins=10, color=(114/255,158/255,206/255))
ax5.grid()
ax5.set_xlim(0,10)
ax5.spines['top'].set_visible(False)
ax5.spines['left'].set_visible(False)
ax5.spines['right'].set_visible(False)
ax6 = fig.add_subplot(1,2,2, sharey=ax5)
df['metascore'].hist(range=(0,100), bins=10, color=(114/255,158/255,206/255))
ax6.grid()
ax6.set_xticks([0,20,40,60,80,100])
ax6.spines['top'].set_visible(False)
ax6.spines['left'].set_visible(False)
ax6.spines['right'].set_visible(False)
ax6.tick_params(bottom=False, left=False, right=False, labelright=False, labelleft=False)
plt.tight_layout()
IMDB評分集中在6分到8分區(qū)間莉兰,9分以上的超高分電影幾乎絕跡。Metascore得分的分布接近正態(tài)分布礁竞,超低分和超高分的電影都占據(jù)一定比例糖荒。
# IMDB評分和metascore得分的相關性
sns.lmplot(data=df, x='imdb_rate', y='metascore')
sns.despine()
可見,IMDB評分和metascore評分呈高度相關性模捂,大眾和專業(yè)影評人的評價還是相對接近的捶朵。
4.5 評分人數(shù)和電影票房的相關性
# IMDB評分人數(shù)和電影票房的相關性
fig = plt.figure(figsize=(10,5))
sns.scatterplot(data=df, x='votes', y='gross_million_dollar')
sns.despine()
由上圖可知,IMDB評分人數(shù)和電影票房的相關性很弱狂男,高票房不代表評分人數(shù)多综看,低票房電影也能有大量的IMDB評分人數(shù)。