数据集来源:
https://www.kaggle.com/shivamb/netflix-shows
参考:
https://www.kaggle.com/code/shivamb/netflix-shows-and-movies-exploratory-analysis/notebook
import plotly.graph_objects as go
from plotly.offline import init_notebook_mode, iplot
import pandas as pd
df = pd.read_csv("./netflix_titles.csv")
df.head(10)
|
show_id |
type |
title |
director |
cast |
country |
date_added |
release_year |
rating |
duration |
listed_in |
description |
0 |
s1 |
Movie |
Dick Johnson Is Dead |
Kirsten Johnson |
NaN |
United States |
September 25, 2021 |
2020 |
PG-13 |
90 min |
Documentaries |
As her father nears the end of his life, filmm... |
1 |
s2 |
TV Show |
Blood & Water |
NaN |
Ama Qamata, Khosi Ngema, Gail Mabalane, Thaban... |
South Africa |
September 24, 2021 |
2021 |
TV-MA |
2 Seasons |
International TV Shows, TV Dramas, TV Mysteries |
After crossing paths at a party, a Cape Town t... |
2 |
s3 |
TV Show |
Ganglands |
Julien Leclercq |
Sami Bouajila, Tracy Gotoas, Samuel Jouy, Nabi... |
NaN |
September 24, 2021 |
2021 |
TV-MA |
1 Season |
Crime TV Shows, International TV Shows, TV Act... |
To protect his family from a powerful drug lor... |
3 |
s4 |
TV Show |
Jailbirds New Orleans |
NaN |
NaN |
NaN |
September 24, 2021 |
2021 |
TV-MA |
1 Season |
Docuseries, Reality TV |
Feuds, flirtations and toilet talk go down amo... |
4 |
s5 |
TV Show |
Kota Factory |
NaN |
Mayur More, Jitendra Kumar, Ranjan Raj, Alam K... |
India |
September 24, 2021 |
2021 |
TV-MA |
2 Seasons |
International TV Shows, Romantic TV Shows, TV ... |
In a city of coaching centers known to train I... |
5 |
s6 |
TV Show |
Midnight Mass |
Mike Flanagan |
Kate Siegel, Zach Gilford, Hamish Linklater, H... |
NaN |
September 24, 2021 |
2021 |
TV-MA |
1 Season |
TV Dramas, TV Horror, TV Mysteries |
The arrival of a charismatic young priest brin... |
6 |
s7 |
Movie |
My Little Pony: A New Generation |
Robert Cullen, José Luis Ucha |
Vanessa Hudgens, Kimiko Glenn, James Marsden, ... |
NaN |
September 24, 2021 |
2021 |
PG |
91 min |
Children & Family Movies |
Equestria's divided. But a bright-eyed hero be... |
7 |
s8 |
Movie |
Sankofa |
Haile Gerima |
Kofi Ghanaba, Oyafunmike Ogunlano, Alexandra D... |
United States, Ghana, Burkina Faso, United Kin... |
September 24, 2021 |
1993 |
TV-MA |
125 min |
Dramas, Independent Movies, International Movies |
On a photo shoot in Ghana, an American model s... |
8 |
s9 |
TV Show |
The Great British Baking Show |
Andy Devonshire |
Mel Giedroyc, Sue Perkins, Mary Berry, Paul Ho... |
United Kingdom |
September 24, 2021 |
2021 |
TV-14 |
9 Seasons |
British TV Shows, Reality TV |
A talented batch of amateur bakers face off in... |
9 |
s10 |
Movie |
The Starling |
Theodore Melfi |
Melissa McCarthy, Chris O'Dowd, Kevin Kline, T... |
United States |
September 24, 2021 |
2021 |
PG-13 |
104 min |
Comedies, Dramas |
A woman adjusting to life after a loss contend... |
df["date_added"] = pd.to_datetime(df['date_added'])
df['year_added'] = df['date_added'].dt.year
df['month_added'] = df['date_added'].dt.month
df['season_count'] = df.apply(lambda x : str(x['duration']).split(" ")[0] if 'Season' in str(x['duration']) else "",axis = 1)
df['duration'] = df.apply(lambda x : str(x['duration']).split(" ")[0] if 'Season'not in str(x['duration']) else "",axis = 1)
df.head()
|
show_id |
type |
title |
director |
cast |
country |
date_added |
release_year |
rating |
duration |
listed_in |
description |
year_added |
month_added |
season_count |
0 |
s1 |
Movie |
Dick Johnson Is Dead |
Kirsten Johnson |
NaN |
United States |
2021-09-25 |
2020 |
PG-13 |
90 |
Documentaries |
As her father nears the end of his life, filmm... |
2021.0 |
9.0 |
|
1 |
s2 |
TV Show |
Blood & Water |
NaN |
Ama Qamata, Khosi Ngema, Gail Mabalane, Thaban... |
South Africa |
2021-09-24 |
2021 |
TV-MA |
|
International TV Shows, TV Dramas, TV Mysteries |
After crossing paths at a party, a Cape Town t... |
2021.0 |
9.0 |
2 |
2 |
s3 |
TV Show |
Ganglands |
Julien Leclercq |
Sami Bouajila, Tracy Gotoas, Samuel Jouy, Nabi... |
NaN |
2021-09-24 |
2021 |
TV-MA |
|
Crime TV Shows, International TV Shows, TV Act... |
To protect his family from a powerful drug lor... |
2021.0 |
9.0 |
1 |
3 |
s4 |
TV Show |
Jailbirds New Orleans |
NaN |
NaN |
NaN |
2021-09-24 |
2021 |
TV-MA |
|
Docuseries, Reality TV |
Feuds, flirtations and toilet talk go down amo... |
2021.0 |
9.0 |
1 |
4 |
s5 |
TV Show |
Kota Factory |
NaN |
Mayur More, Jitendra Kumar, Ranjan Raj, Alam K... |
India |
2021-09-24 |
2021 |
TV-MA |
|
International TV Shows, Romantic TV Shows, TV ... |
In a city of coaching centers known to train I... |
2021.0 |
9.0 |
2 |
1、网飞上的影视内容类型占比
grouped = df['type'].value_counts().reset_index()
grouped = grouped.rename(columns = {
'type' : "count", "index" : 'type'})
trace = go.Pie(labels=grouped['type'], values=grouped['count'], pull=[0.05, 0], marker=dict(colors=["#6ad49b", "#a678de"]))
layout = go.Layout(title="Netflix影视类型占比图", height=360, legend=dict(x=0.05, y=1.1))
fig = go.Figure(data = [trace], layout = layout)
iplot(fig)
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/d9d99f40c11a203c6f9284923e00f779.png)
grouped
|
type |
count |
0 |
Movie |
6131 |
1 |
TV Show |
2676 |
电影占比69.6%,电视剧占比30.4%
2、不同类型年度增长趋势
df1 = df[df['type']== "TV Show"]
df2 = df[df['type']== "Movie"]
vc1 = df1['year_added'].value_counts().reset_index()
vc1 = vc1.rename(columns={
'year_added':'count','index':'year_added'})
vc1['percent'] = vc1['count'].apply(lambda x:100*x/sum(vc1['count']))
vc1 = vc1.sort_values('year_added')
vc2 = df2['year_added'].value_counts().reset_index()
vc2 = vc2.rename(columns={
'year_added':'count','index':'year_added'})
vc2['percent'] = vc2['count'].apply(lambda x:100*x/sum(vc2['count']))
vc2 = vc2.sort_values('year_added')
trace1 = go.Scatter(x=vc1['year_added'], y=vc1["count"], name="TV Shows", marker=dict(color="#a678de"))
trace2 = go.Scatter(x=vc2['year_added'], y=vc2["count"], name="Movies", marker=dict(color="#6ad49b"))
data = [trace1, trace2]
layout = go.Layout(title="不同影视类型年度增长趋势图", legend=dict(x=0.1, y=1.1, orientation="h"))
fig = go.Figure(data, layout