From be5d0267969cf41d5fe07387ceed640e02fc4c84 Mon Sep 17 00:00:00 2001 From: martingonzalezr001 Date: Sun, 5 Jan 2025 12:17:24 +0100 Subject: [PATCH] Work-shop Ended --- notebooks/MyCodeHere.ipynb | 1415 ++++++++++++++++++++++++++++++++ notebooks/your_code_here.ipynb | 6 +- 2 files changed, 1418 insertions(+), 3 deletions(-) create mode 100644 notebooks/MyCodeHere.ipynb diff --git a/notebooks/MyCodeHere.ipynb b/notebooks/MyCodeHere.ipynb new file mode 100644 index 0000000..31783a3 --- /dev/null +++ b/notebooks/MyCodeHere.ipynb @@ -0,0 +1,1415 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "b5c4c78e-bc1e-4f4d-bbe7-7be6991f0c5e", + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "c4979952-9ec2-4466-9ab2-b0807a72b4d5", + "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", + "
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
.......................................
995996Secret in Their EyesCrime,Drama,MysteryA tight-knit team of rising investigators, alo...Billy RayChiwetel Ejiofor, Nicole Kidman, Julia Roberts...20151116.227585NaN45.0
996997Hostel: Part IIHorrorThree American college students studying abroa...Eli RothLauren German, Heather Matarazzo, Bijou Philli...2007945.57315217.5446.0
997998Step Up 2: The StreetsDrama,Music,RomanceRomantic sparks occur between two dance studen...Jon M. ChuRobert Hoffman, Briana Evigan, Cassie Ventura,...2008986.27069958.0150.0
998999Search PartyAdventure,ComedyA pair of friends embark on a mission to reuni...Scot ArmstrongAdam Pally, T.J. Miller, Thomas Middleditch,Sh...2014935.64881NaN22.0
9991000Nine LivesComedy,Family,FantasyA stuffy businessman finds himself trapped ins...Barry SonnenfeldKevin Spacey, Jennifer Garner, Robbie Amell,Ch...2016875.31243519.6411.0
\n", + "

1000 rows × 12 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 \n", + "0 121 8.1 757074 333.13 76.0 \n", + "1 124 7.0 485820 126.46 65.0 \n", + "2 117 7.3 157606 138.12 62.0 \n", + "3 108 7.2 60545 270.32 59.0 \n", + "4 123 6.2 393727 325.02 40.0 \n", + ".. ... ... ... ... ... \n", + "995 111 6.2 27585 NaN 45.0 \n", + "996 94 5.5 73152 17.54 46.0 \n", + "997 98 6.2 70699 58.01 50.0 \n", + "998 93 5.6 4881 NaN 22.0 \n", + "999 87 5.3 12435 19.64 11.0 \n", + "\n", + "[1000 rows x 12 columns]" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#Leer csv en workshop\n", + "df = pd.read_csv(\"../data/input/IMDB-Movie-Data.csv\")\n", + "df" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "4c55da98-764f-4589-a15a-d5e4731431ee", + "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.0cat4
12PrometheusAdventure,Mystery,Sci-FiFollowing clues to the origin of mankind, a te...Ridley ScottNoomi Rapace, Logan Marshall-Green, Michael Fa...20121247.0485820126.4665.0cat4
23SplitHorror,ThrillerThree girls are kidnapped by a man with a diag...M. Night ShyamalanJames McAvoy, Anya Taylor-Joy, Haley Lu Richar...20161177.3157606138.1262.0cat4
34SingAnimation,Comedy,FamilyIn a city of humanoid animals, a hustling thea...Christophe LourdeletMatthew McConaughey,Reese Witherspoon, Seth Ma...20161087.260545270.3259.0cat3
45Suicide SquadAction,Adventure,FantasyA secret government agency recruits some of th...David AyerWill Smith, Jared Leto, Margot Robbie, Viola D...20161236.2393727325.0240.0cat4
..........................................
995996Secret in Their EyesCrime,Drama,MysteryA tight-knit team of rising investigators, alo...Billy RayChiwetel Ejiofor, Nicole Kidman, Julia Roberts...20151116.227585NaN45.0cat3
996997Hostel: Part IIHorrorThree American college students studying abroa...Eli RothLauren German, Heather Matarazzo, Bijou Philli...2007945.57315217.5446.0cat3
997998Step Up 2: The StreetsDrama,Music,RomanceRomantic sparks occur between two dance studen...Jon M. ChuRobert Hoffman, Briana Evigan, Cassie Ventura,...2008986.27069958.0150.0cat3
998999Search PartyAdventure,ComedyA pair of friends embark on a mission to reuni...Scot ArmstrongAdam Pally, T.J. Miller, Thomas Middleditch,Sh...2014935.64881NaN22.0cat2
9991000Nine LivesComedy,Family,FantasyA stuffy businessman finds himself trapped ins...Barry SonnenfeldKevin Spacey, Jennifer Garner, Robbie Amell,Ch...2016875.31243519.6411.0cat3
\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 cat4 \n", + "1 124 7.0 485820 126.46 65.0 cat4 \n", + "2 117 7.3 157606 138.12 62.0 cat4 \n", + "3 108 7.2 60545 270.32 59.0 cat3 \n", + "4 123 6.2 393727 325.02 40.0 cat4 \n", + ".. ... ... ... ... ... ... \n", + "995 111 6.2 27585 NaN 45.0 cat3 \n", + "996 94 5.5 73152 17.54 46.0 cat3 \n", + "997 98 6.2 70699 58.01 50.0 cat3 \n", + "998 93 5.6 4881 NaN 22.0 cat2 \n", + "999 87 5.3 12435 19.64 11.0 cat3 \n", + "\n", + "[1000 rows x 13 columns]" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# We want to create bins of movies according to the number of votes they've received. For that matter, we will create a new column named 'bin' which will tag every movie as follow:\n", + "\n", + "# From 0 to 999 ==> 'cat_1'\n", + "# From 1000 to 9999 ==> 'cat_2'\n", + "# From 10000 to 99999 ==> 'cat_3'\n", + "# From 100000 to 999999 ==> 'cat_4'\n", + "# More than 1000000 ==> 'cat_5'\n", + "df[\"Bin\"] = df['Votes'].apply(lambda x: 'cat1' if x >= 0 and x <= 999 else\n", + " 'cat2' if x >= 1000 and x <= 9999 else\n", + " 'cat3' if x >= 10000 and x <= 99999 else\n", + " 'cat4' if x >= 100000 and x <= 999999 else\n", + " 'cat5' if x >= 1000000 else\n", + " 'undefined')\n", + "df" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "0f11ca68-bd04-447e-bb00-e0f10a7046c6", + "metadata": {}, + "outputs": [], + "source": [ + "# Challenge 2: We want to know how much is the revenue per minute for every movie.\n", + "def create_revenue_per_minute(revenue, minutes):\n", + " revenue_per_minute = revenue / minutes\n", + " return revenue_per_minute\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "59dbac93-1e57-42dd-9043-d1a896663561", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2.7531404958677688" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "create_revenue_per_minute(333.13,121)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "924e17c6-77ba-4bca-af84-cd5d3a1ca65a", + "metadata": {}, + "outputs": [], + "source": [ + "df[\"Revenue_per_Minute\"] = df.apply(lambda row: create_revenue_per_minute(row[\"Revenue (Millions)\"], row[\"Runtime (Minutes)\"]), axis=1)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "07050a9b-85f0-4254-b578-0305ad9ac7aa", + "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.0cat42.753140
12PrometheusAdventure,Mystery,Sci-FiFollowing clues to the origin of mankind, a te...Ridley ScottNoomi Rapace, Logan Marshall-Green, Michael Fa...20121247.0485820126.4665.0cat41.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.0cat41.180513
34SingAnimation,Comedy,FamilyIn a city of humanoid animals, a hustling thea...Christophe LourdeletMatthew McConaughey,Reese Witherspoon, Seth Ma...20161087.260545270.3259.0cat32.502963
45Suicide SquadAction,Adventure,FantasyA secret government agency recruits some of th...David AyerWill Smith, Jared Leto, Margot Robbie, Viola D...20161236.2393727325.0240.0cat42.642439
.............................................
995996Secret in Their EyesCrime,Drama,MysteryA tight-knit team of rising investigators, alo...Billy RayChiwetel Ejiofor, Nicole Kidman, Julia Roberts...20151116.227585NaN45.0cat3NaN
996997Hostel: Part IIHorrorThree American college students studying abroa...Eli RothLauren German, Heather Matarazzo, Bijou Philli...2007945.57315217.5446.0cat30.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.0cat30.591939
998999Search PartyAdventure,ComedyA pair of friends embark on a mission to reuni...Scot ArmstrongAdam Pally, T.J. Miller, Thomas Middleditch,Sh...2014935.64881NaN22.0cat2NaN
9991000Nine LivesComedy,Family,FantasyA stuffy businessman finds himself trapped ins...Barry SonnenfeldKevin Spacey, Jennifer Garner, Robbie Amell,Ch...2016875.31243519.6411.0cat30.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 cat4 \n", + "1 124 7.0 485820 126.46 65.0 cat4 \n", + "2 117 7.3 157606 138.12 62.0 cat4 \n", + "3 108 7.2 60545 270.32 59.0 cat3 \n", + "4 123 6.2 393727 325.02 40.0 cat4 \n", + ".. ... ... ... ... ... ... \n", + "995 111 6.2 27585 NaN 45.0 cat3 \n", + "996 94 5.5 73152 17.54 46.0 cat3 \n", + "997 98 6.2 70699 58.01 50.0 cat3 \n", + "998 93 5.6 4881 NaN 22.0 cat2 \n", + "999 87 5.3 12435 19.64 11.0 cat3 \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": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "121e9ae2-3b71-4795-a1c5-f2b3e7d93a59", + "metadata": {}, + "outputs": [], + "source": [ + "# Challenge 3 We want to create a new rating where we add 1 point if the genre is thriller but subtract 1 point if the genre is comedy.\n", + "\n", + "def new_rating(genre, rating):\n", + " new_rating = rating\n", + " if genre == \"Thriller\":\n", + " new_rating += 1\n", + " if genre == \"Comedy\":\n", + " new_rating -= 1\n", + " return new_rating\n", + " \n", + " \n" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "2739985c-aff8-4827-9d8e-1ea803963da8", + "metadata": {}, + "outputs": [], + "source": [ + "df[\"New_Rating\"] = df.apply(lambda row: new_rating(row[\"Genre\"], row[\"Rating\"]), axis = 1)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "a36d8f9a-c3f6-4f62-921e-d501dbf28ed4", + "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.0cat42.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.0cat41.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.0cat41.1805137.3
34SingAnimation,Comedy,FamilyIn a city of humanoid animals, a hustling thea...Christophe LourdeletMatthew McConaughey,Reese Witherspoon, Seth Ma...20161087.260545270.3259.0cat32.5029637.2
45Suicide SquadAction,Adventure,FantasyA secret government agency recruits some of th...David AyerWill Smith, Jared Leto, Margot Robbie, Viola D...20161236.2393727325.0240.0cat42.6424396.2
................................................
995996Secret in Their EyesCrime,Drama,MysteryA tight-knit team of rising investigators, alo...Billy RayChiwetel Ejiofor, Nicole Kidman, Julia Roberts...20151116.227585NaN45.0cat3NaN6.2
996997Hostel: Part IIHorrorThree American college students studying abroa...Eli RothLauren German, Heather Matarazzo, Bijou Philli...2007945.57315217.5446.0cat30.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.0cat30.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.0cat2NaN5.6
9991000Nine LivesComedy,Family,FantasyA stuffy businessman finds himself trapped ins...Barry SonnenfeldKevin Spacey, Jennifer Garner, Robbie Amell,Ch...2016875.31243519.6411.0cat30.2257475.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 cat4 \n", + "1 124 7.0 485820 126.46 65.0 cat4 \n", + "2 117 7.3 157606 138.12 62.0 cat4 \n", + "3 108 7.2 60545 270.32 59.0 cat3 \n", + "4 123 6.2 393727 325.02 40.0 cat4 \n", + ".. ... ... ... ... ... ... \n", + "995 111 6.2 27585 NaN 45.0 cat3 \n", + "996 94 5.5 73152 17.54 46.0 cat3 \n", + "997 98 6.2 70699 58.01 50.0 cat3 \n", + "998 93 5.6 4881 NaN 22.0 cat2 \n", + "999 87 5.3 12435 19.64 11.0 cat3 \n", + "\n", + " Revenue_per_Minute New_Rating \n", + "0 2.753140 8.1 \n", + "1 1.019839 7.0 \n", + "2 1.180513 7.3 \n", + "3 2.502963 7.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 5.6 \n", + "999 0.225747 5.3 \n", + "\n", + "[1000 rows x 15 columns]" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "id": "54e118f5-5fc5-4920-b5c6-f1188561d9e1", + "metadata": {}, + "outputs": [], + "source": [ + "# Challenge 4: We want to know whether the integer part of the number resulting from the sum of the ASCII value of every character of the movie title divided by the number of votes, is a prime number (remember that prime numbers are integers).\n", + "# Nueva columna: bool, lo que devuelva el booleano de si el resultado de la operacion es un numero primo o no\n", + "\n", + "\n", + "#Funcion que calcula la suma de los valores de cada caracter en codigo ascii de los titulos de las peliculas\n", + "def ascii_number(title,votes):\n", + " count = 0\n", + " ascii_code = [ord(char) for char in title]\n", + " for x in ascii_code: \n", + " count += x\n", + " return count\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "id": "a6f2d106-d0b1-4d72-8f0e-b3f24715ee34", + "metadata": {}, + "outputs": [], + "source": [ + "df['ASCII_sum']= df.apply(lambda row: ascii_number(row['Title'], row['Votes']), axis=1)" + ] + }, + { + "cell_type": "code", + "execution_count": 66, + "id": "0b80d615-f0db-4a40-b6f4-84ad99364530", + "metadata": {}, + "outputs": [], + "source": [ + "def prime_number(ascii_number,votes):\n", + " cociente = ascii_number / votes\n", + " return cociente" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "id": "84ee04be-a58f-4697-97da-9044cdf8ed0d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0 0.002866\n", + "1 0.002198\n", + "2 0.003325\n", + "3 0.006623\n", + "4 0.003180\n", + "5 0.022343\n", + "6 0.003066\n", + "7 0.333735\n", + "8 0.215220\n", + "9 0.005469\n", + "dtype: float64" + ] + }, + "execution_count": 68, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.apply(lambda row: prime_number(row['ASCII_sum'],row['Votes']),axis=1).head(10)\n", + "# Vemos que son todos decimales menores que 1" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8e98432e-4c49-46bf-aa72-f3e293e401a0", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python (m1)", + "language": "python", + "name": "m1" + }, + "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.15" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/notebooks/your_code_here.ipynb b/notebooks/your_code_here.ipynb index f60a09e..b6388aa 100644 --- a/notebooks/your_code_here.ipynb +++ b/notebooks/your_code_here.ipynb @@ -59,9 +59,9 @@ ], "metadata": { "kernelspec": { - "display_name": "Python [conda env:.conda-m1_env]", + "display_name": "Python 3 (ipykernel)", "language": "python", - "name": "conda-env-.conda-m1_env-py" + "name": "python3" }, "language_info": { "codemirror_mode": { @@ -73,7 +73,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.16" + "version": "3.10.14" } }, "nbformat": 4,