diff --git a/notebooks/[Pandas_Apply_Lambdas] Silvia Martinez.ipynb b/notebooks/[Pandas_Apply_Lambdas] Silvia Martinez.ipynb new file mode 100644 index 0000000..ad53c33 --- /dev/null +++ b/notebooks/[Pandas_Apply_Lambdas] Silvia Martinez.ipynb @@ -0,0 +1,4659 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "280006e6", + "metadata": {}, + "source": [ + "### Pandas Apply Lambda\n", + "\n", + "Always remember the Zen of Python!!!" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "d3c3dd76", + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "import numpy as np" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "2c578f42", + "metadata": {}, + "outputs": [], + "source": [ + "df = pd.read_csv(\"../data/input/IMDB-Movie-Data.csv\")" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "6504b944", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
RankTitleGenreDescriptionDirectorActorsYearRuntime (Minutes)RatingVotesRevenue (Millions)Metascore
01Guardians of the GalaxyAction,Adventure,Sci-FiA group of intergalactic criminals are forced ...James GunnChris Pratt, Vin Diesel, Bradley Cooper, Zoe S...20141218.1757074333.1376.0
12PrometheusAdventure,Mystery,Sci-FiFollowing clues to the origin of mankind, a te...Ridley ScottNoomi Rapace, Logan Marshall-Green, Michael Fa...20121247.0485820126.4665.0
23SplitHorror,ThrillerThree girls are kidnapped by a man with a diag...M. Night ShyamalanJames McAvoy, Anya Taylor-Joy, Haley Lu Richar...20161177.3157606138.1262.0
34SingAnimation,Comedy,FamilyIn a city of humanoid animals, a hustling thea...Christophe LourdeletMatthew McConaughey,Reese Witherspoon, Seth Ma...20161087.260545270.3259.0
45Suicide SquadAction,Adventure,FantasyA secret government agency recruits some of th...David AyerWill Smith, Jared Leto, Margot Robbie, Viola D...20161236.2393727325.0240.0
56The Great WallAction,Adventure,FantasyEuropean mercenaries searching for black powde...Yimou ZhangMatt Damon, Tian Jing, Willem Dafoe, Andy Lau20161036.15603645.1342.0
67La La LandComedy,Drama,MusicA jazz pianist falls for an aspiring actress i...Damien ChazelleRyan Gosling, Emma Stone, Rosemarie DeWitt, J....20161288.3258682151.0693.0
78MindhornComedyA has-been actor best known for playing the ti...Sean FoleyEssie Davis, Andrea Riseborough, Julian Barrat...2016896.42490NaN71.0
89The Lost City of ZAction,Adventure,BiographyA true-life drama, centering on British explor...James GrayCharlie Hunnam, Robert Pattinson, Sienna Mille...20161417.171888.0178.0
910PassengersAdventure,Drama,RomanceA spacecraft traveling to a distant colony pla...Morten TyldumJennifer Lawrence, Chris Pratt, Michael Sheen,...20161167.0192177100.0141.0
\n", + "
" + ], + "text/plain": [ + " Rank Title Genre \\\n", + "0 1 Guardians of the Galaxy Action,Adventure,Sci-Fi \n", + "1 2 Prometheus Adventure,Mystery,Sci-Fi \n", + "2 3 Split Horror,Thriller \n", + "3 4 Sing Animation,Comedy,Family \n", + "4 5 Suicide Squad Action,Adventure,Fantasy \n", + "5 6 The Great Wall Action,Adventure,Fantasy \n", + "6 7 La La Land Comedy,Drama,Music \n", + "7 8 Mindhorn Comedy \n", + "8 9 The Lost City of Z Action,Adventure,Biography \n", + "9 10 Passengers Adventure,Drama,Romance \n", + "\n", + " Description Director \\\n", + "0 A group of intergalactic criminals are forced ... James Gunn \n", + "1 Following clues to the origin of mankind, a te... Ridley Scott \n", + "2 Three girls are kidnapped by a man with a diag... M. Night Shyamalan \n", + "3 In a city of humanoid animals, a hustling thea... Christophe Lourdelet \n", + "4 A secret government agency recruits some of th... David Ayer \n", + "5 European mercenaries searching for black powde... Yimou Zhang \n", + "6 A jazz pianist falls for an aspiring actress i... Damien Chazelle \n", + "7 A has-been actor best known for playing the ti... Sean Foley \n", + "8 A true-life drama, centering on British explor... James Gray \n", + "9 A spacecraft traveling to a distant colony pla... Morten Tyldum \n", + "\n", + " Actors Year Runtime (Minutes) \\\n", + "0 Chris Pratt, Vin Diesel, Bradley Cooper, Zoe S... 2014 121 \n", + "1 Noomi Rapace, Logan Marshall-Green, Michael Fa... 2012 124 \n", + "2 James McAvoy, Anya Taylor-Joy, Haley Lu Richar... 2016 117 \n", + "3 Matthew McConaughey,Reese Witherspoon, Seth Ma... 2016 108 \n", + "4 Will Smith, Jared Leto, Margot Robbie, Viola D... 2016 123 \n", + "5 Matt Damon, Tian Jing, Willem Dafoe, Andy Lau 2016 103 \n", + "6 Ryan Gosling, Emma Stone, Rosemarie DeWitt, J.... 2016 128 \n", + "7 Essie Davis, Andrea Riseborough, Julian Barrat... 2016 89 \n", + "8 Charlie Hunnam, Robert Pattinson, Sienna Mille... 2016 141 \n", + "9 Jennifer Lawrence, Chris Pratt, Michael Sheen,... 2016 116 \n", + "\n", + " Rating Votes Revenue (Millions) Metascore \n", + "0 8.1 757074 333.13 76.0 \n", + "1 7.0 485820 126.46 65.0 \n", + "2 7.3 157606 138.12 62.0 \n", + "3 7.2 60545 270.32 59.0 \n", + "4 6.2 393727 325.02 40.0 \n", + "5 6.1 56036 45.13 42.0 \n", + "6 8.3 258682 151.06 93.0 \n", + "7 6.4 2490 NaN 71.0 \n", + "8 7.1 7188 8.01 78.0 \n", + "9 7.0 192177 100.01 41.0 " + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.head(10)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "bf6b244f", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "RangeIndex: 1000 entries, 0 to 999\n", + "Data columns (total 12 columns):\n", + " # Column Non-Null Count Dtype \n", + "--- ------ -------------- ----- \n", + " 0 Rank 1000 non-null int64 \n", + " 1 Title 1000 non-null object \n", + " 2 Genre 1000 non-null object \n", + " 3 Description 1000 non-null object \n", + " 4 Director 1000 non-null object \n", + " 5 Actors 1000 non-null object \n", + " 6 Year 1000 non-null int64 \n", + " 7 Runtime (Minutes) 1000 non-null int64 \n", + " 8 Rating 1000 non-null float64\n", + " 9 Votes 1000 non-null int64 \n", + " 10 Revenue (Millions) 872 non-null float64\n", + " 11 Metascore 936 non-null float64\n", + "dtypes: float64(3), int64(4), object(5)\n", + "memory usage: 93.9+ KB\n" + ] + } + ], + "source": [ + "df.info()" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "9c77ffb1", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
RankYearRuntime (Minutes)RatingVotesRevenue (Millions)Metascore
count1000.0000001000.0000001000.0000001000.0000001.000000e+03872.000000936.000000
mean500.5000002012.783000113.1720006.7232001.698083e+0582.95637658.985043
std288.8194363.20596218.8109080.9454291.887626e+05103.25354017.194757
min1.0000002006.00000066.0000001.9000006.100000e+010.00000011.000000
25%250.7500002010.000000100.0000006.2000003.630900e+0413.27000047.000000
50%500.5000002014.000000111.0000006.8000001.107990e+0547.98500059.500000
75%750.2500002016.000000123.0000007.4000002.399098e+05113.71500072.000000
max1000.0000002016.000000191.0000009.0000001.791916e+06936.630000100.000000
\n", + "
" + ], + "text/plain": [ + " Rank Year Runtime (Minutes) Rating Votes \\\n", + "count 1000.000000 1000.000000 1000.000000 1000.000000 1.000000e+03 \n", + "mean 500.500000 2012.783000 113.172000 6.723200 1.698083e+05 \n", + "std 288.819436 3.205962 18.810908 0.945429 1.887626e+05 \n", + "min 1.000000 2006.000000 66.000000 1.900000 6.100000e+01 \n", + "25% 250.750000 2010.000000 100.000000 6.200000 3.630900e+04 \n", + "50% 500.500000 2014.000000 111.000000 6.800000 1.107990e+05 \n", + "75% 750.250000 2016.000000 123.000000 7.400000 2.399098e+05 \n", + "max 1000.000000 2016.000000 191.000000 9.000000 1.791916e+06 \n", + "\n", + " Revenue (Millions) Metascore \n", + "count 872.000000 936.000000 \n", + "mean 82.956376 58.985043 \n", + "std 103.253540 17.194757 \n", + "min 0.000000 11.000000 \n", + "25% 13.270000 47.000000 \n", + "50% 47.985000 59.500000 \n", + "75% 113.715000 72.000000 \n", + "max 936.630000 100.000000 " + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.describe()" + ] + }, + { + "cell_type": "markdown", + "id": "d5d05749", + "metadata": {}, + "source": [ + "## Challenge 1. Using a single argument" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "0e329800", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'cat_2'" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def bins(votes):\n", + " if votes >= 0 and votes <= 999:\n", + " return \"cat_1\"\n", + " elif votes >= 1000 and votes <= 9999:\n", + " return \"cat_2\"\n", + " elif votes >= 10000 and votes <= 99999:\n", + " return \"cat_3\"\n", + " elif votes >= 100000 and votes <= 999999:\n", + " return \"cat_4\"\n", + " elif votes >= 1000000:\n", + " return \"cat_5\"\n", + " \n", + "bins(1000)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "35fc08c9", + "metadata": {}, + "outputs": [], + "source": [ + "df[\"Bin\"] = df.apply(lambda x: bins(x[\"Votes\"]), axis = 1)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "af83288a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
RankTitleGenreDescriptionDirectorActorsYearRuntime (Minutes)RatingVotesRevenue (Millions)MetascoreBin
01Guardians of the GalaxyAction,Adventure,Sci-FiA group of intergalactic criminals are forced ...James GunnChris Pratt, Vin Diesel, Bradley Cooper, Zoe S...20141218.1757074333.1376.0cat_4
12PrometheusAdventure,Mystery,Sci-FiFollowing clues to the origin of mankind, a te...Ridley ScottNoomi Rapace, Logan Marshall-Green, Michael Fa...20121247.0485820126.4665.0cat_4
23SplitHorror,ThrillerThree girls are kidnapped by a man with a diag...M. Night ShyamalanJames McAvoy, Anya Taylor-Joy, Haley Lu Richar...20161177.3157606138.1262.0cat_4
34SingAnimation,Comedy,FamilyIn a city of humanoid animals, a hustling thea...Christophe LourdeletMatthew McConaughey,Reese Witherspoon, Seth Ma...20161087.260545270.3259.0cat_3
45Suicide SquadAction,Adventure,FantasyA secret government agency recruits some of th...David AyerWill Smith, Jared Leto, Margot Robbie, Viola D...20161236.2393727325.0240.0cat_4
..........................................
995996Secret in Their EyesCrime,Drama,MysteryA tight-knit team of rising investigators, alo...Billy RayChiwetel Ejiofor, Nicole Kidman, Julia Roberts...20151116.227585NaN45.0cat_3
996997Hostel: Part IIHorrorThree American college students studying abroa...Eli RothLauren German, Heather Matarazzo, Bijou Philli...2007945.57315217.5446.0cat_3
997998Step Up 2: The StreetsDrama,Music,RomanceRomantic sparks occur between two dance studen...Jon M. ChuRobert Hoffman, Briana Evigan, Cassie Ventura,...2008986.27069958.0150.0cat_3
998999Search PartyAdventure,ComedyA pair of friends embark on a mission to reuni...Scot ArmstrongAdam Pally, T.J. Miller, Thomas Middleditch,Sh...2014935.64881NaN22.0cat_2
9991000Nine LivesComedy,Family,FantasyA stuffy businessman finds himself trapped ins...Barry SonnenfeldKevin Spacey, Jennifer Garner, Robbie Amell,Ch...2016875.31243519.6411.0cat_3
\n", + "

1000 rows × 13 columns

\n", + "
" + ], + "text/plain": [ + " Rank Title Genre \\\n", + "0 1 Guardians of the Galaxy Action,Adventure,Sci-Fi \n", + "1 2 Prometheus Adventure,Mystery,Sci-Fi \n", + "2 3 Split Horror,Thriller \n", + "3 4 Sing Animation,Comedy,Family \n", + "4 5 Suicide Squad Action,Adventure,Fantasy \n", + ".. ... ... ... \n", + "995 996 Secret in Their Eyes Crime,Drama,Mystery \n", + "996 997 Hostel: Part II Horror \n", + "997 998 Step Up 2: The Streets Drama,Music,Romance \n", + "998 999 Search Party Adventure,Comedy \n", + "999 1000 Nine Lives Comedy,Family,Fantasy \n", + "\n", + " Description Director \\\n", + "0 A group of intergalactic criminals are forced ... James Gunn \n", + "1 Following clues to the origin of mankind, a te... Ridley Scott \n", + "2 Three girls are kidnapped by a man with a diag... M. Night Shyamalan \n", + "3 In a city of humanoid animals, a hustling thea... Christophe Lourdelet \n", + "4 A secret government agency recruits some of th... David Ayer \n", + ".. ... ... \n", + "995 A tight-knit team of rising investigators, alo... Billy Ray \n", + "996 Three American college students studying abroa... Eli Roth \n", + "997 Romantic sparks occur between two dance studen... Jon M. Chu \n", + "998 A pair of friends embark on a mission to reuni... Scot Armstrong \n", + "999 A stuffy businessman finds himself trapped ins... Barry Sonnenfeld \n", + "\n", + " Actors Year \\\n", + "0 Chris Pratt, Vin Diesel, Bradley Cooper, Zoe S... 2014 \n", + "1 Noomi Rapace, Logan Marshall-Green, Michael Fa... 2012 \n", + "2 James McAvoy, Anya Taylor-Joy, Haley Lu Richar... 2016 \n", + "3 Matthew McConaughey,Reese Witherspoon, Seth Ma... 2016 \n", + "4 Will Smith, Jared Leto, Margot Robbie, Viola D... 2016 \n", + ".. ... ... \n", + "995 Chiwetel Ejiofor, Nicole Kidman, Julia Roberts... 2015 \n", + "996 Lauren German, Heather Matarazzo, Bijou Philli... 2007 \n", + "997 Robert Hoffman, Briana Evigan, Cassie Ventura,... 2008 \n", + "998 Adam Pally, T.J. Miller, Thomas Middleditch,Sh... 2014 \n", + "999 Kevin Spacey, Jennifer Garner, Robbie Amell,Ch... 2016 \n", + "\n", + " Runtime (Minutes) Rating Votes Revenue (Millions) Metascore Bin \n", + "0 121 8.1 757074 333.13 76.0 cat_4 \n", + "1 124 7.0 485820 126.46 65.0 cat_4 \n", + "2 117 7.3 157606 138.12 62.0 cat_4 \n", + "3 108 7.2 60545 270.32 59.0 cat_3 \n", + "4 123 6.2 393727 325.02 40.0 cat_4 \n", + ".. ... ... ... ... ... ... \n", + "995 111 6.2 27585 NaN 45.0 cat_3 \n", + "996 94 5.5 73152 17.54 46.0 cat_3 \n", + "997 98 6.2 70699 58.01 50.0 cat_3 \n", + "998 93 5.6 4881 NaN 22.0 cat_2 \n", + "999 87 5.3 12435 19.64 11.0 cat_3 \n", + "\n", + "[1000 rows x 13 columns]" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df" + ] + }, + { + "cell_type": "markdown", + "id": "d75e12ce", + "metadata": {}, + "source": [ + "## Challenge 2. Using 2 arguments" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "4a2a6a6e", + "metadata": {}, + "outputs": [], + "source": [ + "def revenue_minute(revenue, minute):\n", + " return revenue / minute" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "e702cb7b", + "metadata": {}, + "outputs": [], + "source": [ + "df[\"Revenue per Minute\"] = df.apply(lambda x: revenue_minute(x[\"Revenue (Millions)\"], x[\"Runtime (Minutes)\"]), axis = 1)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "fffa468a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
RankTitleGenreDescriptionDirectorActorsYearRuntime (Minutes)RatingVotesRevenue (Millions)MetascoreBinRevenue per Minute
01Guardians of the GalaxyAction,Adventure,Sci-FiA group of intergalactic criminals are forced ...James GunnChris Pratt, Vin Diesel, Bradley Cooper, Zoe S...20141218.1757074333.1376.0cat_42.753140
12PrometheusAdventure,Mystery,Sci-FiFollowing clues to the origin of mankind, a te...Ridley ScottNoomi Rapace, Logan Marshall-Green, Michael Fa...20121247.0485820126.4665.0cat_41.019839
23SplitHorror,ThrillerThree girls are kidnapped by a man with a diag...M. Night ShyamalanJames McAvoy, Anya Taylor-Joy, Haley Lu Richar...20161177.3157606138.1262.0cat_41.180513
34SingAnimation,Comedy,FamilyIn a city of humanoid animals, a hustling thea...Christophe LourdeletMatthew McConaughey,Reese Witherspoon, Seth Ma...20161087.260545270.3259.0cat_32.502963
45Suicide SquadAction,Adventure,FantasyA secret government agency recruits some of th...David AyerWill Smith, Jared Leto, Margot Robbie, Viola D...20161236.2393727325.0240.0cat_42.642439
.............................................
995996Secret in Their EyesCrime,Drama,MysteryA tight-knit team of rising investigators, alo...Billy RayChiwetel Ejiofor, Nicole Kidman, Julia Roberts...20151116.227585NaN45.0cat_3NaN
996997Hostel: Part IIHorrorThree American college students studying abroa...Eli RothLauren German, Heather Matarazzo, Bijou Philli...2007945.57315217.5446.0cat_30.186596
997998Step Up 2: The StreetsDrama,Music,RomanceRomantic sparks occur between two dance studen...Jon M. ChuRobert Hoffman, Briana Evigan, Cassie Ventura,...2008986.27069958.0150.0cat_30.591939
998999Search PartyAdventure,ComedyA pair of friends embark on a mission to reuni...Scot ArmstrongAdam Pally, T.J. Miller, Thomas Middleditch,Sh...2014935.64881NaN22.0cat_2NaN
9991000Nine LivesComedy,Family,FantasyA stuffy businessman finds himself trapped ins...Barry SonnenfeldKevin Spacey, Jennifer Garner, Robbie Amell,Ch...2016875.31243519.6411.0cat_30.225747
\n", + "

1000 rows × 14 columns

\n", + "
" + ], + "text/plain": [ + " Rank Title Genre \\\n", + "0 1 Guardians of the Galaxy Action,Adventure,Sci-Fi \n", + "1 2 Prometheus Adventure,Mystery,Sci-Fi \n", + "2 3 Split Horror,Thriller \n", + "3 4 Sing Animation,Comedy,Family \n", + "4 5 Suicide Squad Action,Adventure,Fantasy \n", + ".. ... ... ... \n", + "995 996 Secret in Their Eyes Crime,Drama,Mystery \n", + "996 997 Hostel: Part II Horror \n", + "997 998 Step Up 2: The Streets Drama,Music,Romance \n", + "998 999 Search Party Adventure,Comedy \n", + "999 1000 Nine Lives Comedy,Family,Fantasy \n", + "\n", + " Description Director \\\n", + "0 A group of intergalactic criminals are forced ... James Gunn \n", + "1 Following clues to the origin of mankind, a te... Ridley Scott \n", + "2 Three girls are kidnapped by a man with a diag... M. Night Shyamalan \n", + "3 In a city of humanoid animals, a hustling thea... Christophe Lourdelet \n", + "4 A secret government agency recruits some of th... David Ayer \n", + ".. ... ... \n", + "995 A tight-knit team of rising investigators, alo... Billy Ray \n", + "996 Three American college students studying abroa... Eli Roth \n", + "997 Romantic sparks occur between two dance studen... Jon M. Chu \n", + "998 A pair of friends embark on a mission to reuni... Scot Armstrong \n", + "999 A stuffy businessman finds himself trapped ins... Barry Sonnenfeld \n", + "\n", + " Actors Year \\\n", + "0 Chris Pratt, Vin Diesel, Bradley Cooper, Zoe S... 2014 \n", + "1 Noomi Rapace, Logan Marshall-Green, Michael Fa... 2012 \n", + "2 James McAvoy, Anya Taylor-Joy, Haley Lu Richar... 2016 \n", + "3 Matthew McConaughey,Reese Witherspoon, Seth Ma... 2016 \n", + "4 Will Smith, Jared Leto, Margot Robbie, Viola D... 2016 \n", + ".. ... ... \n", + "995 Chiwetel Ejiofor, Nicole Kidman, Julia Roberts... 2015 \n", + "996 Lauren German, Heather Matarazzo, Bijou Philli... 2007 \n", + "997 Robert Hoffman, Briana Evigan, Cassie Ventura,... 2008 \n", + "998 Adam Pally, T.J. Miller, Thomas Middleditch,Sh... 2014 \n", + "999 Kevin Spacey, Jennifer Garner, Robbie Amell,Ch... 2016 \n", + "\n", + " Runtime (Minutes) Rating Votes Revenue (Millions) Metascore Bin \\\n", + "0 121 8.1 757074 333.13 76.0 cat_4 \n", + "1 124 7.0 485820 126.46 65.0 cat_4 \n", + "2 117 7.3 157606 138.12 62.0 cat_4 \n", + "3 108 7.2 60545 270.32 59.0 cat_3 \n", + "4 123 6.2 393727 325.02 40.0 cat_4 \n", + ".. ... ... ... ... ... ... \n", + "995 111 6.2 27585 NaN 45.0 cat_3 \n", + "996 94 5.5 73152 17.54 46.0 cat_3 \n", + "997 98 6.2 70699 58.01 50.0 cat_3 \n", + "998 93 5.6 4881 NaN 22.0 cat_2 \n", + "999 87 5.3 12435 19.64 11.0 cat_3 \n", + "\n", + " Revenue per Minute \n", + "0 2.753140 \n", + "1 1.019839 \n", + "2 1.180513 \n", + "3 2.502963 \n", + "4 2.642439 \n", + ".. ... \n", + "995 NaN \n", + "996 0.186596 \n", + "997 0.591939 \n", + "998 NaN \n", + "999 0.225747 \n", + "\n", + "[1000 rows x 14 columns]" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df" + ] + }, + { + "cell_type": "markdown", + "id": "47c2531c", + "metadata": {}, + "source": [ + "## Challenge 3. A bit more complicated" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "47fe1029", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
RankTitleGenreDescriptionDirectorActorsYearRuntime (Minutes)RatingVotesRevenue (Millions)MetascoreBinRevenue per Minute
01Guardians of the GalaxyAction,Adventure,Sci-FiA group of intergalactic criminals are forced ...James GunnChris Pratt, Vin Diesel, Bradley Cooper, Zoe S...20141218.1757074333.1376.0cat_42.753140
12PrometheusAdventure,Mystery,Sci-FiFollowing clues to the origin of mankind, a te...Ridley ScottNoomi Rapace, Logan Marshall-Green, Michael Fa...20121247.0485820126.4665.0cat_41.019839
23SplitHorror,ThrillerThree girls are kidnapped by a man with a diag...M. Night ShyamalanJames McAvoy, Anya Taylor-Joy, Haley Lu Richar...20161177.3157606138.1262.0cat_41.180513
34SingAnimation,Comedy,FamilyIn a city of humanoid animals, a hustling thea...Christophe LourdeletMatthew McConaughey,Reese Witherspoon, Seth Ma...20161087.260545270.3259.0cat_32.502963
45Suicide SquadAction,Adventure,FantasyA secret government agency recruits some of th...David AyerWill Smith, Jared Leto, Margot Robbie, Viola D...20161236.2393727325.0240.0cat_42.642439
.............................................
995996Secret in Their EyesCrime,Drama,MysteryA tight-knit team of rising investigators, alo...Billy RayChiwetel Ejiofor, Nicole Kidman, Julia Roberts...20151116.227585NaN45.0cat_3NaN
996997Hostel: Part IIHorrorThree American college students studying abroa...Eli RothLauren German, Heather Matarazzo, Bijou Philli...2007945.57315217.5446.0cat_30.186596
997998Step Up 2: The StreetsDrama,Music,RomanceRomantic sparks occur between two dance studen...Jon M. ChuRobert Hoffman, Briana Evigan, Cassie Ventura,...2008986.27069958.0150.0cat_30.591939
998999Search PartyAdventure,ComedyA pair of friends embark on a mission to reuni...Scot ArmstrongAdam Pally, T.J. Miller, Thomas Middleditch,Sh...2014935.64881NaN22.0cat_2NaN
9991000Nine LivesComedy,Family,FantasyA stuffy businessman finds himself trapped ins...Barry SonnenfeldKevin Spacey, Jennifer Garner, Robbie Amell,Ch...2016875.31243519.6411.0cat_30.225747
\n", + "

1000 rows × 14 columns

\n", + "
" + ], + "text/plain": [ + " Rank Title Genre \\\n", + "0 1 Guardians of the Galaxy Action,Adventure,Sci-Fi \n", + "1 2 Prometheus Adventure,Mystery,Sci-Fi \n", + "2 3 Split Horror,Thriller \n", + "3 4 Sing Animation,Comedy,Family \n", + "4 5 Suicide Squad Action,Adventure,Fantasy \n", + ".. ... ... ... \n", + "995 996 Secret in Their Eyes Crime,Drama,Mystery \n", + "996 997 Hostel: Part II Horror \n", + "997 998 Step Up 2: The Streets Drama,Music,Romance \n", + "998 999 Search Party Adventure,Comedy \n", + "999 1000 Nine Lives Comedy,Family,Fantasy \n", + "\n", + " Description Director \\\n", + "0 A group of intergalactic criminals are forced ... James Gunn \n", + "1 Following clues to the origin of mankind, a te... Ridley Scott \n", + "2 Three girls are kidnapped by a man with a diag... M. Night Shyamalan \n", + "3 In a city of humanoid animals, a hustling thea... Christophe Lourdelet \n", + "4 A secret government agency recruits some of th... David Ayer \n", + ".. ... ... \n", + "995 A tight-knit team of rising investigators, alo... Billy Ray \n", + "996 Three American college students studying abroa... Eli Roth \n", + "997 Romantic sparks occur between two dance studen... Jon M. Chu \n", + "998 A pair of friends embark on a mission to reuni... Scot Armstrong \n", + "999 A stuffy businessman finds himself trapped ins... Barry Sonnenfeld \n", + "\n", + " Actors Year \\\n", + "0 Chris Pratt, Vin Diesel, Bradley Cooper, Zoe S... 2014 \n", + "1 Noomi Rapace, Logan Marshall-Green, Michael Fa... 2012 \n", + "2 James McAvoy, Anya Taylor-Joy, Haley Lu Richar... 2016 \n", + "3 Matthew McConaughey,Reese Witherspoon, Seth Ma... 2016 \n", + "4 Will Smith, Jared Leto, Margot Robbie, Viola D... 2016 \n", + ".. ... ... \n", + "995 Chiwetel Ejiofor, Nicole Kidman, Julia Roberts... 2015 \n", + "996 Lauren German, Heather Matarazzo, Bijou Philli... 2007 \n", + "997 Robert Hoffman, Briana Evigan, Cassie Ventura,... 2008 \n", + "998 Adam Pally, T.J. Miller, Thomas Middleditch,Sh... 2014 \n", + "999 Kevin Spacey, Jennifer Garner, Robbie Amell,Ch... 2016 \n", + "\n", + " Runtime (Minutes) Rating Votes Revenue (Millions) Metascore Bin \\\n", + "0 121 8.1 757074 333.13 76.0 cat_4 \n", + "1 124 7.0 485820 126.46 65.0 cat_4 \n", + "2 117 7.3 157606 138.12 62.0 cat_4 \n", + "3 108 7.2 60545 270.32 59.0 cat_3 \n", + "4 123 6.2 393727 325.02 40.0 cat_4 \n", + ".. ... ... ... ... ... ... \n", + "995 111 6.2 27585 NaN 45.0 cat_3 \n", + "996 94 5.5 73152 17.54 46.0 cat_3 \n", + "997 98 6.2 70699 58.01 50.0 cat_3 \n", + "998 93 5.6 4881 NaN 22.0 cat_2 \n", + "999 87 5.3 12435 19.64 11.0 cat_3 \n", + "\n", + " Revenue per Minute \n", + "0 2.753140 \n", + "1 1.019839 \n", + "2 1.180513 \n", + "3 2.502963 \n", + "4 2.642439 \n", + ".. ... \n", + "995 NaN \n", + "996 0.186596 \n", + "997 0.591939 \n", + "998 NaN \n", + "999 0.225747 \n", + "\n", + "[1000 rows x 14 columns]" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "fa346936", + "metadata": {}, + "outputs": [], + "source": [ + "def new_rating(genre, rating):\n", + " if \"thriller\" in genre.lower():\n", + " rating = rating + 1\n", + " elif \"comedy\" in genre.lower():\n", + " rating = rating -1\n", + " return rating" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "785f6324", + "metadata": {}, + "outputs": [], + "source": [ + "df[\"New Rating\"] = df.apply(lambda x: new_rating(x[\"Genre\"], x[\"Rating\"]), axis = 1)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "9ea130d3", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
RankTitleGenreDescriptionDirectorActorsYearRuntime (Minutes)RatingVotesRevenue (Millions)MetascoreBinRevenue per MinuteNew Rating
01Guardians of the GalaxyAction,Adventure,Sci-FiA group of intergalactic criminals are forced ...James GunnChris Pratt, Vin Diesel, Bradley Cooper, Zoe S...20141218.1757074333.1376.0cat_42.7531408.1
12PrometheusAdventure,Mystery,Sci-FiFollowing clues to the origin of mankind, a te...Ridley ScottNoomi Rapace, Logan Marshall-Green, Michael Fa...20121247.0485820126.4665.0cat_41.0198397.0
23SplitHorror,ThrillerThree girls are kidnapped by a man with a diag...M. Night ShyamalanJames McAvoy, Anya Taylor-Joy, Haley Lu Richar...20161177.3157606138.1262.0cat_41.1805138.3
34SingAnimation,Comedy,FamilyIn a city of humanoid animals, a hustling thea...Christophe LourdeletMatthew McConaughey,Reese Witherspoon, Seth Ma...20161087.260545270.3259.0cat_32.5029636.2
45Suicide SquadAction,Adventure,FantasyA secret government agency recruits some of th...David AyerWill Smith, Jared Leto, Margot Robbie, Viola D...20161236.2393727325.0240.0cat_42.6424396.2
................................................
995996Secret in Their EyesCrime,Drama,MysteryA tight-knit team of rising investigators, alo...Billy RayChiwetel Ejiofor, Nicole Kidman, Julia Roberts...20151116.227585NaN45.0cat_3NaN6.2
996997Hostel: Part IIHorrorThree American college students studying abroa...Eli RothLauren German, Heather Matarazzo, Bijou Philli...2007945.57315217.5446.0cat_30.1865965.5
997998Step Up 2: The StreetsDrama,Music,RomanceRomantic sparks occur between two dance studen...Jon M. ChuRobert Hoffman, Briana Evigan, Cassie Ventura,...2008986.27069958.0150.0cat_30.5919396.2
998999Search PartyAdventure,ComedyA pair of friends embark on a mission to reuni...Scot ArmstrongAdam Pally, T.J. Miller, Thomas Middleditch,Sh...2014935.64881NaN22.0cat_2NaN4.6
9991000Nine LivesComedy,Family,FantasyA stuffy businessman finds himself trapped ins...Barry SonnenfeldKevin Spacey, Jennifer Garner, Robbie Amell,Ch...2016875.31243519.6411.0cat_30.2257474.3
\n", + "

1000 rows × 15 columns

\n", + "
" + ], + "text/plain": [ + " Rank Title Genre \\\n", + "0 1 Guardians of the Galaxy Action,Adventure,Sci-Fi \n", + "1 2 Prometheus Adventure,Mystery,Sci-Fi \n", + "2 3 Split Horror,Thriller \n", + "3 4 Sing Animation,Comedy,Family \n", + "4 5 Suicide Squad Action,Adventure,Fantasy \n", + ".. ... ... ... \n", + "995 996 Secret in Their Eyes Crime,Drama,Mystery \n", + "996 997 Hostel: Part II Horror \n", + "997 998 Step Up 2: The Streets Drama,Music,Romance \n", + "998 999 Search Party Adventure,Comedy \n", + "999 1000 Nine Lives Comedy,Family,Fantasy \n", + "\n", + " Description Director \\\n", + "0 A group of intergalactic criminals are forced ... James Gunn \n", + "1 Following clues to the origin of mankind, a te... Ridley Scott \n", + "2 Three girls are kidnapped by a man with a diag... M. Night Shyamalan \n", + "3 In a city of humanoid animals, a hustling thea... Christophe Lourdelet \n", + "4 A secret government agency recruits some of th... David Ayer \n", + ".. ... ... \n", + "995 A tight-knit team of rising investigators, alo... Billy Ray \n", + "996 Three American college students studying abroa... Eli Roth \n", + "997 Romantic sparks occur between two dance studen... Jon M. Chu \n", + "998 A pair of friends embark on a mission to reuni... Scot Armstrong \n", + "999 A stuffy businessman finds himself trapped ins... Barry Sonnenfeld \n", + "\n", + " Actors Year \\\n", + "0 Chris Pratt, Vin Diesel, Bradley Cooper, Zoe S... 2014 \n", + "1 Noomi Rapace, Logan Marshall-Green, Michael Fa... 2012 \n", + "2 James McAvoy, Anya Taylor-Joy, Haley Lu Richar... 2016 \n", + "3 Matthew McConaughey,Reese Witherspoon, Seth Ma... 2016 \n", + "4 Will Smith, Jared Leto, Margot Robbie, Viola D... 2016 \n", + ".. ... ... \n", + "995 Chiwetel Ejiofor, Nicole Kidman, Julia Roberts... 2015 \n", + "996 Lauren German, Heather Matarazzo, Bijou Philli... 2007 \n", + "997 Robert Hoffman, Briana Evigan, Cassie Ventura,... 2008 \n", + "998 Adam Pally, T.J. Miller, Thomas Middleditch,Sh... 2014 \n", + "999 Kevin Spacey, Jennifer Garner, Robbie Amell,Ch... 2016 \n", + "\n", + " Runtime (Minutes) Rating Votes Revenue (Millions) Metascore Bin \\\n", + "0 121 8.1 757074 333.13 76.0 cat_4 \n", + "1 124 7.0 485820 126.46 65.0 cat_4 \n", + "2 117 7.3 157606 138.12 62.0 cat_4 \n", + "3 108 7.2 60545 270.32 59.0 cat_3 \n", + "4 123 6.2 393727 325.02 40.0 cat_4 \n", + ".. ... ... ... ... ... ... \n", + "995 111 6.2 27585 NaN 45.0 cat_3 \n", + "996 94 5.5 73152 17.54 46.0 cat_3 \n", + "997 98 6.2 70699 58.01 50.0 cat_3 \n", + "998 93 5.6 4881 NaN 22.0 cat_2 \n", + "999 87 5.3 12435 19.64 11.0 cat_3 \n", + "\n", + " Revenue per Minute New Rating \n", + "0 2.753140 8.1 \n", + "1 1.019839 7.0 \n", + "2 1.180513 8.3 \n", + "3 2.502963 6.2 \n", + "4 2.642439 6.2 \n", + ".. ... ... \n", + "995 NaN 6.2 \n", + "996 0.186596 5.5 \n", + "997 0.591939 6.2 \n", + "998 NaN 4.6 \n", + "999 0.225747 4.3 \n", + "\n", + "[1000 rows x 15 columns]" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df" + ] + }, + { + "cell_type": "markdown", + "id": "ef54ae50", + "metadata": {}, + "source": [ + "## Challenge 4. A bit too weird..." + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "734632a9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def prime(movie_title, votes):\n", + " ascii_movie = []\n", + " def criba_eratostenes(n): #Definimos una función para determinar si el número es o no primo siguiendo el método de la criba de eratóstenes.\n", + " primos = []\n", + " no_primos = []\n", + " for i in range(2, n + 1):\n", + " if i not in no_primos:\n", + " primos.append(i)\n", + " for j in range(i * i, n + 1, i):\n", + " no_primos.append(j)\n", + " if n in primos:\n", + " return True\n", + " else:\n", + " return False\n", + " for i in movie_title:\n", + " ascii_movie.append(ord(i))\n", + " number = int((sum(ascii_movie)) / votes)\n", + " if criba_eratostenes(number) == True:\n", + " return True\n", + " else:\n", + " return False\n", + " \n", + " \n", + "prime(\"Hola caracola\", 90)" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "21af3d36", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def criba_eratostenes(n): #Definimos una función para determinar si el número es o no primo siguiendo el método de la criba de eratóstenes.\n", + " primos = []\n", + " no_primos = []\n", + " for i in range(2, n + 1):\n", + " if i not in no_primos:\n", + " primos.append(i)\n", + "\n", + " for j in range(i * i, n + 1, i):\n", + " no_primos.append(j)\n", + " if n in primos:\n", + " return True\n", + " else:\n", + " return False\n", + " \n", + "criba_eratostenes(23)\n", + "\n", + "#Dejo la función sola para comprobar que funciona (es muy difícil que coincida en el dataset, aunque da True en el 45, por ejemplo.)" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "aa57e8fa", + "metadata": {}, + "outputs": [], + "source": [ + "df[\"Is Prime?\"] = df.apply(lambda x: prime(x[\"Title\"], x[\"Votes\"]), axis = 1)" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "70ffb2f0", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
RankTitleGenreDescriptionDirectorActorsYearRuntime (Minutes)RatingVotesRevenue (Millions)MetascoreBinRevenue per MinuteNew RatingIs Prime?
01Guardians of the GalaxyAction,Adventure,Sci-FiA group of intergalactic criminals are forced ...James GunnChris Pratt, Vin Diesel, Bradley Cooper, Zoe S...20141218.1757074333.1376.0cat_42.7531408.1False
12PrometheusAdventure,Mystery,Sci-FiFollowing clues to the origin of mankind, a te...Ridley ScottNoomi Rapace, Logan Marshall-Green, Michael Fa...20121247.0485820126.4665.0cat_41.0198397.0False
23SplitHorror,ThrillerThree girls are kidnapped by a man with a diag...M. Night ShyamalanJames McAvoy, Anya Taylor-Joy, Haley Lu Richar...20161177.3157606138.1262.0cat_41.1805138.3False
34SingAnimation,Comedy,FamilyIn a city of humanoid animals, a hustling thea...Christophe LourdeletMatthew McConaughey,Reese Witherspoon, Seth Ma...20161087.260545270.3259.0cat_32.5029636.2False
45Suicide SquadAction,Adventure,FantasyA secret government agency recruits some of th...David AyerWill Smith, Jared Leto, Margot Robbie, Viola D...20161236.2393727325.0240.0cat_42.6424396.2False
...................................................
995996Secret in Their EyesCrime,Drama,MysteryA tight-knit team of rising investigators, alo...Billy RayChiwetel Ejiofor, Nicole Kidman, Julia Roberts...20151116.227585NaN45.0cat_3NaN6.2False
996997Hostel: Part IIHorrorThree American college students studying abroa...Eli RothLauren German, Heather Matarazzo, Bijou Philli...2007945.57315217.5446.0cat_30.1865965.5False
997998Step Up 2: The StreetsDrama,Music,RomanceRomantic sparks occur between two dance studen...Jon M. ChuRobert Hoffman, Briana Evigan, Cassie Ventura,...2008986.27069958.0150.0cat_30.5919396.2False
998999Search PartyAdventure,ComedyA pair of friends embark on a mission to reuni...Scot ArmstrongAdam Pally, T.J. Miller, Thomas Middleditch,Sh...2014935.64881NaN22.0cat_2NaN4.6False
9991000Nine LivesComedy,Family,FantasyA stuffy businessman finds himself trapped ins...Barry SonnenfeldKevin Spacey, Jennifer Garner, Robbie Amell,Ch...2016875.31243519.6411.0cat_30.2257474.3False
\n", + "

1000 rows × 16 columns

\n", + "
" + ], + "text/plain": [ + " Rank Title Genre \\\n", + "0 1 Guardians of the Galaxy Action,Adventure,Sci-Fi \n", + "1 2 Prometheus Adventure,Mystery,Sci-Fi \n", + "2 3 Split Horror,Thriller \n", + "3 4 Sing Animation,Comedy,Family \n", + "4 5 Suicide Squad Action,Adventure,Fantasy \n", + ".. ... ... ... \n", + "995 996 Secret in Their Eyes Crime,Drama,Mystery \n", + "996 997 Hostel: Part II Horror \n", + "997 998 Step Up 2: The Streets Drama,Music,Romance \n", + "998 999 Search Party Adventure,Comedy \n", + "999 1000 Nine Lives Comedy,Family,Fantasy \n", + "\n", + " Description Director \\\n", + "0 A group of intergalactic criminals are forced ... James Gunn \n", + "1 Following clues to the origin of mankind, a te... Ridley Scott \n", + "2 Three girls are kidnapped by a man with a diag... M. Night Shyamalan \n", + "3 In a city of humanoid animals, a hustling thea... Christophe Lourdelet \n", + "4 A secret government agency recruits some of th... David Ayer \n", + ".. ... ... \n", + "995 A tight-knit team of rising investigators, alo... Billy Ray \n", + "996 Three American college students studying abroa... Eli Roth \n", + "997 Romantic sparks occur between two dance studen... Jon M. Chu \n", + "998 A pair of friends embark on a mission to reuni... Scot Armstrong \n", + "999 A stuffy businessman finds himself trapped ins... Barry Sonnenfeld \n", + "\n", + " Actors Year \\\n", + "0 Chris Pratt, Vin Diesel, Bradley Cooper, Zoe S... 2014 \n", + "1 Noomi Rapace, Logan Marshall-Green, Michael Fa... 2012 \n", + "2 James McAvoy, Anya Taylor-Joy, Haley Lu Richar... 2016 \n", + "3 Matthew McConaughey,Reese Witherspoon, Seth Ma... 2016 \n", + "4 Will Smith, Jared Leto, Margot Robbie, Viola D... 2016 \n", + ".. ... ... \n", + "995 Chiwetel Ejiofor, Nicole Kidman, Julia Roberts... 2015 \n", + "996 Lauren German, Heather Matarazzo, Bijou Philli... 2007 \n", + "997 Robert Hoffman, Briana Evigan, Cassie Ventura,... 2008 \n", + "998 Adam Pally, T.J. Miller, Thomas Middleditch,Sh... 2014 \n", + "999 Kevin Spacey, Jennifer Garner, Robbie Amell,Ch... 2016 \n", + "\n", + " Runtime (Minutes) Rating Votes Revenue (Millions) Metascore Bin \\\n", + "0 121 8.1 757074 333.13 76.0 cat_4 \n", + "1 124 7.0 485820 126.46 65.0 cat_4 \n", + "2 117 7.3 157606 138.12 62.0 cat_4 \n", + "3 108 7.2 60545 270.32 59.0 cat_3 \n", + "4 123 6.2 393727 325.02 40.0 cat_4 \n", + ".. ... ... ... ... ... ... \n", + "995 111 6.2 27585 NaN 45.0 cat_3 \n", + "996 94 5.5 73152 17.54 46.0 cat_3 \n", + "997 98 6.2 70699 58.01 50.0 cat_3 \n", + "998 93 5.6 4881 NaN 22.0 cat_2 \n", + "999 87 5.3 12435 19.64 11.0 cat_3 \n", + "\n", + " Revenue per Minute New Rating Is Prime? \n", + "0 2.753140 8.1 False \n", + "1 1.019839 7.0 False \n", + "2 1.180513 8.3 False \n", + "3 2.502963 6.2 False \n", + "4 2.642439 6.2 False \n", + ".. ... ... ... \n", + "995 NaN 6.2 False \n", + "996 0.186596 5.5 False \n", + "997 0.591939 6.2 False \n", + "998 NaN 4.6 False \n", + "999 0.225747 4.3 False \n", + "\n", + "[1000 rows x 16 columns]" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df" + ] + }, + { + "cell_type": "markdown", + "id": "dc37872f", + "metadata": {}, + "source": [ + "## Challege 5. And finally some fantasy..." + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "22077648", + "metadata": {}, + "outputs": [], + "source": [ + "# I am goin to establish the average rating taking in consideration\n", + "#web rating(metascore) and user rating(rating)." + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "2232920d", + "metadata": {}, + "outputs": [], + "source": [ + "#I am going to convert the metascore rating into a 1-10 value, to be equal to the other rating.\n", + "\n", + "df[\"Metascore\"] = df[\"Metascore\"]/10\n" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "1ee3d2f9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
RankTitleGenreDescriptionDirectorActorsYearRuntime (Minutes)RatingVotesRevenue (Millions)MetascoreBinRevenue per MinuteNew RatingIs Prime?
01Guardians of the GalaxyAction,Adventure,Sci-FiA group of intergalactic criminals are forced ...James GunnChris Pratt, Vin Diesel, Bradley Cooper, Zoe S...20141218.1757074333.137.6cat_42.7531408.1False
12PrometheusAdventure,Mystery,Sci-FiFollowing clues to the origin of mankind, a te...Ridley ScottNoomi Rapace, Logan Marshall-Green, Michael Fa...20121247.0485820126.466.5cat_41.0198397.0False
23SplitHorror,ThrillerThree girls are kidnapped by a man with a diag...M. Night ShyamalanJames McAvoy, Anya Taylor-Joy, Haley Lu Richar...20161177.3157606138.126.2cat_41.1805138.3False
34SingAnimation,Comedy,FamilyIn a city of humanoid animals, a hustling thea...Christophe LourdeletMatthew McConaughey,Reese Witherspoon, Seth Ma...20161087.260545270.325.9cat_32.5029636.2False
45Suicide SquadAction,Adventure,FantasyA secret government agency recruits some of th...David AyerWill Smith, Jared Leto, Margot Robbie, Viola D...20161236.2393727325.024.0cat_42.6424396.2False
...................................................
995996Secret in Their EyesCrime,Drama,MysteryA tight-knit team of rising investigators, alo...Billy RayChiwetel Ejiofor, Nicole Kidman, Julia Roberts...20151116.227585NaN4.5cat_3NaN6.2False
996997Hostel: Part IIHorrorThree American college students studying abroa...Eli RothLauren German, Heather Matarazzo, Bijou Philli...2007945.57315217.544.6cat_30.1865965.5False
997998Step Up 2: The StreetsDrama,Music,RomanceRomantic sparks occur between two dance studen...Jon M. ChuRobert Hoffman, Briana Evigan, Cassie Ventura,...2008986.27069958.015.0cat_30.5919396.2False
998999Search PartyAdventure,ComedyA pair of friends embark on a mission to reuni...Scot ArmstrongAdam Pally, T.J. Miller, Thomas Middleditch,Sh...2014935.64881NaN2.2cat_2NaN4.6False
9991000Nine LivesComedy,Family,FantasyA stuffy businessman finds himself trapped ins...Barry SonnenfeldKevin Spacey, Jennifer Garner, Robbie Amell,Ch...2016875.31243519.641.1cat_30.2257474.3False
\n", + "

1000 rows × 16 columns

\n", + "
" + ], + "text/plain": [ + " Rank Title Genre \\\n", + "0 1 Guardians of the Galaxy Action,Adventure,Sci-Fi \n", + "1 2 Prometheus Adventure,Mystery,Sci-Fi \n", + "2 3 Split Horror,Thriller \n", + "3 4 Sing Animation,Comedy,Family \n", + "4 5 Suicide Squad Action,Adventure,Fantasy \n", + ".. ... ... ... \n", + "995 996 Secret in Their Eyes Crime,Drama,Mystery \n", + "996 997 Hostel: Part II Horror \n", + "997 998 Step Up 2: The Streets Drama,Music,Romance \n", + "998 999 Search Party Adventure,Comedy \n", + "999 1000 Nine Lives Comedy,Family,Fantasy \n", + "\n", + " Description Director \\\n", + "0 A group of intergalactic criminals are forced ... James Gunn \n", + "1 Following clues to the origin of mankind, a te... Ridley Scott \n", + "2 Three girls are kidnapped by a man with a diag... M. Night Shyamalan \n", + "3 In a city of humanoid animals, a hustling thea... Christophe Lourdelet \n", + "4 A secret government agency recruits some of th... David Ayer \n", + ".. ... ... \n", + "995 A tight-knit team of rising investigators, alo... Billy Ray \n", + "996 Three American college students studying abroa... Eli Roth \n", + "997 Romantic sparks occur between two dance studen... Jon M. Chu \n", + "998 A pair of friends embark on a mission to reuni... Scot Armstrong \n", + "999 A stuffy businessman finds himself trapped ins... Barry Sonnenfeld \n", + "\n", + " Actors Year \\\n", + "0 Chris Pratt, Vin Diesel, Bradley Cooper, Zoe S... 2014 \n", + "1 Noomi Rapace, Logan Marshall-Green, Michael Fa... 2012 \n", + "2 James McAvoy, Anya Taylor-Joy, Haley Lu Richar... 2016 \n", + "3 Matthew McConaughey,Reese Witherspoon, Seth Ma... 2016 \n", + "4 Will Smith, Jared Leto, Margot Robbie, Viola D... 2016 \n", + ".. ... ... \n", + "995 Chiwetel Ejiofor, Nicole Kidman, Julia Roberts... 2015 \n", + "996 Lauren German, Heather Matarazzo, Bijou Philli... 2007 \n", + "997 Robert Hoffman, Briana Evigan, Cassie Ventura,... 2008 \n", + "998 Adam Pally, T.J. Miller, Thomas Middleditch,Sh... 2014 \n", + "999 Kevin Spacey, Jennifer Garner, Robbie Amell,Ch... 2016 \n", + "\n", + " Runtime (Minutes) Rating Votes Revenue (Millions) Metascore Bin \\\n", + "0 121 8.1 757074 333.13 7.6 cat_4 \n", + "1 124 7.0 485820 126.46 6.5 cat_4 \n", + "2 117 7.3 157606 138.12 6.2 cat_4 \n", + "3 108 7.2 60545 270.32 5.9 cat_3 \n", + "4 123 6.2 393727 325.02 4.0 cat_4 \n", + ".. ... ... ... ... ... ... \n", + "995 111 6.2 27585 NaN 4.5 cat_3 \n", + "996 94 5.5 73152 17.54 4.6 cat_3 \n", + "997 98 6.2 70699 58.01 5.0 cat_3 \n", + "998 93 5.6 4881 NaN 2.2 cat_2 \n", + "999 87 5.3 12435 19.64 1.1 cat_3 \n", + "\n", + " Revenue per Minute New Rating Is Prime? \n", + "0 2.753140 8.1 False \n", + "1 1.019839 7.0 False \n", + "2 1.180513 8.3 False \n", + "3 2.502963 6.2 False \n", + "4 2.642439 6.2 False \n", + ".. ... ... ... \n", + "995 NaN 6.2 False \n", + "996 0.186596 5.5 False \n", + "997 0.591939 6.2 False \n", + "998 NaN 4.6 False \n", + "999 0.225747 4.3 False \n", + "\n", + "[1000 rows x 16 columns]" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "30aa1c51", + "metadata": {}, + "outputs": [], + "source": [ + "df[\"Average_Rating\"] = (df[\"Rating\"] + df[\"Metascore\"]) / 2" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "77c139e4", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
RankTitleGenreDescriptionDirectorActorsYearRuntime (Minutes)RatingVotesRevenue (Millions)MetascoreBinRevenue per MinuteNew RatingIs Prime?Average_Rating
01Guardians of the GalaxyAction,Adventure,Sci-FiA group of intergalactic criminals are forced ...James GunnChris Pratt, Vin Diesel, Bradley Cooper, Zoe S...20141218.1757074333.137.6cat_42.7531408.1False7.85
12PrometheusAdventure,Mystery,Sci-FiFollowing clues to the origin of mankind, a te...Ridley ScottNoomi Rapace, Logan Marshall-Green, Michael Fa...20121247.0485820126.466.5cat_41.0198397.0False6.75
23SplitHorror,ThrillerThree girls are kidnapped by a man with a diag...M. Night ShyamalanJames McAvoy, Anya Taylor-Joy, Haley Lu Richar...20161177.3157606138.126.2cat_41.1805138.3False6.75
34SingAnimation,Comedy,FamilyIn a city of humanoid animals, a hustling thea...Christophe LourdeletMatthew McConaughey,Reese Witherspoon, Seth Ma...20161087.260545270.325.9cat_32.5029636.2False6.55
45Suicide SquadAction,Adventure,FantasyA secret government agency recruits some of th...David AyerWill Smith, Jared Leto, Margot Robbie, Viola D...20161236.2393727325.024.0cat_42.6424396.2False5.10
......................................................
995996Secret in Their EyesCrime,Drama,MysteryA tight-knit team of rising investigators, alo...Billy RayChiwetel Ejiofor, Nicole Kidman, Julia Roberts...20151116.227585NaN4.5cat_3NaN6.2False5.35
996997Hostel: Part IIHorrorThree American college students studying abroa...Eli RothLauren German, Heather Matarazzo, Bijou Philli...2007945.57315217.544.6cat_30.1865965.5False5.05
997998Step Up 2: The StreetsDrama,Music,RomanceRomantic sparks occur between two dance studen...Jon M. ChuRobert Hoffman, Briana Evigan, Cassie Ventura,...2008986.27069958.015.0cat_30.5919396.2False5.60
998999Search PartyAdventure,ComedyA pair of friends embark on a mission to reuni...Scot ArmstrongAdam Pally, T.J. Miller, Thomas Middleditch,Sh...2014935.64881NaN2.2cat_2NaN4.6False3.90
9991000Nine LivesComedy,Family,FantasyA stuffy businessman finds himself trapped ins...Barry SonnenfeldKevin Spacey, Jennifer Garner, Robbie Amell,Ch...2016875.31243519.641.1cat_30.2257474.3False3.20
\n", + "

1000 rows × 17 columns

\n", + "
" + ], + "text/plain": [ + " Rank Title Genre \\\n", + "0 1 Guardians of the Galaxy Action,Adventure,Sci-Fi \n", + "1 2 Prometheus Adventure,Mystery,Sci-Fi \n", + "2 3 Split Horror,Thriller \n", + "3 4 Sing Animation,Comedy,Family \n", + "4 5 Suicide Squad Action,Adventure,Fantasy \n", + ".. ... ... ... \n", + "995 996 Secret in Their Eyes Crime,Drama,Mystery \n", + "996 997 Hostel: Part II Horror \n", + "997 998 Step Up 2: The Streets Drama,Music,Romance \n", + "998 999 Search Party Adventure,Comedy \n", + "999 1000 Nine Lives Comedy,Family,Fantasy \n", + "\n", + " Description Director \\\n", + "0 A group of intergalactic criminals are forced ... James Gunn \n", + "1 Following clues to the origin of mankind, a te... Ridley Scott \n", + "2 Three girls are kidnapped by a man with a diag... M. Night Shyamalan \n", + "3 In a city of humanoid animals, a hustling thea... Christophe Lourdelet \n", + "4 A secret government agency recruits some of th... David Ayer \n", + ".. ... ... \n", + "995 A tight-knit team of rising investigators, alo... Billy Ray \n", + "996 Three American college students studying abroa... Eli Roth \n", + "997 Romantic sparks occur between two dance studen... Jon M. Chu \n", + "998 A pair of friends embark on a mission to reuni... Scot Armstrong \n", + "999 A stuffy businessman finds himself trapped ins... Barry Sonnenfeld \n", + "\n", + " Actors Year \\\n", + "0 Chris Pratt, Vin Diesel, Bradley Cooper, Zoe S... 2014 \n", + "1 Noomi Rapace, Logan Marshall-Green, Michael Fa... 2012 \n", + "2 James McAvoy, Anya Taylor-Joy, Haley Lu Richar... 2016 \n", + "3 Matthew McConaughey,Reese Witherspoon, Seth Ma... 2016 \n", + "4 Will Smith, Jared Leto, Margot Robbie, Viola D... 2016 \n", + ".. ... ... \n", + "995 Chiwetel Ejiofor, Nicole Kidman, Julia Roberts... 2015 \n", + "996 Lauren German, Heather Matarazzo, Bijou Philli... 2007 \n", + "997 Robert Hoffman, Briana Evigan, Cassie Ventura,... 2008 \n", + "998 Adam Pally, T.J. Miller, Thomas Middleditch,Sh... 2014 \n", + "999 Kevin Spacey, Jennifer Garner, Robbie Amell,Ch... 2016 \n", + "\n", + " Runtime (Minutes) Rating Votes Revenue (Millions) Metascore Bin \\\n", + "0 121 8.1 757074 333.13 7.6 cat_4 \n", + "1 124 7.0 485820 126.46 6.5 cat_4 \n", + "2 117 7.3 157606 138.12 6.2 cat_4 \n", + "3 108 7.2 60545 270.32 5.9 cat_3 \n", + "4 123 6.2 393727 325.02 4.0 cat_4 \n", + ".. ... ... ... ... ... ... \n", + "995 111 6.2 27585 NaN 4.5 cat_3 \n", + "996 94 5.5 73152 17.54 4.6 cat_3 \n", + "997 98 6.2 70699 58.01 5.0 cat_3 \n", + "998 93 5.6 4881 NaN 2.2 cat_2 \n", + "999 87 5.3 12435 19.64 1.1 cat_3 \n", + "\n", + " Revenue per Minute New Rating Is Prime? Average_Rating \n", + "0 2.753140 8.1 False 7.85 \n", + "1 1.019839 7.0 False 6.75 \n", + "2 1.180513 8.3 False 6.75 \n", + "3 2.502963 6.2 False 6.55 \n", + "4 2.642439 6.2 False 5.10 \n", + ".. ... ... ... ... \n", + "995 NaN 6.2 False 5.35 \n", + "996 0.186596 5.5 False 5.05 \n", + "997 0.591939 6.2 False 5.60 \n", + "998 NaN 4.6 False 3.90 \n", + "999 0.225747 4.3 False 3.20 \n", + "\n", + "[1000 rows x 17 columns]" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "2d762507", + "metadata": {}, + "outputs": [], + "source": [ + "top_avg_rated_movies = df.sort_values(by=\"Average_Rating\", ascending=False)" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "5a019e72", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
RankTitleGenreDescriptionDirectorActorsYearRuntime (Minutes)RatingVotesRevenue (Millions)MetascoreBinRevenue per MinuteNew RatingIs Prime?Average_Rating
230231Pan's LabyrinthDrama,Fantasy,WarIn the falangist Spain of 1944, the bookish yo...Guillermo del ToroIvana Baquero, Ariadna Gil, Sergi López,Maribe...20061188.249887937.629.8cat_40.3188148.2False9.00
656657BoyhoodDramaThe life of Mason, from early childhood to his...Richard LinklaterEllar Coltrane, Patricia Arquette, Ethan Hawke...20141657.928672225.3610.0cat_40.1536977.9False8.95
11111212 Years a SlaveBiography,Drama,HistoryIn the antebellum United States, Solomon North...Steve McQueenChiwetel Ejiofor, Michael Kenneth Williams, Mi...20131348.148633856.679.6cat_40.4229108.1False8.85
67La La LandComedy,Drama,MusicA jazz pianist falls for an aspiring actress i...Damien ChazelleRyan Gosling, Emma Stone, Rosemarie DeWitt, J....20161288.3258682151.069.3cat_41.1801567.3False8.80
241242Inside OutAnimation,Adventure,ComedyAfter young Riley is uprooted from her Midwest...Pete DocterAmy Poehler, Bill Hader, Lewis Black, Mindy Ka...2015958.2416689356.459.4cat_43.7521057.2False8.80
......................................................
967968The WalkAdventure,Biography,CrimeIn 1974, high-wire artist Philippe Petit recru...Robert ZemeckisJoseph Gordon-Levitt, Charlotte Le Bon,Guillau...20151237.39237810.14NaNcat_30.0824397.3FalseNaN
969970The Lone RangerAction,Adventure,WesternNative American warrior Tonto recounts the unt...Gore VerbinskiJohnny Depp, Armie Hammer, William Fichtner,To...20131506.519085589.29NaNcat_40.5952676.5FalseNaN
971972DisturbiaDrama,Mystery,ThrillerA teen living under house arrest becomes convi...D.J. CarusoShia LaBeouf, David Morse, Carrie-Anne Moss, S...20071056.919349180.05NaNcat_40.7623817.9FalseNaN
989990SelmaBiography,Drama,HistoryA chronicle of Martin Luther King's campaign t...Ava DuVernayDavid Oyelowo, Carmen Ejogo, Tim Roth, Lorrain...20141287.56763752.07NaNcat_30.4067977.5FalseNaN
992993Take Me Home TonightComedy,Drama,RomanceFour years after graduation, an awkward high s...Michael DowseTopher Grace, Anna Faris, Dan Fogler, Teresa P...2011976.3454196.92NaNcat_30.0713405.3FalseNaN
\n", + "

1000 rows × 17 columns

\n", + "
" + ], + "text/plain": [ + " Rank Title Genre \\\n", + "230 231 Pan's Labyrinth Drama,Fantasy,War \n", + "656 657 Boyhood Drama \n", + "111 112 12 Years a Slave Biography,Drama,History \n", + "6 7 La La Land Comedy,Drama,Music \n", + "241 242 Inside Out Animation,Adventure,Comedy \n", + ".. ... ... ... \n", + "967 968 The Walk Adventure,Biography,Crime \n", + "969 970 The Lone Ranger Action,Adventure,Western \n", + "971 972 Disturbia Drama,Mystery,Thriller \n", + "989 990 Selma Biography,Drama,History \n", + "992 993 Take Me Home Tonight Comedy,Drama,Romance \n", + "\n", + " Description Director \\\n", + "230 In the falangist Spain of 1944, the bookish yo... Guillermo del Toro \n", + "656 The life of Mason, from early childhood to his... Richard Linklater \n", + "111 In the antebellum United States, Solomon North... Steve McQueen \n", + "6 A jazz pianist falls for an aspiring actress i... Damien Chazelle \n", + "241 After young Riley is uprooted from her Midwest... Pete Docter \n", + ".. ... ... \n", + "967 In 1974, high-wire artist Philippe Petit recru... Robert Zemeckis \n", + "969 Native American warrior Tonto recounts the unt... Gore Verbinski \n", + "971 A teen living under house arrest becomes convi... D.J. Caruso \n", + "989 A chronicle of Martin Luther King's campaign t... Ava DuVernay \n", + "992 Four years after graduation, an awkward high s... Michael Dowse \n", + "\n", + " Actors Year \\\n", + "230 Ivana Baquero, Ariadna Gil, Sergi López,Maribe... 2006 \n", + "656 Ellar Coltrane, Patricia Arquette, Ethan Hawke... 2014 \n", + "111 Chiwetel Ejiofor, Michael Kenneth Williams, Mi... 2013 \n", + "6 Ryan Gosling, Emma Stone, Rosemarie DeWitt, J.... 2016 \n", + "241 Amy Poehler, Bill Hader, Lewis Black, Mindy Ka... 2015 \n", + ".. ... ... \n", + "967 Joseph Gordon-Levitt, Charlotte Le Bon,Guillau... 2015 \n", + "969 Johnny Depp, Armie Hammer, William Fichtner,To... 2013 \n", + "971 Shia LaBeouf, David Morse, Carrie-Anne Moss, S... 2007 \n", + "989 David Oyelowo, Carmen Ejogo, Tim Roth, Lorrain... 2014 \n", + "992 Topher Grace, Anna Faris, Dan Fogler, Teresa P... 2011 \n", + "\n", + " Runtime (Minutes) Rating Votes Revenue (Millions) Metascore Bin \\\n", + "230 118 8.2 498879 37.62 9.8 cat_4 \n", + "656 165 7.9 286722 25.36 10.0 cat_4 \n", + "111 134 8.1 486338 56.67 9.6 cat_4 \n", + "6 128 8.3 258682 151.06 9.3 cat_4 \n", + "241 95 8.2 416689 356.45 9.4 cat_4 \n", + ".. ... ... ... ... ... ... \n", + "967 123 7.3 92378 10.14 NaN cat_3 \n", + "969 150 6.5 190855 89.29 NaN cat_4 \n", + "971 105 6.9 193491 80.05 NaN cat_4 \n", + "989 128 7.5 67637 52.07 NaN cat_3 \n", + "992 97 6.3 45419 6.92 NaN cat_3 \n", + "\n", + " Revenue per Minute New Rating Is Prime? Average_Rating \n", + "230 0.318814 8.2 False 9.00 \n", + "656 0.153697 7.9 False 8.95 \n", + "111 0.422910 8.1 False 8.85 \n", + "6 1.180156 7.3 False 8.80 \n", + "241 3.752105 7.2 False 8.80 \n", + ".. ... ... ... ... \n", + "967 0.082439 7.3 False NaN \n", + "969 0.595267 6.5 False NaN \n", + "971 0.762381 7.9 False NaN \n", + "989 0.406797 7.5 False NaN \n", + "992 0.071340 5.3 False NaN \n", + "\n", + "[1000 rows x 17 columns]" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "top_avg_rated_movies" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "31f9595a", + "metadata": {}, + "outputs": [], + "source": [ + "# I am going to create a new ranking taking in consideration the number of votes. If a film has more than 30000 votes, the ranking will decrease 1 point. It will add 1 point to the ones below that number of votes.\n", + "\n", + "def ranking_votes(votes, rating):\n", + " if votes >= 30000:\n", + " rating = rating - 1\n", + " else:\n", + " rating = rating + 1\n", + " return rating\n", + "\n", + "df[\"Rating_Votes\"] = df.apply(lambda x: ranking_votes(x[\"Votes\"], x[\"Rating\"]), axis = 1)" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "7ad8f5c5", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
RankTitleGenreDescriptionDirectorActorsYearRuntime (Minutes)RatingVotesRevenue (Millions)MetascoreBinRevenue per MinuteNew RatingIs Prime?Average_RatingRating_Votes
01Guardians of the GalaxyAction,Adventure,Sci-FiA group of intergalactic criminals are forced ...James GunnChris Pratt, Vin Diesel, Bradley Cooper, Zoe S...20141218.1757074333.137.6cat_42.7531408.1False7.857.1
12PrometheusAdventure,Mystery,Sci-FiFollowing clues to the origin of mankind, a te...Ridley ScottNoomi Rapace, Logan Marshall-Green, Michael Fa...20121247.0485820126.466.5cat_41.0198397.0False6.756.0
23SplitHorror,ThrillerThree girls are kidnapped by a man with a diag...M. Night ShyamalanJames McAvoy, Anya Taylor-Joy, Haley Lu Richar...20161177.3157606138.126.2cat_41.1805138.3False6.756.3
34SingAnimation,Comedy,FamilyIn a city of humanoid animals, a hustling thea...Christophe LourdeletMatthew McConaughey,Reese Witherspoon, Seth Ma...20161087.260545270.325.9cat_32.5029636.2False6.556.2
45Suicide SquadAction,Adventure,FantasyA secret government agency recruits some of th...David AyerWill Smith, Jared Leto, Margot Robbie, Viola D...20161236.2393727325.024.0cat_42.6424396.2False5.105.2
.........................................................
995996Secret in Their EyesCrime,Drama,MysteryA tight-knit team of rising investigators, alo...Billy RayChiwetel Ejiofor, Nicole Kidman, Julia Roberts...20151116.227585NaN4.5cat_3NaN6.2False5.357.2
996997Hostel: Part IIHorrorThree American college students studying abroa...Eli RothLauren German, Heather Matarazzo, Bijou Philli...2007945.57315217.544.6cat_30.1865965.5False5.054.5
997998Step Up 2: The StreetsDrama,Music,RomanceRomantic sparks occur between two dance studen...Jon M. ChuRobert Hoffman, Briana Evigan, Cassie Ventura,...2008986.27069958.015.0cat_30.5919396.2False5.605.2
998999Search PartyAdventure,ComedyA pair of friends embark on a mission to reuni...Scot ArmstrongAdam Pally, T.J. Miller, Thomas Middleditch,Sh...2014935.64881NaN2.2cat_2NaN4.6False3.906.6
9991000Nine LivesComedy,Family,FantasyA stuffy businessman finds himself trapped ins...Barry SonnenfeldKevin Spacey, Jennifer Garner, Robbie Amell,Ch...2016875.31243519.641.1cat_30.2257474.3False3.206.3
\n", + "

1000 rows × 18 columns

\n", + "
" + ], + "text/plain": [ + " Rank Title Genre \\\n", + "0 1 Guardians of the Galaxy Action,Adventure,Sci-Fi \n", + "1 2 Prometheus Adventure,Mystery,Sci-Fi \n", + "2 3 Split Horror,Thriller \n", + "3 4 Sing Animation,Comedy,Family \n", + "4 5 Suicide Squad Action,Adventure,Fantasy \n", + ".. ... ... ... \n", + "995 996 Secret in Their Eyes Crime,Drama,Mystery \n", + "996 997 Hostel: Part II Horror \n", + "997 998 Step Up 2: The Streets Drama,Music,Romance \n", + "998 999 Search Party Adventure,Comedy \n", + "999 1000 Nine Lives Comedy,Family,Fantasy \n", + "\n", + " Description Director \\\n", + "0 A group of intergalactic criminals are forced ... James Gunn \n", + "1 Following clues to the origin of mankind, a te... Ridley Scott \n", + "2 Three girls are kidnapped by a man with a diag... M. Night Shyamalan \n", + "3 In a city of humanoid animals, a hustling thea... Christophe Lourdelet \n", + "4 A secret government agency recruits some of th... David Ayer \n", + ".. ... ... \n", + "995 A tight-knit team of rising investigators, alo... Billy Ray \n", + "996 Three American college students studying abroa... Eli Roth \n", + "997 Romantic sparks occur between two dance studen... Jon M. Chu \n", + "998 A pair of friends embark on a mission to reuni... Scot Armstrong \n", + "999 A stuffy businessman finds himself trapped ins... Barry Sonnenfeld \n", + "\n", + " Actors Year \\\n", + "0 Chris Pratt, Vin Diesel, Bradley Cooper, Zoe S... 2014 \n", + "1 Noomi Rapace, Logan Marshall-Green, Michael Fa... 2012 \n", + "2 James McAvoy, Anya Taylor-Joy, Haley Lu Richar... 2016 \n", + "3 Matthew McConaughey,Reese Witherspoon, Seth Ma... 2016 \n", + "4 Will Smith, Jared Leto, Margot Robbie, Viola D... 2016 \n", + ".. ... ... \n", + "995 Chiwetel Ejiofor, Nicole Kidman, Julia Roberts... 2015 \n", + "996 Lauren German, Heather Matarazzo, Bijou Philli... 2007 \n", + "997 Robert Hoffman, Briana Evigan, Cassie Ventura,... 2008 \n", + "998 Adam Pally, T.J. Miller, Thomas Middleditch,Sh... 2014 \n", + "999 Kevin Spacey, Jennifer Garner, Robbie Amell,Ch... 2016 \n", + "\n", + " Runtime (Minutes) Rating Votes Revenue (Millions) Metascore Bin \\\n", + "0 121 8.1 757074 333.13 7.6 cat_4 \n", + "1 124 7.0 485820 126.46 6.5 cat_4 \n", + "2 117 7.3 157606 138.12 6.2 cat_4 \n", + "3 108 7.2 60545 270.32 5.9 cat_3 \n", + "4 123 6.2 393727 325.02 4.0 cat_4 \n", + ".. ... ... ... ... ... ... \n", + "995 111 6.2 27585 NaN 4.5 cat_3 \n", + "996 94 5.5 73152 17.54 4.6 cat_3 \n", + "997 98 6.2 70699 58.01 5.0 cat_3 \n", + "998 93 5.6 4881 NaN 2.2 cat_2 \n", + "999 87 5.3 12435 19.64 1.1 cat_3 \n", + "\n", + " Revenue per Minute New Rating Is Prime? Average_Rating Rating_Votes \n", + "0 2.753140 8.1 False 7.85 7.1 \n", + "1 1.019839 7.0 False 6.75 6.0 \n", + "2 1.180513 8.3 False 6.75 6.3 \n", + "3 2.502963 6.2 False 6.55 6.2 \n", + "4 2.642439 6.2 False 5.10 5.2 \n", + ".. ... ... ... ... ... \n", + "995 NaN 6.2 False 5.35 7.2 \n", + "996 0.186596 5.5 False 5.05 4.5 \n", + "997 0.591939 6.2 False 5.60 5.2 \n", + "998 NaN 4.6 False 3.90 6.6 \n", + "999 0.225747 4.3 False 3.20 6.3 \n", + "\n", + "[1000 rows x 18 columns]" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "3f3f23f4", + "metadata": {}, + "outputs": [], + "source": [ + "#Finally, I am going to create a rating based on the the other kind of ratings. \n", + "\n", + "df[\"Final_Rating\"] = (df[\"Rating\"] + df[\"Metascore\"] + df[\"Average_Rating\"] + df[\"Rating_Votes\"]) / 4" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "id": "9bd0d1a4", + "metadata": { + "scrolled": false + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
RankTitleGenreDescriptionDirectorActorsYearRuntime (Minutes)RatingVotesRevenue (Millions)MetascoreBinRevenue per MinuteNew RatingIs Prime?Average_RatingRating_VotesFinal_Rating
230231Pan's LabyrinthDrama,Fantasy,WarIn the falangist Spain of 1944, the bookish yo...Guillermo del ToroIvana Baquero, Ariadna Gil, Sergi López,Maribe...20061188.249887937.629.8cat_40.3188148.2False9.007.28.5500
861862Koe no katachiAnimation,Drama,RomanceThe story revolves around Nishimiya Shoko, a g...Naoko YamadaMiyu Irino, Saori Hayami, Aoi Yuki, Kenshô Ono20161298.42421NaN8.0cat_2NaN8.4False8.209.48.5000
611612Toni ErdmannComedy,DramaA practical joking father tries to reconnect w...Maren AdeSandra Hüller, Peter Simonischek, Michael Witt...20161627.6243871.489.3cat_30.0091366.6False8.458.68.4875
5455The Dark KnightAction,Crime,DramaWhen the menace known as the Joker wreaks havo...Christopher NolanChristian Bale, Heath Ledger, Aaron Eckhart,Mi...20081529.01791916533.328.2cat_53.5086849.0False8.608.08.4500
184185ForushandeDrama,ThrillerWhile both participating in a production of \"D...Asghar FarhadiTaraneh Alidoosti, Shahab Hosseini, Babak Kari...20161248.0223893.408.5cat_30.0274199.0False8.259.08.4375
............................................................
967968The WalkAdventure,Biography,CrimeIn 1974, high-wire artist Philippe Petit recru...Robert ZemeckisJoseph Gordon-Levitt, Charlotte Le Bon,Guillau...20151237.39237810.14NaNcat_30.0824397.3FalseNaN6.3NaN
969970The Lone RangerAction,Adventure,WesternNative American warrior Tonto recounts the unt...Gore VerbinskiJohnny Depp, Armie Hammer, William Fichtner,To...20131506.519085589.29NaNcat_40.5952676.5FalseNaN5.5NaN
971972DisturbiaDrama,Mystery,ThrillerA teen living under house arrest becomes convi...D.J. CarusoShia LaBeouf, David Morse, Carrie-Anne Moss, S...20071056.919349180.05NaNcat_40.7623817.9FalseNaN5.9NaN
989990SelmaBiography,Drama,HistoryA chronicle of Martin Luther King's campaign t...Ava DuVernayDavid Oyelowo, Carmen Ejogo, Tim Roth, Lorrain...20141287.56763752.07NaNcat_30.4067977.5FalseNaN6.5NaN
992993Take Me Home TonightComedy,Drama,RomanceFour years after graduation, an awkward high s...Michael DowseTopher Grace, Anna Faris, Dan Fogler, Teresa P...2011976.3454196.92NaNcat_30.0713405.3FalseNaN5.3NaN
\n", + "

1000 rows × 19 columns

\n", + "
" + ], + "text/plain": [ + " Rank Title Genre \\\n", + "230 231 Pan's Labyrinth Drama,Fantasy,War \n", + "861 862 Koe no katachi Animation,Drama,Romance \n", + "611 612 Toni Erdmann Comedy,Drama \n", + "54 55 The Dark Knight Action,Crime,Drama \n", + "184 185 Forushande Drama,Thriller \n", + ".. ... ... ... \n", + "967 968 The Walk Adventure,Biography,Crime \n", + "969 970 The Lone Ranger Action,Adventure,Western \n", + "971 972 Disturbia Drama,Mystery,Thriller \n", + "989 990 Selma Biography,Drama,History \n", + "992 993 Take Me Home Tonight Comedy,Drama,Romance \n", + "\n", + " Description Director \\\n", + "230 In the falangist Spain of 1944, the bookish yo... Guillermo del Toro \n", + "861 The story revolves around Nishimiya Shoko, a g... Naoko Yamada \n", + "611 A practical joking father tries to reconnect w... Maren Ade \n", + "54 When the menace known as the Joker wreaks havo... Christopher Nolan \n", + "184 While both participating in a production of \"D... Asghar Farhadi \n", + ".. ... ... \n", + "967 In 1974, high-wire artist Philippe Petit recru... Robert Zemeckis \n", + "969 Native American warrior Tonto recounts the unt... Gore Verbinski \n", + "971 A teen living under house arrest becomes convi... D.J. Caruso \n", + "989 A chronicle of Martin Luther King's campaign t... Ava DuVernay \n", + "992 Four years after graduation, an awkward high s... Michael Dowse \n", + "\n", + " Actors Year \\\n", + "230 Ivana Baquero, Ariadna Gil, Sergi López,Maribe... 2006 \n", + "861 Miyu Irino, Saori Hayami, Aoi Yuki, Kenshô Ono 2016 \n", + "611 Sandra Hüller, Peter Simonischek, Michael Witt... 2016 \n", + "54 Christian Bale, Heath Ledger, Aaron Eckhart,Mi... 2008 \n", + "184 Taraneh Alidoosti, Shahab Hosseini, Babak Kari... 2016 \n", + ".. ... ... \n", + "967 Joseph Gordon-Levitt, Charlotte Le Bon,Guillau... 2015 \n", + "969 Johnny Depp, Armie Hammer, William Fichtner,To... 2013 \n", + "971 Shia LaBeouf, David Morse, Carrie-Anne Moss, S... 2007 \n", + "989 David Oyelowo, Carmen Ejogo, Tim Roth, Lorrain... 2014 \n", + "992 Topher Grace, Anna Faris, Dan Fogler, Teresa P... 2011 \n", + "\n", + " Runtime (Minutes) Rating Votes Revenue (Millions) Metascore Bin \\\n", + "230 118 8.2 498879 37.62 9.8 cat_4 \n", + "861 129 8.4 2421 NaN 8.0 cat_2 \n", + "611 162 7.6 24387 1.48 9.3 cat_3 \n", + "54 152 9.0 1791916 533.32 8.2 cat_5 \n", + "184 124 8.0 22389 3.40 8.5 cat_3 \n", + ".. ... ... ... ... ... ... \n", + "967 123 7.3 92378 10.14 NaN cat_3 \n", + "969 150 6.5 190855 89.29 NaN cat_4 \n", + "971 105 6.9 193491 80.05 NaN cat_4 \n", + "989 128 7.5 67637 52.07 NaN cat_3 \n", + "992 97 6.3 45419 6.92 NaN cat_3 \n", + "\n", + " Revenue per Minute New Rating Is Prime? Average_Rating Rating_Votes \\\n", + "230 0.318814 8.2 False 9.00 7.2 \n", + "861 NaN 8.4 False 8.20 9.4 \n", + "611 0.009136 6.6 False 8.45 8.6 \n", + "54 3.508684 9.0 False 8.60 8.0 \n", + "184 0.027419 9.0 False 8.25 9.0 \n", + ".. ... ... ... ... ... \n", + "967 0.082439 7.3 False NaN 6.3 \n", + "969 0.595267 6.5 False NaN 5.5 \n", + "971 0.762381 7.9 False NaN 5.9 \n", + "989 0.406797 7.5 False NaN 6.5 \n", + "992 0.071340 5.3 False NaN 5.3 \n", + "\n", + " Final_Rating \n", + "230 8.5500 \n", + "861 8.5000 \n", + "611 8.4875 \n", + "54 8.4500 \n", + "184 8.4375 \n", + ".. ... \n", + "967 NaN \n", + "969 NaN \n", + "971 NaN \n", + "989 NaN \n", + "992 NaN \n", + "\n", + "[1000 rows x 19 columns]" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.sort_values(by = \"Final_Rating\", ascending=False)" + ] + }, + { + "cell_type": "markdown", + "id": "a9f9aeb5", + "metadata": {}, + "source": [ + "## Bonus Challenge. Freaky bonus" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "id": "9ef24eee", + "metadata": {}, + "outputs": [], + "source": [ + "def sum_numbers(column, revenue, votes):\n", + " nums = []\n", + " for i in column:\n", + " if i.isdigit() == True:\n", + " nums.append(int(i))\n", + " if sum(nums) >= revenue and sum(nums) <= votes:\n", + " return f\"It has a hidden pattern\"\n", + " else:\n", + " return f\"There is no hidden pattern here...\"" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "id": "e486f834", + "metadata": {}, + "outputs": [], + "source": [ + "df[\"Hidden_Patterns\"] = df.apply(lambda x: sum_numbers(x[\"Description\"], x[\"Revenue (Millions)\"], x[\"Votes\"]), axis = 1)" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "id": "adee4cd5", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
RankTitleGenreDescriptionDirectorActorsYearRuntime (Minutes)RatingVotesRevenue (Millions)MetascoreBinRevenue per MinuteNew RatingIs Prime?Average_RatingRating_VotesFinal_RatingHidden_Patterns
01Guardians of the GalaxyAction,Adventure,Sci-FiA group of intergalactic criminals are forced ...James GunnChris Pratt, Vin Diesel, Bradley Cooper, Zoe S...20141218.1757074333.137.6cat_42.7531408.1False7.857.17.6625There is no hidden pattern here...
12PrometheusAdventure,Mystery,Sci-FiFollowing clues to the origin of mankind, a te...Ridley ScottNoomi Rapace, Logan Marshall-Green, Michael Fa...20121247.0485820126.466.5cat_41.0198397.0False6.756.06.5625There is no hidden pattern here...
23SplitHorror,ThrillerThree girls are kidnapped by a man with a diag...M. Night ShyamalanJames McAvoy, Anya Taylor-Joy, Haley Lu Richar...20161177.3157606138.126.2cat_41.1805138.3False6.756.36.6375There is no hidden pattern here...
34SingAnimation,Comedy,FamilyIn a city of humanoid animals, a hustling thea...Christophe LourdeletMatthew McConaughey,Reese Witherspoon, Seth Ma...20161087.260545270.325.9cat_32.5029636.2False6.556.26.4625There is no hidden pattern here...
45Suicide SquadAction,Adventure,FantasyA secret government agency recruits some of th...David AyerWill Smith, Jared Leto, Margot Robbie, Viola D...20161236.2393727325.024.0cat_42.6424396.2False5.105.25.1250There is no hidden pattern here...
...............................................................
995996Secret in Their EyesCrime,Drama,MysteryA tight-knit team of rising investigators, alo...Billy RayChiwetel Ejiofor, Nicole Kidman, Julia Roberts...20151116.227585NaN4.5cat_3NaN6.2False5.357.25.8125There is no hidden pattern here...
996997Hostel: Part IIHorrorThree American college students studying abroa...Eli RothLauren German, Heather Matarazzo, Bijou Philli...2007945.57315217.544.6cat_30.1865965.5False5.054.54.9125There is no hidden pattern here...
997998Step Up 2: The StreetsDrama,Music,RomanceRomantic sparks occur between two dance studen...Jon M. ChuRobert Hoffman, Briana Evigan, Cassie Ventura,...2008986.27069958.015.0cat_30.5919396.2False5.605.25.5000There is no hidden pattern here...
998999Search PartyAdventure,ComedyA pair of friends embark on a mission to reuni...Scot ArmstrongAdam Pally, T.J. Miller, Thomas Middleditch,Sh...2014935.64881NaN2.2cat_2NaN4.6False3.906.64.5750There is no hidden pattern here...
9991000Nine LivesComedy,Family,FantasyA stuffy businessman finds himself trapped ins...Barry SonnenfeldKevin Spacey, Jennifer Garner, Robbie Amell,Ch...2016875.31243519.641.1cat_30.2257474.3False3.206.33.9750There is no hidden pattern here...
\n", + "

1000 rows × 20 columns

\n", + "
" + ], + "text/plain": [ + " Rank Title Genre \\\n", + "0 1 Guardians of the Galaxy Action,Adventure,Sci-Fi \n", + "1 2 Prometheus Adventure,Mystery,Sci-Fi \n", + "2 3 Split Horror,Thriller \n", + "3 4 Sing Animation,Comedy,Family \n", + "4 5 Suicide Squad Action,Adventure,Fantasy \n", + ".. ... ... ... \n", + "995 996 Secret in Their Eyes Crime,Drama,Mystery \n", + "996 997 Hostel: Part II Horror \n", + "997 998 Step Up 2: The Streets Drama,Music,Romance \n", + "998 999 Search Party Adventure,Comedy \n", + "999 1000 Nine Lives Comedy,Family,Fantasy \n", + "\n", + " Description Director \\\n", + "0 A group of intergalactic criminals are forced ... James Gunn \n", + "1 Following clues to the origin of mankind, a te... Ridley Scott \n", + "2 Three girls are kidnapped by a man with a diag... M. Night Shyamalan \n", + "3 In a city of humanoid animals, a hustling thea... Christophe Lourdelet \n", + "4 A secret government agency recruits some of th... David Ayer \n", + ".. ... ... \n", + "995 A tight-knit team of rising investigators, alo... Billy Ray \n", + "996 Three American college students studying abroa... Eli Roth \n", + "997 Romantic sparks occur between two dance studen... Jon M. Chu \n", + "998 A pair of friends embark on a mission to reuni... Scot Armstrong \n", + "999 A stuffy businessman finds himself trapped ins... Barry Sonnenfeld \n", + "\n", + " Actors Year \\\n", + "0 Chris Pratt, Vin Diesel, Bradley Cooper, Zoe S... 2014 \n", + "1 Noomi Rapace, Logan Marshall-Green, Michael Fa... 2012 \n", + "2 James McAvoy, Anya Taylor-Joy, Haley Lu Richar... 2016 \n", + "3 Matthew McConaughey,Reese Witherspoon, Seth Ma... 2016 \n", + "4 Will Smith, Jared Leto, Margot Robbie, Viola D... 2016 \n", + ".. ... ... \n", + "995 Chiwetel Ejiofor, Nicole Kidman, Julia Roberts... 2015 \n", + "996 Lauren German, Heather Matarazzo, Bijou Philli... 2007 \n", + "997 Robert Hoffman, Briana Evigan, Cassie Ventura,... 2008 \n", + "998 Adam Pally, T.J. Miller, Thomas Middleditch,Sh... 2014 \n", + "999 Kevin Spacey, Jennifer Garner, Robbie Amell,Ch... 2016 \n", + "\n", + " Runtime (Minutes) Rating Votes Revenue (Millions) Metascore Bin \\\n", + "0 121 8.1 757074 333.13 7.6 cat_4 \n", + "1 124 7.0 485820 126.46 6.5 cat_4 \n", + "2 117 7.3 157606 138.12 6.2 cat_4 \n", + "3 108 7.2 60545 270.32 5.9 cat_3 \n", + "4 123 6.2 393727 325.02 4.0 cat_4 \n", + ".. ... ... ... ... ... ... \n", + "995 111 6.2 27585 NaN 4.5 cat_3 \n", + "996 94 5.5 73152 17.54 4.6 cat_3 \n", + "997 98 6.2 70699 58.01 5.0 cat_3 \n", + "998 93 5.6 4881 NaN 2.2 cat_2 \n", + "999 87 5.3 12435 19.64 1.1 cat_3 \n", + "\n", + " Revenue per Minute New Rating Is Prime? Average_Rating Rating_Votes \\\n", + "0 2.753140 8.1 False 7.85 7.1 \n", + "1 1.019839 7.0 False 6.75 6.0 \n", + "2 1.180513 8.3 False 6.75 6.3 \n", + "3 2.502963 6.2 False 6.55 6.2 \n", + "4 2.642439 6.2 False 5.10 5.2 \n", + ".. ... ... ... ... ... \n", + "995 NaN 6.2 False 5.35 7.2 \n", + "996 0.186596 5.5 False 5.05 4.5 \n", + "997 0.591939 6.2 False 5.60 5.2 \n", + "998 NaN 4.6 False 3.90 6.6 \n", + "999 0.225747 4.3 False 3.20 6.3 \n", + "\n", + " Final_Rating Hidden_Patterns \n", + "0 7.6625 There is no hidden pattern here... \n", + "1 6.5625 There is no hidden pattern here... \n", + "2 6.6375 There is no hidden pattern here... \n", + "3 6.4625 There is no hidden pattern here... \n", + "4 5.1250 There is no hidden pattern here... \n", + ".. ... ... \n", + "995 5.8125 There is no hidden pattern here... \n", + "996 4.9125 There is no hidden pattern here... \n", + "997 5.5000 There is no hidden pattern here... \n", + "998 4.5750 There is no hidden pattern here... \n", + "999 3.9750 There is no hidden pattern here... \n", + "\n", + "[1000 rows x 20 columns]" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "id": "39efeacf", + "metadata": {}, + "outputs": [], + "source": [ + "movies_with_hidden_pattern = df[df[\"Hidden_Patterns\"] == \"It has a hidden pattern\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "id": "bdf8a8cf", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "8 The Lost City of Z\n", + "55 Silence\n", + "100 Legend\n", + "161 Free Fire\n", + "186 Billy Lynn's Long Halftime Walk\n", + "231 A Kind of Murder\n", + "247 20th Century Women\n", + "273 Sing Street\n", + "278 Everybody Wants Some!!\n", + "288 Masterminds\n", + "305 Inherent Vice\n", + "353 Café Society\n", + "392 Steve Jobs\n", + "471 Marie Antoinette\n", + "475 Eddie the Eagle\n", + "476 The Lives of Others\n", + "501 Carol\n", + "519 Half of a Yellow Sun\n", + "551 Loving\n", + "579 All Good Things\n", + "588 Sunshine\n", + "677 Love, Rosie\n", + "679 The Age of Shadows\n", + "810 Turbo Kid\n", + "823 Christine\n", + "866 Indignation\n", + "886 The Tree of Life\n", + "897 The Fall\n", + "949 Kicks\n", + "967 The Walk\n", + "Name: Title, dtype: object" + ] + }, + "execution_count": 49, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "movies_with_hidden_pattern[\"Title\"]" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python (jupyter_env)", + "language": "python", + "name": "jupyter_env" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/notebooks/your_code_here.ipynb b/notebooks/your_code_here.ipynb deleted file mode 100644 index f60a09e..0000000 --- a/notebooks/your_code_here.ipynb +++ /dev/null @@ -1,81 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "280006e6", - "metadata": {}, - "source": [ - "### Pandas Apply Lambda\n", - "\n", - "Always remember the Zen of Python!!!" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "id": "ace6da70", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "The Zen of Python, by Tim Peters\n", - "\n", - "Beautiful is better than ugly.\n", - "Explicit is better than implicit.\n", - "Simple is better than complex.\n", - "Complex is better than complicated.\n", - "Flat is better than nested.\n", - "Sparse is better than dense.\n", - "Readability counts.\n", - "Special cases aren't special enough to break the rules.\n", - "Although practicality beats purity.\n", - "Errors should never pass silently.\n", - "Unless explicitly silenced.\n", - "In the face of ambiguity, refuse the temptation to guess.\n", - "There should be one-- and preferably only one --obvious way to do it.\n", - "Although that way may not be obvious at first unless you're Dutch.\n", - "Now is better than never.\n", - "Although never is often better than *right* now.\n", - "If the implementation is hard to explain, it's a bad idea.\n", - "If the implementation is easy to explain, it may be a good idea.\n", - "Namespaces are one honking great idea -- let's do more of those!\n" - ] - } - ], - "source": [ - "import this" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "d3c3dd76", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python [conda env:.conda-m1_env]", - "language": "python", - "name": "conda-env-.conda-m1_env-py" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.9.16" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -}