2023. 11. 12. 17:57ㆍ공모전 & 프로젝트
https://github.com/1282saa/netflix-data-
GitHub - 1282saa/netflix-data-: this project analize netfilix data
this project analize netfilix data. Contribute to 1282saa/netflix-data- development by creating an account on GitHub.
github.com
넷플릭스¶
목차¶
3.데이터 소개
- 3-1 변수 설명
- 3-2 데이터 분석 내용
4.데이터 불러오기
- 4-1 분석에 필요한 패키지 불러오기
- 4-2 데이터 불러오기
5.데이터 검토 및 결측치 확인
- 5-1 결측치 확인
- 5-2 데이터 검토
6.데이터 전처리
- 6-1 변수명 변환
- 6-2 결측치 변환 및 행 제거
- 6-3 비교 분석을 위해 새로운 컬럼 생성
- 6-4 데이터 type 변환
7.one-hot encoding
8.데이터 분석 & EDA
- 8-1 넷플릭스에 프로그램이 추가되는 달 분석
- 8-2 type 컬럼의 tv show와 movie 타입 비율 분석
- 8-3 영화, 티비 쇼 타입의 연령대별 시청 수 분석
- 8-4 컨텐츠 추가 연도 분석
- 8-5 영화 프로그램 상영 시간 분석
- 8-6 장르와 프로그램 길이 분석
- 8-7 국가별 프로그램 길이 분석
- 8-8 국가별 인기 장르 분석
- 8-9 넷플릭스 제작 국가 분석
- 8-10 director 분석
- 8-11 개봉 연도와 프로그램 길이의 상관관계
9. 결론 및 인사이트
데이터 소개¶
변수 설명¶
- show_id : 프로그램 고유 id
- type : 프로그램의 카테고리 (tv show와 movie 타입으로 나눠짐)
- title : 프로그램 이름
- director : 감독 이름
- country : 제작국가
- date_added : 프로그램이 넷플릭스에 추가된 날짜
- release_year : 프로그램의 개봉일
- rating : 연령대별 프로그램 등급
- duration : 프로그램 길이
- listed_in : 프로그램의 장르
데이터 분석 내용¶
- 넷플릭스에 프로그램이 추가되는 달 분석
- type 컬럼의 tv show와 movie 타입 비율 분석
- 영화, 티비 쇼 타입의 연령대별 시청 수 분석
- 텐츠 추가 연도 분석
- 영화 프로그램 상영 시간 분석
- 장르와 프로그램 길이 분석
- 국가별 프로그램 길이 분석
- 국가별 인기 장르 분석
- 넷플릭스 제작 국가 분석
- director 분석
- 개봉 연도와 프로그램 길이의 상관관계
데이터 불러오기¶
분석에 필요한 패키지 불러오기¶
import pandas as pd
import numpy as np
import seaborn as sns
from sklearn.metrics.pairwise import cosine_similarity,cosine_distances
import matplotlib.pyplot as plt
import plotly.express as px
import plotly.graph_objects as go
from scipy.stats import norm
데이터 불러오기¶
nfx=pd.read_csv('netflix1.csv') #nfx로 데이터프레임 저장
nfx
show_id | type | title | director | country | date_added | release_year | rating | duration | listed_in | |
---|---|---|---|---|---|---|---|---|---|---|
0 | s1 | Movie | Dick Johnson Is Dead | Kirsten Johnson | United States | 9/25/2021 | 2020 | PG-13 | 90 min | Documentaries |
1 | s3 | TV Show | Ganglands | Julien Leclercq | France | 9/24/2021 | 2021 | TV-MA | 1 Season | Crime TV Shows, International TV Shows, TV Act... |
2 | s6 | TV Show | Midnight Mass | Mike Flanagan | United States | 9/24/2021 | 2021 | TV-MA | 1 Season | TV Dramas, TV Horror, TV Mysteries |
3 | s14 | Movie | Confessions of an Invisible Girl | Bruno Garotti | Brazil | 9/22/2021 | 2021 | TV-PG | 91 min | Children & Family Movies, Comedies |
4 | s8 | Movie | Sankofa | Haile Gerima | United States | 9/24/2021 | 1993 | TV-MA | 125 min | Dramas, Independent Movies, International Movies |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
8785 | s8797 | TV Show | Yunus Emre | Not Given | Turkey | 1/17/2017 | 2016 | TV-PG | 2 Seasons | International TV Shows, TV Dramas |
8786 | s8798 | TV Show | Zak Storm | Not Given | United States | 9/13/2018 | 2016 | TV-Y7 | 3 Seasons | Kids' TV |
8787 | s8801 | TV Show | Zindagi Gulzar Hai | Not Given | Pakistan | 12/15/2016 | 2012 | TV-PG | 1 Season | International TV Shows, Romantic TV Shows, TV ... |
8788 | s8784 | TV Show | Yoko | Not Given | Pakistan | 6/23/2018 | 2016 | TV-Y | 1 Season | Kids' TV |
8789 | s8786 | TV Show | YOM | Not Given | Pakistan | 6/7/2018 | 2016 | TV-Y7 | 1 Season | Kids' TV |
8790 rows × 10 columns
데이터 검토 및 결측치 확인¶
결측치 확인¶
nfx.isnull().sum()
show_id 0
type 0
title 0
director 0
country 0
date_added 0
release_year 0
rating 0
duration 0
listed_in 0
dtype: int64
데이터 검토¶
nfx.info()
#release_year 컬럼을 제외하고 모두 문자형인 것을 확인할 수 있음
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 8790 entries, 0 to 8789
Data columns (total 10 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 show_id 8790 non-null object
1 type 8790 non-null object
2 title 8790 non-null object
3 director 8790 non-null object
4 country 8790 non-null object
5 date_added 8790 non-null object
6 release_year 8790 non-null int64
7 rating 8790 non-null object
8 duration 8790 non-null object
9 listed_in 8790 non-null object
dtypes: int64(1), object(9)
memory usage: 686.8+ KB
nfx.describe()
release_year | |
---|---|
count | 8790.000000 |
mean | 2014.183163 |
std | 8.825466 |
min | 1925.000000 |
25% | 2013.000000 |
50% | 2017.000000 |
75% | 2019.000000 |
max | 2021.000000 |
nfx['director'].value_counts() #감독 컬럼의 빈도 수 파악
Not Given 2588
Rajiv Chilaka 20
Alastair Fothergill 18
Raúl Campos, Jan Suter 18
Suhas Kadav 16
...
Matt D'Avella 1
Parthiban 1
Scott McAboy 1
Raymie Muzquiz, Stu Livingston 1
Mozez Singh 1
Name: director, Length: 4528, dtype: int64
nfx['country'].value_counts() #나라별 시청 빈도 확인
United States 3240
India 1057
United Kingdom 638
Pakistan 421
Not Given 287
...
Iran 1
West Germany 1
Greece 1
Zimbabwe 1
Soviet Union 1
Name: country, Length: 86, dtype: int64
nfx['rating'].value_counts() #연령별 등급 확안
TV-MA 3205
TV-14 2157
TV-PG 861
R 799
PG-13 490
TV-Y7 333
TV-Y 306
PG 287
TV-G 220
NR 79
G 41
TV-Y7-FV 6
NC-17 3
UR 3
Name: rating, dtype: int64
rating 컬럼 설명
티비 쇼 권장 시청자 연령 그룹(빈도 수 순서로 설명)
TV-MA(성인 시청자 전용): 성인 시청자를 대상으로 하며 17세 미만의 어린이에게는 적합하지 않습니다. 콘텐츠에는 강렬한 폭력, 폭력적인 언어, 성적인 콘텐츠 또는 기타 성인용 주제가 포함될 수 있습니다.
TV-14(부모님 강력 주의): 일부 자료는 14세 미만의 어린이에게 적합하지 않을 수 있습니다. 콘텐츠에는 강렬한 폭력, 성적인 내용, 저속한 유머 또는 거친 언어가 포함될 수 있으므로 부모는 주의를 기울여야 합니다.
TV-PG(부모 지도 권장): 일부 자료는 어린이에게 적합하지 않을 수 있습니다. 콘텐츠에 가벼운 폭력, 암시적인 대화 또는 거친 언어가 포함될 수 있으므로 부모는 "부모의 지도"를 제공하는 것이 좋습니다.
R(제한): 17세 이상 시청가 또는 부모 또는 성인 보호자가 동반한 시청자로 제한됩니다. 콘텐츠에는 거친 언어, 격렬한 폭력, 과도한 노출, 약물 사용 또는 기타 성인용 주제가 포함될 수 있습니다. 이 등급은 일반적으로 TV 프로그램보다는 영화에 사용됩니다.
PG-13(부모님 강력 주의): 일부 자료는 13세 미만 어린이에게 부적절할 수 있습니다. 해당 콘텐츠에는 폭력, 짧은 노출, 온화한 언어가 포함될 수 있으므로 부모는 주의하시기 바랍니다. 이 등급은 일반적으로 TV 프로그램보다는 영화에 사용됩니다.
TV-Y7(고학년 어린이 대상): 7세 이상의 어린이를 대상으로 합니다. 콘텐츠는 좀 더 큰 어린이에게 적합하도록 설계되었으며 가벼운 판타지 폭력이나 코미디 요소가 포함될 수 있습니다.
TV-Y(모든 어린이): 모든 어린이에게 적합합니다. 콘텐츠는 모든 연령대의 어린이에게 적합하도록 설계되었으며 불쾌감을 줄 수 있는 내용을 포함하지 않습니다.
PG(부모 지도 권장): 일부 자료는 어린이에게 적합하지 않을 수 있습니다. 콘텐츠에는 어린 시청자가 혼란스럽거나 속상하다고 느낄 수 있는 내용이 포함될 수 있으므로 부모는 '부모의 지도'를 제공할 것을 권장합니다.
TV-G(일반 시청자): 모든 연령층에 적합합니다. 해당 콘텐츠는 어린이를 포함해 모든 사람에게 적합한 것으로 간주됩니다. 여기에는 부모가 부적절하다고 생각할 만한 자료가 포함되어 있지 않습니다.
NR(등급 없음): 콘텐츠에 특정 등급이 할당되지 않았습니다. 이는 독립 영화나 등급을 위해 제출되지 않은 콘텐츠 등 다양한 이유로 발생할 수 있습니다.
G(일반 관객): 모든 연령층에 적합합니다. 해당 콘텐츠는 어린이를 포함해 모든 사람에게 적합한 것으로 간주됩니다. 이 등급은 일반적으로 TV 프로그램보다는 영화에 사용됩니다.
TV-Y7-FV(고학년 대상 - 판타지 폭력): 7세 이상의 어린이를 대상으로 합니다. 콘텐츠에는 TV-Y7 등급 프로그램에 비해 더 강렬하거나 빈번한 판타지 폭력이 포함될 수 있습니다.
NC-17(성인 전용): 17세 이하는 입장할 수 없습니다. 해당 콘텐츠는 어린이나 청소년에게 적합하지 않으며 노골적인 성적 콘텐츠, 장기간의 폭력 또는 기타 극단적인 성인 주제가 포함될 수 있습니다. 이 등급은 일반적으로 TV 프로그램보다는 영화에 사용됩니다.
UR(등급 없음): 콘텐츠에 특정 등급이 할당되지 않았거나 등급이 부여된 영화의 등급이 없는 버전입니다. 시청자는 시청하기 전에 주의를 기울이고 콘텐츠의 성격을 고려해야 합니다.
전처리¶
변수명 변환¶
#rating컬럼을 쉽게 알아보기 위해 target_ages컬럼을 생성
#- ok(older kids)=3개
#- ad(adults)=5개
#- te(teens)=2개
#- ki(kids)=3개
ratings_ages = {
'TV-PG': 'Older Kids', ## ok
'TV-MA': 'Adults', ## ad
'TV-Y7-FV': 'Older Kids', ##ok
'TV-Y7': 'Older Kids', ##ok
'TV-14': 'Teens', ## te
'R': 'Adults', ## ad
'TV-Y': 'Kids', ##ki
'NR': 'Adults', ##ad ##NR(등급 없음): 콘텐츠에 특정 등급이 할당되지 않았습니다. 이는 독립 영화나 등급을 위해 제출되지 않은 콘텐츠 등 다양한 이유로 발생할 수 있습니다.
'PG-13': 'Teens', ##te
'TV-G': 'Kids', ##ki
'PG': 'Older Kids', ##ok
'G': 'Kids', ##ki
'UR': 'Adults', ##ad
#UR(등급 없음): 콘텐츠에 특정 등급이 할당되지 않았거나 등급이 부여된 영화의 등급이 없는 버전입니다. 시청자는 시청하기 전에 주의를 기울이고 콘텐츠의 성격을 고려해야 합니다.
'NC-17': 'Adults' ## ad
}
nfx['target_ages']=nfx['rating'].replace(ratings_ages)
결측치 변환 및 행 제거¶
# rating 컬름의 UR 값은 특정 등급이 지정되지 않았거나 부여된 영화의 등급이 없는 등급이다. 또한 빈도수를 확인하면 상대적으로 적은 빈도인 3개의 값이 존재하는 것을 확인 가능하다
#따라서 데이터 분석에 큰 요인이 되지않는 UR 등급이 존재하는 행은 삭제한다.
nfx['rating']=np.where(nfx['rating']=='UR',np.nan,nfx['rating']) #UR이 값을 결측치로 변환
nfx.isna().sum()
#ur 값은 삭제된 상태
show_id 0
type 0
title 0
director 0
country 0
date_added 0
release_year 0
rating 3
duration 0
listed_in 0
target_ages 0
dtype: int64
nfx=nfx.dropna() #결측치로 변환한 값 제거해주기
nfx.isna().sum() #ur값이 사라진 것을 확인 가능
show_id 0
type 0
title 0
director 0
country 0
date_added 0
release_year 0
rating 0
duration 0
listed_in 0
target_ages 0
dtype: int64
비교 분석을 위해 새로운 컬럼 생성¶
## date_added 컬럼을 연도와 달로 분해하기
# year_added 컬럼 추가 하기
nfx['year_added'] = nfx['date_added'].apply(lambda x: x.split("/")[-1])
# month_added 컬럼 추가 하기
nfx['month_added'] = nfx['date_added'].apply(lambda x: x.split("/")[0])
# 추가한 컬럼 데이터 확인
nfx.tail()
#year_added / month_added / target_ages 컬럼이 새롭게 추가된 것을 확인 가능
/var/folders/24/kj6qhrn550xbr18__b59pv440000gn/T/ipykernel_9766/2728872958.py:4: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
nfx['year_added'] = nfx['date_added'].apply(lambda x: x.split("/")[-1])
/var/folders/24/kj6qhrn550xbr18__b59pv440000gn/T/ipykernel_9766/2728872958.py:7: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
nfx['month_added'] = nfx['date_added'].apply(lambda x: x.split("/")[0])
show_id | type | title | director | country | date_added | release_year | rating | duration | listed_in | target_ages | year_added | month_added | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
8785 | s8797 | TV Show | Yunus Emre | Not Given | Turkey | 1/17/2017 | 2016 | TV-PG | 2 Seasons | International TV Shows, TV Dramas | Older Kids | 2017 | 1 |
8786 | s8798 | TV Show | Zak Storm | Not Given | United States | 9/13/2018 | 2016 | TV-Y7 | 3 Seasons | Kids' TV | Older Kids | 2018 | 9 |
8787 | s8801 | TV Show | Zindagi Gulzar Hai | Not Given | Pakistan | 12/15/2016 | 2012 | TV-PG | 1 Season | International TV Shows, Romantic TV Shows, TV ... | Older Kids | 2016 | 12 |
8788 | s8784 | TV Show | Yoko | Not Given | Pakistan | 6/23/2018 | 2016 | TV-Y | 1 Season | Kids' TV | Kids | 2018 | 6 |
8789 | s8786 | TV Show | YOM | Not Given | Pakistan | 6/7/2018 | 2016 | TV-Y7 | 1 Season | Kids' TV | Older Kids | 2018 | 6 |
데이터 type 변환¶
nfx.dtypes
show_id object
type object
title object
director object
country object
date_added object
release_year int64
rating object
duration object
listed_in object
target_ages object
year_added object
month_added object
dtype: object
#비교를 하기 위해 type을 변환
nfx['type']=pd.Categorical(nfx['type']) #type은 카테고리형으로 변환
nfx['year_added']=pd.to_numeric(nfx['year_added']) #날짜 데이터는 정수형으로 변환하기
nfx['month_added']=pd.to_numeric(nfx['month_added']) #날짜 데이터는 정수형으로 변환하기
/var/folders/24/kj6qhrn550xbr18__b59pv440000gn/T/ipykernel_9766/497470474.py:2: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
nfx['type']=pd.Categorical(nfx['type']) #type은 카테고리형으로 변환
/var/folders/24/kj6qhrn550xbr18__b59pv440000gn/T/ipykernel_9766/497470474.py:3: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
nfx['year_added']=pd.to_numeric(nfx['year_added']) #날짜 데이터는 정수형으로 변환하기
/var/folders/24/kj6qhrn550xbr18__b59pv440000gn/T/ipykernel_9766/497470474.py:4: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
nfx['month_added']=pd.to_numeric(nfx['month_added']) #날짜 데이터는 정수형으로 변환하기
nfx.dtypes
show_id object
type category
title object
director object
country object
date_added object
release_year int64
rating object
duration object
listed_in object
target_ages object
year_added int64
month_added int64
dtype: object
one-hot encoding¶
-범주형 데이터인 type 혹은 target_ages를 원핫 인코딩 실시
1)type은 movie와 tv show로 원핫 인코딩이 가능
2)target_ages는 adults / kids / older kids / teens로 원핫 인코딩이 가능
type_dummy=pd.get_dummies(nfx[['type']])
type_dummy.head(10)
type_Movie | type_TV Show | |
---|---|---|
0 | 1 | 0 |
1 | 0 | 1 |
2 | 0 | 1 |
3 | 1 | 0 |
4 | 1 | 0 |
5 | 0 | 1 |
6 | 1 | 0 |
7 | 1 | 0 |
8 | 1 | 0 |
9 | 1 | 0 |
target_ages_dummy=pd.get_dummies(nfx[['target_ages']])
target_ages_dummy.head(10)
target_ages_Adults | target_ages_Kids | target_ages_Older Kids | target_ages_Teens | |
---|---|---|---|---|
0 | 0 | 0 | 0 | 1 |
1 | 1 | 0 | 0 | 0 |
2 | 1 | 0 | 0 | 0 |
3 | 0 | 0 | 1 | 0 |
4 | 1 | 0 | 0 | 0 |
5 | 0 | 0 | 0 | 1 |
6 | 0 | 0 | 0 | 1 |
7 | 0 | 0 | 1 | 0 |
8 | 1 | 0 | 0 | 0 |
9 | 0 | 0 | 1 | 0 |
concat_data=pd.concat([nfx,target_ages_dummy],axis=1)
concat_data #원핫인코딩한 데이터 결과와 nfx기존 데이터 합치기
show_id | type | title | director | country | date_added | release_year | rating | duration | listed_in | target_ages | year_added | month_added | target_ages_Adults | target_ages_Kids | target_ages_Older Kids | target_ages_Teens | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | s1 | Movie | Dick Johnson Is Dead | Kirsten Johnson | United States | 9/25/2021 | 2020 | PG-13 | 90 min | Documentaries | Teens | 2021 | 9 | 0 | 0 | 0 | 1 |
1 | s3 | TV Show | Ganglands | Julien Leclercq | France | 9/24/2021 | 2021 | TV-MA | 1 Season | Crime TV Shows, International TV Shows, TV Act... | Adults | 2021 | 9 | 1 | 0 | 0 | 0 |
2 | s6 | TV Show | Midnight Mass | Mike Flanagan | United States | 9/24/2021 | 2021 | TV-MA | 1 Season | TV Dramas, TV Horror, TV Mysteries | Adults | 2021 | 9 | 1 | 0 | 0 | 0 |
3 | s14 | Movie | Confessions of an Invisible Girl | Bruno Garotti | Brazil | 9/22/2021 | 2021 | TV-PG | 91 min | Children & Family Movies, Comedies | Older Kids | 2021 | 9 | 0 | 0 | 1 | 0 |
4 | s8 | Movie | Sankofa | Haile Gerima | United States | 9/24/2021 | 1993 | TV-MA | 125 min | Dramas, Independent Movies, International Movies | Adults | 2021 | 9 | 1 | 0 | 0 | 0 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
8785 | s8797 | TV Show | Yunus Emre | Not Given | Turkey | 1/17/2017 | 2016 | TV-PG | 2 Seasons | International TV Shows, TV Dramas | Older Kids | 2017 | 1 | 0 | 0 | 1 | 0 |
8786 | s8798 | TV Show | Zak Storm | Not Given | United States | 9/13/2018 | 2016 | TV-Y7 | 3 Seasons | Kids' TV | Older Kids | 2018 | 9 | 0 | 0 | 1 | 0 |
8787 | s8801 | TV Show | Zindagi Gulzar Hai | Not Given | Pakistan | 12/15/2016 | 2012 | TV-PG | 1 Season | International TV Shows, Romantic TV Shows, TV ... | Older Kids | 2016 | 12 | 0 | 0 | 1 | 0 |
8788 | s8784 | TV Show | Yoko | Not Given | Pakistan | 6/23/2018 | 2016 | TV-Y | 1 Season | Kids' TV | Kids | 2018 | 6 | 0 | 1 | 0 | 0 |
8789 | s8786 | TV Show | YOM | Not Given | Pakistan | 6/7/2018 | 2016 | TV-Y7 | 1 Season | Kids' TV | Older Kids | 2018 | 6 | 0 | 0 | 1 | 0 |
8787 rows × 17 columns
'공모전 & 프로젝트' 카테고리의 다른 글
월마트 데이터 분석(평가 : ridge, lasso, elastic net) (0) | 2023.12.16 |
---|---|
오징어 게임 파이썬 구현 (0) | 2023.12.16 |
마케팅 공모전 수상 후기 (1) | 2023.11.23 |
[프로젝트]시간에 따른 이혼율 추세와 이혼 사유 데이터 분석 (0) | 2023.11.12 |
[프로젝트]넷플릭스 데이터 분석2(시각화) (0) | 2023.11.12 |