문제 접근 (Mandatory Part)¶
- 일단 데이터 열어서
- country column에서 South Korea의 개수를 세면 되겠네
문제 접근 (Bonus Part)¶
- 일단 데이터를 열어서 안에 뭐가 들었는지 보고
- 질문이 원하는 바가 뭔지 -> 단일국가를 기준으로 가장 많은 작품을 올린 나라, 작품 개수
- 나라별로 정렬한 뒤,
- 나라별로 add하면 되겠네
In [2]:
import pandas as pd
In [21]:
netflix = pd.read_csv("./netflix_titles.csv")
netflix
Out[21]:
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... |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
8802 | s8803 | Movie | Zodiac | David Fincher | Mark Ruffalo, Jake Gyllenhaal, Robert Downey J... | United States | November 20, 2019 | 2007 | R | 158 min | Cult Movies, Dramas, Thrillers | A political cartoonist, a crime reporter and a... |
8803 | s8804 | TV Show | Zombie Dumb | NaN | NaN | NaN | July 1, 2019 | 2018 | TV-Y7 | 2 Seasons | Kids' TV, Korean TV Shows, TV Comedies | While living alone in a spooky town, a young g... |
8804 | s8805 | Movie | Zombieland | Ruben Fleischer | Jesse Eisenberg, Woody Harrelson, Emma Stone, ... | United States | November 1, 2019 | 2009 | R | 88 min | Comedies, Horror Movies | Looking to survive in a world taken over by zo... |
8805 | s8806 | Movie | Zoom | Peter Hewitt | Tim Allen, Courteney Cox, Chevy Chase, Kate Ma... | United States | January 11, 2020 | 2006 | PG | 88 min | Children & Family Movies, Comedies | Dragged from civilian life, a former superhero... |
8806 | s8807 | Movie | Zubaan | Mozez Singh | Vicky Kaushal, Sarah-Jane Dias, Raaghav Chanan... | India | March 2, 2019 | 2015 | TV-14 | 111 min | Dramas, International Movies, Music & Musicals | A scrappy but poor boy worms his way into a ty... |
8807 rows × 12 columns
Mandatory Part 풀이¶
In [107]:
netflix_kor = netflix[netflix['country'] == 'South Korea']
netflix_kor
Out[107]:
show_id | type | title | director | cast | country | date_added | release_year | rating | duration | listed_in | description | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
104 | s105 | TV Show | Tayo the Little Bus | NaN | Robyn Slade, Kami Desilets | South Korea | September 6, 2021 | 2016 | TV-Y | 2 Seasons | Kids' TV, Korean TV Shows | As they learn their routes around the busy cit... |
124 | s125 | TV Show | Pororo - The Little Penguin | NaN | NaN | South Korea | September 2, 2021 | 2013 | TV-Y7 | 3 Seasons | Kids' TV, Korean TV Shows | On a tiny island, Pororo the penguin has fun a... |
289 | s290 | TV Show | The Crowned Clown | NaN | Yeo Jin-goo, Lee Se-young, Kim Sang-kyung, Jun... | South Korea | August 10, 2021 | 2019 | TV-14 | 1 Season | International TV Shows, Romantic TV Shows, TV ... | Standing in for an unhinged Joseon king, a loo... |
456 | s457 | TV Show | Her Private Life | NaN | Park Min-young, Kim Jae-uk, Ahn Bo-hyun, Jung ... | South Korea | July 15, 2021 | 2019 | TV-14 | 1 Season | International TV Shows, Romantic TV Shows, TV ... | An art curator's life unravels, as she tries t... |
545 | s546 | TV Show | YooHoo to the Rescue | NaN | Kira Buckland, Ryan Bartley, Bryce Papenbrook,... | South Korea | July 6, 2021 | 2020 | TV-Y | 3 Seasons | Kids' TV, Korean TV Shows | In a series of magical missions, quick-witted ... |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
8463 | s8464 | Movie | The President's Barber | Chan-sang Lim | Kang-ho Song, So-ri Moon, Jae-eung Lee, Yeong-... | South Korea | October 1, 2017 | 2004 | TV-MA | 116 min | Comedies, Dramas, International Movies | The personal barber to the president, as well ... |
8467 | s8468 | Movie | The Prison | Na Hyeon | Suk-kyu Han, Rae-won Kim, Kyeong-yeong Lee, Wo... | South Korea | November 18, 2017 | 2017 | TV-MA | 125 min | Action & Adventure, Dramas, International Movies | A cop-turned-convict discovers a crime syndica... |
8575 | s8576 | TV Show | This Is My Love | NaN | Jin-mo Joo, Sa-rang Kim, Junior, Ja-in Lee, Su... | South Korea | May 22, 2017 | 2015 | TV-14 | 1 Season | International TV Shows, Korean TV Shows, Roman... | A renowned actor who is still pining over the ... |
8613 | s8614 | Movie | Train to Busan | Sang-ho Yeon | Gong Yoo, Yu-mi Jung, Dong-seok Ma, Soo-an Kim... | South Korea | March 18, 2017 | 2016 | TV-MA | 118 min | Action & Adventure, Horror Movies, Internation... | As a zombie outbreak sweeps the country, a dad... |
8684 | s8685 | TV Show | Vroomiz | NaN | Joon-seok Song, Jeong-hwa Yang, Sang-hyun Um, ... | South Korea | August 1, 2017 | 2016 | TV-Y | 3 Seasons | Kids' TV, Korean TV Shows | For these half-car, half-animal friends, each ... |
199 rows × 12 columns
In [90]:
netflix_kor['show_id'].count()
Out[90]:
199
netflix_kor을 출력했을 때, 나온 199 row로도 알 수 있었지만 199개이다.
Bonus Part 풀이¶
In [60]:
netflix_country = netflix.groupby('country')
netflix_country.size()
Out[60]:
country
, France, Algeria 1
, South Korea 1
Argentina 56
Argentina, Brazil, France, Poland, Germany, Denmark 1
Argentina, Chile 2
..
Venezuela 1
Venezuela, Colombia 1
Vietnam 7
West Germany 1
Zimbabwe 1
Length: 748, dtype: int64
value_counts() 함수 (문제 풀 때 제일 도움 많이 됨)¶
- 각 column의 내용의 갯수를 세어준다
In [75]:
netflix_count = netflix['country'].value_counts()
netflix_count
Out[75]:
United States 2818
India 972
United Kingdom 419
Japan 245
South Korea 199
...
Romania, Bulgaria, Hungary 1
Uruguay, Guatemala 1
France, Senegal, Belgium 1
Mexico, United States, Spain, Colombia 1
United Arab Emirates, Jordan 1
Name: country, Length: 748, dtype: int64
In [83]:
net_type = netflix['type'].value_counts()
net_type
Out[83]:
Movie 6131
TV Show 2676
Name: type, dtype: int64
sort_values()¶
- sort_values() 함수를 이용하면 자료를 오름차순 또는 내림차순으로 정리할 수 있다
- 기본적으로 오름차순 정렬이 되어있는데, ascending = False를 하게되면 내림차순 정렬이 가능하다
In [81]:
netflix_count.sort_values()
Out[81]:
Germany, Canada, United States 1
United States, France, Serbia 1
France, Norway, Lebanon, Belgium 1
Sweden, Czech Republic, United Kingdom, Denmark, Netherlands 1
United States, United Kingdom, India 1
...
South Korea 199
Japan 245
United Kingdom 419
India 972
United States 2818
Name: country, Length: 748, dtype: int64
In [80]:
netflix_count.sort_values(ascending = False)
Out[80]:
United States 2818
India 972
United Kingdom 419
Japan 245
South Korea 199
...
Ireland, United Kingdom, Greece, France, Netherlands 1
France, Canada, Italy, United States, China 1
United States, Venezuela 1
United Kingdom, Canada, Japan 1
United Arab Emirates, Jordan 1
Name: country, Length: 748, dtype: int64
count() 와 size의 차이¶
count는 일단 count()로 쓰임 / size는 괄호 없이쓰임 count는 NAN을 세지않고, size는 NAN을 셈
In [57]:
netflix['country'].count()
Out[57]:
7976
In [59]:
netflix['country'].size
Out[59]:
8807
netflix 는 pandas에서 read_csv()함수를 이용해서 만든 DataFrame 객체
netflix_country 는 netfilx를 어떠한 기준(이번엔 country겠지)으로 모은 groupby 객체
오늘 한 실수¶
- netf'li'x 를 netf'il'x 라고 입력하고, pd.read_csv('./netfilx_titles.csv')라고 해서 오픈이 안돼서 열받았음
- groupby()를 까먹었음
오늘 배운 점¶
- 오타 조심!!!!
- groupby()함수 다시 복습..
- groupby한 애들의 각 사이즈를 알고싶으면
<groupby객체 이름>.size()
이용 - groupby를 따로 하지 않아도,
<데이터프레임 객체>['열 이름'].count_values()
이용하면 셀 수 있음 - 참고 https://m.blog.naver.com/PostView.naver?isHttpsRedirect=true&blogId=ji0eeeee&logNo=221533201982
추가로 알고싶은 점¶
In [117]:
netflix_USkr = netflix[(netflix['country'] == 'South Korea') | (netflix['country'] == 'US')]
netflix_USkr
Out[117]:
show_id | type | title | director | cast | country | date_added | release_year | rating | duration | listed_in | description | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
104 | s105 | TV Show | Tayo the Little Bus | NaN | Robyn Slade, Kami Desilets | South Korea | September 6, 2021 | 2016 | TV-Y | 2 Seasons | Kids' TV, Korean TV Shows | As they learn their routes around the busy cit... |
124 | s125 | TV Show | Pororo - The Little Penguin | NaN | NaN | South Korea | September 2, 2021 | 2013 | TV-Y7 | 3 Seasons | Kids' TV, Korean TV Shows | On a tiny island, Pororo the penguin has fun a... |
289 | s290 | TV Show | The Crowned Clown | NaN | Yeo Jin-goo, Lee Se-young, Kim Sang-kyung, Jun... | South Korea | August 10, 2021 | 2019 | TV-14 | 1 Season | International TV Shows, Romantic TV Shows, TV ... | Standing in for an unhinged Joseon king, a loo... |
456 | s457 | TV Show | Her Private Life | NaN | Park Min-young, Kim Jae-uk, Ahn Bo-hyun, Jung ... | South Korea | July 15, 2021 | 2019 | TV-14 | 1 Season | International TV Shows, Romantic TV Shows, TV ... | An art curator's life unravels, as she tries t... |
545 | s546 | TV Show | YooHoo to the Rescue | NaN | Kira Buckland, Ryan Bartley, Bryce Papenbrook,... | South Korea | July 6, 2021 | 2020 | TV-Y | 3 Seasons | Kids' TV, Korean TV Shows | In a series of magical missions, quick-witted ... |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
8463 | s8464 | Movie | The President's Barber | Chan-sang Lim | Kang-ho Song, So-ri Moon, Jae-eung Lee, Yeong-... | South Korea | October 1, 2017 | 2004 | TV-MA | 116 min | Comedies, Dramas, International Movies | The personal barber to the president, as well ... |
8467 | s8468 | Movie | The Prison | Na Hyeon | Suk-kyu Han, Rae-won Kim, Kyeong-yeong Lee, Wo... | South Korea | November 18, 2017 | 2017 | TV-MA | 125 min | Action & Adventure, Dramas, International Movies | A cop-turned-convict discovers a crime syndica... |
8575 | s8576 | TV Show | This Is My Love | NaN | Jin-mo Joo, Sa-rang Kim, Junior, Ja-in Lee, Su... | South Korea | May 22, 2017 | 2015 | TV-14 | 1 Season | International TV Shows, Korean TV Shows, Roman... | A renowned actor who is still pining over the ... |
8613 | s8614 | Movie | Train to Busan | Sang-ho Yeon | Gong Yoo, Yu-mi Jung, Dong-seok Ma, Soo-an Kim... | South Korea | March 18, 2017 | 2016 | TV-MA | 118 min | Action & Adventure, Horror Movies, Internation... | As a zombie outbreak sweeps the country, a dad... |
8684 | s8685 | TV Show | Vroomiz | NaN | Joon-seok Song, Jeong-hwa Yang, Sang-hyun Um, ... | South Korea | August 1, 2017 | 2016 | TV-Y | 3 Seasons | Kids' TV, Korean TV Shows | For these half-car, half-animal friends, each ... |
199 rows × 12 columns
In [ ]:
여기서 또는 연산을 하려고 하는데 한국만 나오는데 어떻게 해야할까?
'TIL > [겨울방학 부트캠프]TIL' 카테고리의 다른 글
TIL 6일차 (22.01.10) (0) | 2022.01.10 |
---|---|
TIL 5일차 (22.01.07) (0) | 2022.01.07 |
TIL 3일차 (22.01.05) (0) | 2022.01.05 |
TIL 2일차(22.01.04) (0) | 2022.01.04 |
TIL 1일차(22.01.03) (0) | 2022.01.04 |