diff --git a/notebooks/your_code_here.ipynb b/notebooks/your_code_here.ipynb
index f60a09e..37518c6 100644
--- a/notebooks/your_code_here.ipynb
+++ b/notebooks/your_code_here.ipynb
@@ -50,18 +50,1384 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 13,
"id": "d3c3dd76",
"metadata": {},
"outputs": [],
- "source": []
+ "source": [
+ "import pandas as pd"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "6d0f75ab",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#CHALLENGE 1."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
+ "id": "537e20cf",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "df = pd.read_csv('../data/input/IMDB-Movie-Data.csv')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 15,
+ "id": "f0a7eba5",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Rank | \n",
+ " Title | \n",
+ " Genre | \n",
+ " Description | \n",
+ " Director | \n",
+ " Actors | \n",
+ " Year | \n",
+ " Runtime (Minutes) | \n",
+ " Rating | \n",
+ " Votes | \n",
+ " Revenue (Millions) | \n",
+ " Metascore | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 1 | \n",
+ " Guardians of the Galaxy | \n",
+ " Action,Adventure,Sci-Fi | \n",
+ " A group of intergalactic criminals are forced ... | \n",
+ " James Gunn | \n",
+ " Chris Pratt, Vin Diesel, Bradley Cooper, Zoe S... | \n",
+ " 2014 | \n",
+ " 121 | \n",
+ " 8.1 | \n",
+ " 757074 | \n",
+ " 333.13 | \n",
+ " 76.0 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 2 | \n",
+ " Prometheus | \n",
+ " Adventure,Mystery,Sci-Fi | \n",
+ " Following clues to the origin of mankind, a te... | \n",
+ " Ridley Scott | \n",
+ " Noomi Rapace, Logan Marshall-Green, Michael Fa... | \n",
+ " 2012 | \n",
+ " 124 | \n",
+ " 7.0 | \n",
+ " 485820 | \n",
+ " 126.46 | \n",
+ " 65.0 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 3 | \n",
+ " Split | \n",
+ " Horror,Thriller | \n",
+ " Three girls are kidnapped by a man with a diag... | \n",
+ " M. Night Shyamalan | \n",
+ " James McAvoy, Anya Taylor-Joy, Haley Lu Richar... | \n",
+ " 2016 | \n",
+ " 117 | \n",
+ " 7.3 | \n",
+ " 157606 | \n",
+ " 138.12 | \n",
+ " 62.0 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 4 | \n",
+ " Sing | \n",
+ " Animation,Comedy,Family | \n",
+ " In a city of humanoid animals, a hustling thea... | \n",
+ " Christophe Lourdelet | \n",
+ " Matthew McConaughey,Reese Witherspoon, Seth Ma... | \n",
+ " 2016 | \n",
+ " 108 | \n",
+ " 7.2 | \n",
+ " 60545 | \n",
+ " 270.32 | \n",
+ " 59.0 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 5 | \n",
+ " Suicide Squad | \n",
+ " Action,Adventure,Fantasy | \n",
+ " A secret government agency recruits some of th... | \n",
+ " David Ayer | \n",
+ " Will Smith, Jared Leto, Margot Robbie, Viola D... | \n",
+ " 2016 | \n",
+ " 123 | \n",
+ " 6.2 | \n",
+ " 393727 | \n",
+ " 325.02 | \n",
+ " 40.0 | \n",
+ "
\n",
+ " \n",
+ "
\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",
+ " 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",
+ " 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",
+ "\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 "
+ ]
+ },
+ "execution_count": 15,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df.head()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "id": "3a2bd0d8",
+ "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": 6,
+ "id": "6fd4470c",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Rank | \n",
+ " Year | \n",
+ " Runtime (Minutes) | \n",
+ " Rating | \n",
+ " Votes | \n",
+ " Revenue (Millions) | \n",
+ " Metascore | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | count | \n",
+ " 1000.000000 | \n",
+ " 1000.000000 | \n",
+ " 1000.000000 | \n",
+ " 1000.000000 | \n",
+ " 1.000000e+03 | \n",
+ " 872.000000 | \n",
+ " 936.000000 | \n",
+ "
\n",
+ " \n",
+ " | mean | \n",
+ " 500.500000 | \n",
+ " 2012.783000 | \n",
+ " 113.172000 | \n",
+ " 6.723200 | \n",
+ " 1.698083e+05 | \n",
+ " 82.956376 | \n",
+ " 58.985043 | \n",
+ "
\n",
+ " \n",
+ " | std | \n",
+ " 288.819436 | \n",
+ " 3.205962 | \n",
+ " 18.810908 | \n",
+ " 0.945429 | \n",
+ " 1.887626e+05 | \n",
+ " 103.253540 | \n",
+ " 17.194757 | \n",
+ "
\n",
+ " \n",
+ " | min | \n",
+ " 1.000000 | \n",
+ " 2006.000000 | \n",
+ " 66.000000 | \n",
+ " 1.900000 | \n",
+ " 6.100000e+01 | \n",
+ " 0.000000 | \n",
+ " 11.000000 | \n",
+ "
\n",
+ " \n",
+ " | 25% | \n",
+ " 250.750000 | \n",
+ " 2010.000000 | \n",
+ " 100.000000 | \n",
+ " 6.200000 | \n",
+ " 3.630900e+04 | \n",
+ " 13.270000 | \n",
+ " 47.000000 | \n",
+ "
\n",
+ " \n",
+ " | 50% | \n",
+ " 500.500000 | \n",
+ " 2014.000000 | \n",
+ " 111.000000 | \n",
+ " 6.800000 | \n",
+ " 1.107990e+05 | \n",
+ " 47.985000 | \n",
+ " 59.500000 | \n",
+ "
\n",
+ " \n",
+ " | 75% | \n",
+ " 750.250000 | \n",
+ " 2016.000000 | \n",
+ " 123.000000 | \n",
+ " 7.400000 | \n",
+ " 2.399098e+05 | \n",
+ " 113.715000 | \n",
+ " 72.000000 | \n",
+ "
\n",
+ " \n",
+ " | max | \n",
+ " 1000.000000 | \n",
+ " 2016.000000 | \n",
+ " 191.000000 | \n",
+ " 9.000000 | \n",
+ " 1.791916e+06 | \n",
+ " 936.630000 | \n",
+ " 100.000000 | \n",
+ "
\n",
+ " \n",
+ "
\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": 6,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df.describe()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "424fc906",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#Tenemos que hacer una función que coja el número de votos, e ir categorizando"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 18,
+ "id": "a78d0da7",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def categorize(votes):\n",
+ " if 0 <= votes <= 999:\n",
+ " return 'cat_1'\n",
+ " elif 1000 <= votes <= 9999:\n",
+ " return 'cat_2'\n",
+ " elif 10000 <= votes <= 99999:\n",
+ " return 'cat_3'\n",
+ " elif 100000 <= votes <= 999999:\n",
+ " return 'cat_4'\n",
+ " elif 1000000 <= votes:\n",
+ " return 'cat_5'"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "cae6a939",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#Añado una columna bin, esa columna bin será el resultado de aplicarle la función anterior a la columna Vote"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 20,
+ "id": "9e5246b0",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Rank | \n",
+ " Title | \n",
+ " Genre | \n",
+ " Description | \n",
+ " Director | \n",
+ " Actors | \n",
+ " Year | \n",
+ " Runtime (Minutes) | \n",
+ " Rating | \n",
+ " Votes | \n",
+ " Revenue (Millions) | \n",
+ " Metascore | \n",
+ " bin | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 1 | \n",
+ " Guardians of the Galaxy | \n",
+ " Action,Adventure,Sci-Fi | \n",
+ " A group of intergalactic criminals are forced ... | \n",
+ " James Gunn | \n",
+ " Chris Pratt, Vin Diesel, Bradley Cooper, Zoe S... | \n",
+ " 2014 | \n",
+ " 121 | \n",
+ " 8.1 | \n",
+ " 757074 | \n",
+ " 333.13 | \n",
+ " 76.0 | \n",
+ " cat_4 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 2 | \n",
+ " Prometheus | \n",
+ " Adventure,Mystery,Sci-Fi | \n",
+ " Following clues to the origin of mankind, a te... | \n",
+ " Ridley Scott | \n",
+ " Noomi Rapace, Logan Marshall-Green, Michael Fa... | \n",
+ " 2012 | \n",
+ " 124 | \n",
+ " 7.0 | \n",
+ " 485820 | \n",
+ " 126.46 | \n",
+ " 65.0 | \n",
+ " cat_4 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 3 | \n",
+ " Split | \n",
+ " Horror,Thriller | \n",
+ " Three girls are kidnapped by a man with a diag... | \n",
+ " M. Night Shyamalan | \n",
+ " James McAvoy, Anya Taylor-Joy, Haley Lu Richar... | \n",
+ " 2016 | \n",
+ " 117 | \n",
+ " 7.3 | \n",
+ " 157606 | \n",
+ " 138.12 | \n",
+ " 62.0 | \n",
+ " cat_4 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 4 | \n",
+ " Sing | \n",
+ " Animation,Comedy,Family | \n",
+ " In a city of humanoid animals, a hustling thea... | \n",
+ " Christophe Lourdelet | \n",
+ " Matthew McConaughey,Reese Witherspoon, Seth Ma... | \n",
+ " 2016 | \n",
+ " 108 | \n",
+ " 7.2 | \n",
+ " 60545 | \n",
+ " 270.32 | \n",
+ " 59.0 | \n",
+ " cat_3 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 5 | \n",
+ " Suicide Squad | \n",
+ " Action,Adventure,Fantasy | \n",
+ " A secret government agency recruits some of th... | \n",
+ " David Ayer | \n",
+ " Will Smith, Jared Leto, Margot Robbie, Viola D... | \n",
+ " 2016 | \n",
+ " 123 | \n",
+ " 6.2 | \n",
+ " 393727 | \n",
+ " 325.02 | \n",
+ " 40.0 | \n",
+ " cat_4 | \n",
+ "
\n",
+ " \n",
+ "
\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",
+ " 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",
+ " 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",
+ "\n",
+ " Rating Votes Revenue (Millions) Metascore bin \n",
+ "0 8.1 757074 333.13 76.0 cat_4 \n",
+ "1 7.0 485820 126.46 65.0 cat_4 \n",
+ "2 7.3 157606 138.12 62.0 cat_4 \n",
+ "3 7.2 60545 270.32 59.0 cat_3 \n",
+ "4 6.2 393727 325.02 40.0 cat_4 "
+ ]
+ },
+ "execution_count": 20,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df['bin'] = df.apply(lambda row: categorize(row[\"Votes\"]),axis=1)\n",
+ "df.head()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "bb73f66b",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#CHALLENGE 2."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 26,
+ "id": "7faa2178",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "df['revenue_per_minute'] = df.apply(lambda row: (row[\"Revenue (Millions)\"]/row[\"Runtime (Minutes)\"]),axis=1)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 27,
+ "id": "fd631fb9",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Rank | \n",
+ " Title | \n",
+ " Genre | \n",
+ " Description | \n",
+ " Director | \n",
+ " Actors | \n",
+ " Year | \n",
+ " Runtime (Minutes) | \n",
+ " Rating | \n",
+ " Votes | \n",
+ " Revenue (Millions) | \n",
+ " Metascore | \n",
+ " bin | \n",
+ " revenue_per_minute | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 1 | \n",
+ " Guardians of the Galaxy | \n",
+ " Action,Adventure,Sci-Fi | \n",
+ " A group of intergalactic criminals are forced ... | \n",
+ " James Gunn | \n",
+ " Chris Pratt, Vin Diesel, Bradley Cooper, Zoe S... | \n",
+ " 2014 | \n",
+ " 121 | \n",
+ " 8.1 | \n",
+ " 757074 | \n",
+ " 333.13 | \n",
+ " 76.0 | \n",
+ " cat_4 | \n",
+ " 2.753140 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 2 | \n",
+ " Prometheus | \n",
+ " Adventure,Mystery,Sci-Fi | \n",
+ " Following clues to the origin of mankind, a te... | \n",
+ " Ridley Scott | \n",
+ " Noomi Rapace, Logan Marshall-Green, Michael Fa... | \n",
+ " 2012 | \n",
+ " 124 | \n",
+ " 7.0 | \n",
+ " 485820 | \n",
+ " 126.46 | \n",
+ " 65.0 | \n",
+ " cat_4 | \n",
+ " 1.019839 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 3 | \n",
+ " Split | \n",
+ " Horror,Thriller | \n",
+ " Three girls are kidnapped by a man with a diag... | \n",
+ " M. Night Shyamalan | \n",
+ " James McAvoy, Anya Taylor-Joy, Haley Lu Richar... | \n",
+ " 2016 | \n",
+ " 117 | \n",
+ " 7.3 | \n",
+ " 157606 | \n",
+ " 138.12 | \n",
+ " 62.0 | \n",
+ " cat_4 | \n",
+ " 1.180513 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 4 | \n",
+ " Sing | \n",
+ " Animation,Comedy,Family | \n",
+ " In a city of humanoid animals, a hustling thea... | \n",
+ " Christophe Lourdelet | \n",
+ " Matthew McConaughey,Reese Witherspoon, Seth Ma... | \n",
+ " 2016 | \n",
+ " 108 | \n",
+ " 7.2 | \n",
+ " 60545 | \n",
+ " 270.32 | \n",
+ " 59.0 | \n",
+ " cat_3 | \n",
+ " 2.502963 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 5 | \n",
+ " Suicide Squad | \n",
+ " Action,Adventure,Fantasy | \n",
+ " A secret government agency recruits some of th... | \n",
+ " David Ayer | \n",
+ " Will Smith, Jared Leto, Margot Robbie, Viola D... | \n",
+ " 2016 | \n",
+ " 123 | \n",
+ " 6.2 | \n",
+ " 393727 | \n",
+ " 325.02 | \n",
+ " 40.0 | \n",
+ " cat_4 | \n",
+ " 2.642439 | \n",
+ "
\n",
+ " \n",
+ "
\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",
+ " 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",
+ " 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",
+ "\n",
+ " Rating Votes Revenue (Millions) Metascore bin revenue_per_minute \n",
+ "0 8.1 757074 333.13 76.0 cat_4 2.753140 \n",
+ "1 7.0 485820 126.46 65.0 cat_4 1.019839 \n",
+ "2 7.3 157606 138.12 62.0 cat_4 1.180513 \n",
+ "3 7.2 60545 270.32 59.0 cat_3 2.502963 \n",
+ "4 6.2 393727 325.02 40.0 cat_4 2.642439 "
+ ]
+ },
+ "execution_count": 27,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df.head()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "b70610d7",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#CHALLENGE 3."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 17,
+ "id": "caca7e6d",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def check_genre(genre,rating):\n",
+ " if 'Thriller' in genre:\n",
+ " return rating + 1\n",
+ " elif 'Comedy' in genre:\n",
+ " return rating - 1\n",
+ " else:\n",
+ " return rating"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 18,
+ "id": "be636747",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "df['__new rating__'] = df.apply(lambda row: check_genre(row[\"Genre\"],row[\"Rating\"]),axis=1)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 19,
+ "id": "aa83c2f0",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Rank | \n",
+ " Title | \n",
+ " Genre | \n",
+ " Description | \n",
+ " Director | \n",
+ " Actors | \n",
+ " Year | \n",
+ " Runtime (Minutes) | \n",
+ " Rating | \n",
+ " Votes | \n",
+ " Revenue (Millions) | \n",
+ " Metascore | \n",
+ " __new rating__ | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 1 | \n",
+ " Guardians of the Galaxy | \n",
+ " Action,Adventure,Sci-Fi | \n",
+ " A group of intergalactic criminals are forced ... | \n",
+ " James Gunn | \n",
+ " Chris Pratt, Vin Diesel, Bradley Cooper, Zoe S... | \n",
+ " 2014 | \n",
+ " 121 | \n",
+ " 8.1 | \n",
+ " 757074 | \n",
+ " 333.13 | \n",
+ " 76.0 | \n",
+ " 8.1 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 2 | \n",
+ " Prometheus | \n",
+ " Adventure,Mystery,Sci-Fi | \n",
+ " Following clues to the origin of mankind, a te... | \n",
+ " Ridley Scott | \n",
+ " Noomi Rapace, Logan Marshall-Green, Michael Fa... | \n",
+ " 2012 | \n",
+ " 124 | \n",
+ " 7.0 | \n",
+ " 485820 | \n",
+ " 126.46 | \n",
+ " 65.0 | \n",
+ " 7.0 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 3 | \n",
+ " Split | \n",
+ " Horror,Thriller | \n",
+ " Three girls are kidnapped by a man with a diag... | \n",
+ " M. Night Shyamalan | \n",
+ " James McAvoy, Anya Taylor-Joy, Haley Lu Richar... | \n",
+ " 2016 | \n",
+ " 117 | \n",
+ " 7.3 | \n",
+ " 157606 | \n",
+ " 138.12 | \n",
+ " 62.0 | \n",
+ " 8.3 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 4 | \n",
+ " Sing | \n",
+ " Animation,Comedy,Family | \n",
+ " In a city of humanoid animals, a hustling thea... | \n",
+ " Christophe Lourdelet | \n",
+ " Matthew McConaughey,Reese Witherspoon, Seth Ma... | \n",
+ " 2016 | \n",
+ " 108 | \n",
+ " 7.2 | \n",
+ " 60545 | \n",
+ " 270.32 | \n",
+ " 59.0 | \n",
+ " 6.2 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 5 | \n",
+ " Suicide Squad | \n",
+ " Action,Adventure,Fantasy | \n",
+ " A secret government agency recruits some of th... | \n",
+ " David Ayer | \n",
+ " Will Smith, Jared Leto, Margot Robbie, Viola D... | \n",
+ " 2016 | \n",
+ " 123 | \n",
+ " 6.2 | \n",
+ " 393727 | \n",
+ " 325.02 | \n",
+ " 40.0 | \n",
+ " 6.2 | \n",
+ "
\n",
+ " \n",
+ "
\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",
+ " 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",
+ " 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",
+ "\n",
+ " Rating Votes Revenue (Millions) Metascore __new rating__ \n",
+ "0 8.1 757074 333.13 76.0 8.1 \n",
+ "1 7.0 485820 126.46 65.0 7.0 \n",
+ "2 7.3 157606 138.12 62.0 8.3 \n",
+ "3 7.2 60545 270.32 59.0 6.2 \n",
+ "4 6.2 393727 325.02 40.0 6.2 "
+ ]
+ },
+ "execution_count": 19,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df.head()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "57653ca7",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#CHALLENGE 4."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 79,
+ "id": "6add83ea",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#Función que saca los valores ASCII de un título - No me ha servido para la solución\n",
+ "list_empty = []\n",
+ "def ASCII_values(title):\n",
+ " for letter in title:\n",
+ " list_empty.append(ord(letter))\n",
+ " return list_empty\n",
+ "\n",
+ " #return sum(list_empty)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 81,
+ "id": "4a1e986a",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "[71,\n",
+ " 117,\n",
+ " 97,\n",
+ " 114,\n",
+ " 100,\n",
+ " 105,\n",
+ " 97,\n",
+ " 110,\n",
+ " 115,\n",
+ " 32,\n",
+ " 111,\n",
+ " 102,\n",
+ " 32,\n",
+ " 116,\n",
+ " 104,\n",
+ " 101,\n",
+ " 32,\n",
+ " 71,\n",
+ " 97,\n",
+ " 108,\n",
+ " 97,\n",
+ " 120,\n",
+ " 121,\n",
+ " 71,\n",
+ " 117,\n",
+ " 97,\n",
+ " 114,\n",
+ " 100,\n",
+ " 105,\n",
+ " 97,\n",
+ " 110,\n",
+ " 115,\n",
+ " 32,\n",
+ " 111,\n",
+ " 102,\n",
+ " 32,\n",
+ " 116,\n",
+ " 104,\n",
+ " 101,\n",
+ " 32,\n",
+ " 71,\n",
+ " 97,\n",
+ " 108,\n",
+ " 97,\n",
+ " 120,\n",
+ " 121]"
+ ]
+ },
+ "execution_count": 81,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "ASCII_values(\"Guardians of the Galaxy\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 77,
+ "id": "07eb8800",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#Función que suma los caracteres de los títulos - No me ha servido para la solución\n",
+ "def sum_ASCII_values(title):\n",
+ " list_empty = []\n",
+ " for letter in title:\n",
+ " list_empty.append(ord(letter))\n",
+ " return sum(list_empty)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 78,
+ "id": "880c5306",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "2170"
+ ]
+ },
+ "execution_count": 78,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "sum_ASCII_values(\"Guardians of the Galaxy\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 95,
+ "id": "d7e77e4f",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#Step 1 del ejercicio. Hacer la función que revise si la división pedida es prima o no, estando los dos argumentos ya preparados \n",
+ "def is_primo(titles,votes):\n",
+ " suma = sum(ord(letter) for letter in titles) #la suma de los caracteres \n",
+ " r = suma//votes #la división entera de esa suma por los votos\n",
+ " if r < 2:\n",
+ " return False\n",
+ " else:\n",
+ " if r == 2:\n",
+ " return True\n",
+ " else:\n",
+ " for i in range(2, r):\n",
+ " if r % i == 0:\n",
+ " return False\n",
+ " return True"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 96,
+ "id": "72f83cff",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "0 False\n",
+ "1 False\n",
+ "2 False\n",
+ "3 False\n",
+ "4 False\n",
+ " ... \n",
+ "995 False\n",
+ "996 False\n",
+ "997 False\n",
+ "998 False\n",
+ "999 False\n",
+ "Length: 1000, dtype: bool"
+ ]
+ },
+ "execution_count": 96,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "#Step 2 del ejercicio. Hacer un apply para aplicar la función de Step 1 a cada una de las columnas que corresponden.\n",
+ "df.apply(lambda row: is_primo(row[\"Title\"],row[\"Votes\"]),axis=1)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "f6b593ed",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#CHALLENGE 5."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 106,
+ "id": "2954eef5",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#Quiero hacer un nuevo rate que sube 10 puntos si en la peli aparece Will Smith, que sume 2 si dura menos de 120 minutos, y que no haga nada si no ocurren estas dos cosas.\n",
+ "\n",
+ "def own_rate(rating, actors, minutes):\n",
+ " if minutes < 120:\n",
+ " return rating + 2\n",
+ " elif 'Will Smith' in actors:\n",
+ " return rating + 10\n",
+ " else: \n",
+ " return rating"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 107,
+ "id": "4ea7de9c",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "df['own_rate'] = df.apply(lambda row: own_rate(row[\"Rating\"],row[\"Actors\"],row[\"Runtime (Minutes)\"]),axis=1)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 108,
+ "id": "5bea6064",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Rank | \n",
+ " Title | \n",
+ " Genre | \n",
+ " Description | \n",
+ " Director | \n",
+ " Actors | \n",
+ " Year | \n",
+ " Runtime (Minutes) | \n",
+ " Rating | \n",
+ " Votes | \n",
+ " Revenue (Millions) | \n",
+ " Metascore | \n",
+ " __new rating__ | \n",
+ " own_rate | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 1 | \n",
+ " Guardians of the Galaxy | \n",
+ " Action,Adventure,Sci-Fi | \n",
+ " A group of intergalactic criminals are forced ... | \n",
+ " James Gunn | \n",
+ " Chris Pratt, Vin Diesel, Bradley Cooper, Zoe S... | \n",
+ " 2014 | \n",
+ " 121 | \n",
+ " 8.1 | \n",
+ " 757074 | \n",
+ " 333.13 | \n",
+ " 76.0 | \n",
+ " 8.1 | \n",
+ " 8.1 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 2 | \n",
+ " Prometheus | \n",
+ " Adventure,Mystery,Sci-Fi | \n",
+ " Following clues to the origin of mankind, a te... | \n",
+ " Ridley Scott | \n",
+ " Noomi Rapace, Logan Marshall-Green, Michael Fa... | \n",
+ " 2012 | \n",
+ " 124 | \n",
+ " 7.0 | \n",
+ " 485820 | \n",
+ " 126.46 | \n",
+ " 65.0 | \n",
+ " 7.0 | \n",
+ " 7.0 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 3 | \n",
+ " Split | \n",
+ " Horror,Thriller | \n",
+ " Three girls are kidnapped by a man with a diag... | \n",
+ " M. Night Shyamalan | \n",
+ " James McAvoy, Anya Taylor-Joy, Haley Lu Richar... | \n",
+ " 2016 | \n",
+ " 117 | \n",
+ " 7.3 | \n",
+ " 157606 | \n",
+ " 138.12 | \n",
+ " 62.0 | \n",
+ " 8.3 | \n",
+ " 9.3 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 4 | \n",
+ " Sing | \n",
+ " Animation,Comedy,Family | \n",
+ " In a city of humanoid animals, a hustling thea... | \n",
+ " Christophe Lourdelet | \n",
+ " Matthew McConaughey,Reese Witherspoon, Seth Ma... | \n",
+ " 2016 | \n",
+ " 108 | \n",
+ " 7.2 | \n",
+ " 60545 | \n",
+ " 270.32 | \n",
+ " 59.0 | \n",
+ " 6.2 | \n",
+ " 9.2 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 5 | \n",
+ " Suicide Squad | \n",
+ " Action,Adventure,Fantasy | \n",
+ " A secret government agency recruits some of th... | \n",
+ " David Ayer | \n",
+ " Will Smith, Jared Leto, Margot Robbie, Viola D... | \n",
+ " 2016 | \n",
+ " 123 | \n",
+ " 6.2 | \n",
+ " 393727 | \n",
+ " 325.02 | \n",
+ " 40.0 | \n",
+ " 6.2 | \n",
+ " 16.2 | \n",
+ "
\n",
+ " \n",
+ "
\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",
+ " 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",
+ " 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",
+ "\n",
+ " Rating Votes Revenue (Millions) Metascore __new rating__ own_rate \n",
+ "0 8.1 757074 333.13 76.0 8.1 8.1 \n",
+ "1 7.0 485820 126.46 65.0 7.0 7.0 \n",
+ "2 7.3 157606 138.12 62.0 8.3 9.3 \n",
+ "3 7.2 60545 270.32 59.0 6.2 9.2 \n",
+ "4 6.2 393727 325.02 40.0 6.2 16.2 "
+ ]
+ },
+ "execution_count": 108,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df.head()"
+ ]
}
],
"metadata": {
"kernelspec": {
- "display_name": "Python [conda env:.conda-m1_env]",
+ "display_name": "Python (m1_env)",
"language": "python",
- "name": "conda-env-.conda-m1_env-py"
+ "name": "m1_env"
},
"language_info": {
"codemirror_mode": {
@@ -73,7 +1439,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.9.16"
+ "version": "3.10.13"
}
},
"nbformat": 4,