{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## ![](https://ga-dash.s3.amazonaws.com/production/assets/logo-9f88ae6c9c3871690e33280fcf557f33.png) Pandas for EDA\n",
    "by [@josephofiowa](https://twitter.com/josephofiowa)\n",
    " \n",
    "<!---\n",
    "This assignment was developed by Joseph Nelson\n",
    "\n",
    "Questions? Comments?\n",
    "1. Log an issue to this repo to alert me of a problem.\n",
    "2. Suggest an edit yourself by forking this repo, making edits, and submitting a pull request with your changes back to our master branch.\n",
    "3. Hit me up on Slack @sonylnagale\n",
    "--->"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Pandas Unit Lab\n",
    "\n",
    "**Woo!** We've made it to the end of our Pandas Unit. Let's put our skills to the test.\n",
    "\n",
    "We're going to explore data from some of the top movies according to IMDB. This is a guided question-and-response lab where some areas are specific asks and others are open ended for you to explore.\n",
    "\n",
    "# Pandas Unit Lab\n",
    "\n",
    "**Woo!** We've made it to the end of our Pandas Unit. Let's put our skills to the test.\n",
    "\n",
    "We're going to explore data from some of the top movies according to IMDB. This is a guided question-and-response lab where some areas are specific asks and others are open ended for you to explore.\n",
    "\n",
    "#### Important!!!\n",
    "- <font color=\"red\">**There are two ways to do this lab!**</font>\n",
    "  - The first way is to read in a dataset that _has already been pulled from the API and cleaned for you_ (`movies_rated.csv`). This is the recommended 'first-pass' way to do this lab.\n",
    "  - _After you have completed the lab using the supplied_ `movies_rated.csv`, you can call the API yourself!\n",
    "  - Calling the API yourself takes time! Be prepared to parse lots of JSON, read docs, etc. Consider this a take-home exercise if the students desire.\n",
    "\n",
    "In this lab, we will:\n",
    "- Use `movie_app.py` to obtain relevant moving rating data\n",
    "- Leverage Pandas to conduct exploratory data analysis, including:\n",
    "    - Assess data integrity\n",
    "    - Create exploratory visualizations\n",
    "    - Produce insights on top actors/actresses across films\n",
    "    \n",
    "Let's get going!\n",
    "\n",
    "In this lab, we will:\n",
    "- Use `movie_app.py` to obtain relevant moving rating data\n",
    "- Leverage Pandas to conduct exploratory data analysis, including:\n",
    "    - Assess data integrity\n",
    "    - Create exploratory visualizations\n",
    "    - Produce insights on top actors/actresses across films\n",
    "    \n",
    "Let's get going!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## The Dataset\n",
    "\n",
    "We'll work with a dataset on the top [IMDB movies](https://www.imdb.com/search/title?count=100&groups=top_1000&sort=user_rating), as rated by IMDB.\n",
    "\n",
    "\n",
    "Specifically, we have a CSV that contains:\n",
    "- IMDB star rating\n",
    "- Movie title\n",
    "- Year\n",
    "- Content rating\n",
    "- Genre\n",
    "- Duration\n",
    "- Gross\n",
    "\n",
    "_[Details available at the above link]_\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Import our necessary libraries"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib as plt\n",
    "import re\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Read in the dataset\n",
    "\n",
    "First, read in the dataset, called `movies.csv` into a DataFrame called \"movies.\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "movies = pd.read_csv('./data/movies.csv')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Check the dataset basics\n",
    "\n",
    "Let's first explore our dataset to verify we have what we expect."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Print the first five rows."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "      <th>content_rating</th>\n",
       "      <th>genre</th>\n",
       "      <th>duration</th>\n",
       "      <th>gross</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>The Shawshank Redemption</td>\n",
       "      <td>1994</td>\n",
       "      <td>R</td>\n",
       "      <td>Drama</td>\n",
       "      <td>142</td>\n",
       "      <td>1963330</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>The Godfather</td>\n",
       "      <td>1972</td>\n",
       "      <td>R</td>\n",
       "      <td>Crime</td>\n",
       "      <td>175</td>\n",
       "      <td>28341469</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>The Dark Knight</td>\n",
       "      <td>2008</td>\n",
       "      <td>PG-13</td>\n",
       "      <td>Action</td>\n",
       "      <td>152</td>\n",
       "      <td>1344258</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>The Godfather: Part II</td>\n",
       "      <td>1974</td>\n",
       "      <td>R</td>\n",
       "      <td>Crime</td>\n",
       "      <td>202</td>\n",
       "      <td>134966411</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Pulp Fiction</td>\n",
       "      <td>1994</td>\n",
       "      <td>R</td>\n",
       "      <td>Crime</td>\n",
       "      <td>154</td>\n",
       "      <td>1935047</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                      title  year content_rating              genre  duration  \\\n",
       "0  The Shawshank Redemption  1994              R  Drama                   142   \n",
       "1             The Godfather  1972              R              Crime       175   \n",
       "2           The Dark Knight  2008          PG-13             Action       152   \n",
       "3    The Godfather: Part II  1974              R              Crime       202   \n",
       "4              Pulp Fiction  1994              R              Crime       154   \n",
       "\n",
       "       gross  \n",
       "0    1963330  \n",
       "1   28341469  \n",
       "2    1344258  \n",
       "3  134966411  \n",
       "4    1935047  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movies.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "How many rows and columns are in the datset?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(79, 6)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movies.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "What are the column names?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Index(['title', 'year', 'content_rating', 'genre', 'duration', 'gross'], dtype='object')\n"
     ]
    }
   ],
   "source": [
    "print(movies.columns)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "How many unique genres are there?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movies['genre'].nunique()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "How many movies are there per genre?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Crime                  16\n",
       "Drama                  14\n",
       "Action                 11\n",
       "Adventure               9\n",
       "Drama                   7\n",
       "Biography               5\n",
       "Animation               5\n",
       "Comedy                  4\n",
       "Western                 3\n",
       "Mystery                 2\n",
       "Horror                  2\n",
       "Comedy                  1\n",
       "Name: genre, dtype: int64"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movies['genre'].value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Only run the below cells if you've obtained an [API key!](http://www.omdbapi.com/apikey.aspx)<br>Otherwise, proceed to the `importing movies_rated.csv` section below."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Obtain more data (with an API call)!\n",
    "\n",
    "- Let's take advantage of our `OmdbAPI` module (stored in `./OmdbAPI.py`, if you'd like to look under the hood) to obtain data from OMDB API on movie ratings. This will enable us to answer the question: **How do other publication's scores compare to IMDB ratings?** Specifically, where do Rotten Tomato critics most disagree with IMDB reviews? \n",
    "- Using the OmdbAPI module, we will obtain the `Internet Movie Database`, the `Rotten Tomatoes`, and the `Metacritic` reviews on the top rated IMDB movies. We will store these ratings in new columns in a new `movies_rated` DataFrame. We have also stored the file locally at `./data/movies_rated.csv`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "import OmdbAPI"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "# replace e54ad9e7 with your API key\n",
    "# this may take a minute\n",
    "movies_rated = OmdbAPI.Omdb(movies, 'e54ad9e7').get_ratings()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "      <th>content_rating</th>\n",
       "      <th>genre</th>\n",
       "      <th>duration</th>\n",
       "      <th>gross</th>\n",
       "      <th>Internet Movie Database</th>\n",
       "      <th>Rotten Tomatoes</th>\n",
       "      <th>Metacritic</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>The Shawshank Redemption</td>\n",
       "      <td>1994</td>\n",
       "      <td>R</td>\n",
       "      <td>Drama</td>\n",
       "      <td>142</td>\n",
       "      <td>1963330</td>\n",
       "      <td>9.3/10</td>\n",
       "      <td>91%</td>\n",
       "      <td>80/100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>The Godfather</td>\n",
       "      <td>1972</td>\n",
       "      <td>R</td>\n",
       "      <td>Crime</td>\n",
       "      <td>175</td>\n",
       "      <td>28341469</td>\n",
       "      <td>9.2/10</td>\n",
       "      <td>98%</td>\n",
       "      <td>100/100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>The Dark Knight</td>\n",
       "      <td>2008</td>\n",
       "      <td>PG-13</td>\n",
       "      <td>Action</td>\n",
       "      <td>152</td>\n",
       "      <td>1344258</td>\n",
       "      <td>9.0/10</td>\n",
       "      <td>94%</td>\n",
       "      <td>82/100</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                      title  year content_rating              genre  duration  \\\n",
       "0  The Shawshank Redemption  1994              R  Drama                   142   \n",
       "1             The Godfather  1972              R              Crime       175   \n",
       "2           The Dark Knight  2008          PG-13             Action       152   \n",
       "\n",
       "      gross Internet Movie Database Rotten Tomatoes Metacritic  \n",
       "0   1963330                  9.3/10             91%     80/100  \n",
       "1  28341469                  9.2/10             98%    100/100  \n",
       "2   1344258                  9.0/10             94%     82/100  "
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movies_rated.head(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Just in case there were movies that the API was unable to get, let's drop nulls."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "movies_rated.dropna(inplace=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's get the ratings in the same float format using an apply function with some regular expressions. Note the use of .copy() when writing and reading from the same dataframe as a best practice."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "      <th>content_rating</th>\n",
       "      <th>genre</th>\n",
       "      <th>duration</th>\n",
       "      <th>gross</th>\n",
       "      <th>Internet Movie Database</th>\n",
       "      <th>Rotten Tomatoes</th>\n",
       "      <th>Metacritic</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>The Shawshank Redemption</td>\n",
       "      <td>1994</td>\n",
       "      <td>R</td>\n",
       "      <td>Drama</td>\n",
       "      <td>142</td>\n",
       "      <td>1963330</td>\n",
       "      <td>9.3</td>\n",
       "      <td>9.1</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>The Godfather</td>\n",
       "      <td>1972</td>\n",
       "      <td>R</td>\n",
       "      <td>Crime</td>\n",
       "      <td>175</td>\n",
       "      <td>28341469</td>\n",
       "      <td>9.2</td>\n",
       "      <td>9.8</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>The Dark Knight</td>\n",
       "      <td>2008</td>\n",
       "      <td>PG-13</td>\n",
       "      <td>Action</td>\n",
       "      <td>152</td>\n",
       "      <td>1344258</td>\n",
       "      <td>9.0</td>\n",
       "      <td>9.4</td>\n",
       "      <td>8.2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                      title  year content_rating              genre  duration  \\\n",
       "0  The Shawshank Redemption  1994              R  Drama                   142   \n",
       "1             The Godfather  1972              R              Crime       175   \n",
       "2           The Dark Knight  2008          PG-13             Action       152   \n",
       "\n",
       "      gross  Internet Movie Database  Rotten Tomatoes  Metacritic  \n",
       "0   1963330                      9.3              9.1         8.0  \n",
       "1  28341469                      9.2              9.8        10.0  \n",
       "2   1344258                      9.0              9.4         8.2  "
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movies_rated['Rotten Tomatoes'] = movies_rated['Rotten Tomatoes'].copy().apply(lambda x: float(re.match('\\d{1,}', x)[0])/10)\n",
    "movies_rated['Internet Movie Database'] = movies_rated['Internet Movie Database'].copy().apply(lambda x: float(re.match('(\\S+)\\/', x)[1]))\n",
    "movies_rated['Metacritic'] = movies_rated['Metacritic'].copy().apply(lambda x: float(re.match('(\\S+)\\/', x)[1])/10)\n",
    "movies_rated.head(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Finally, let's write the cleaned result to a local file so we don't have to call the API again and risk exceeding our daily limit."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "movies_rated.to_csv('./movies_rated.csv', index=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Importing `movies_rated.csv`\n",
    "\n",
    "If you just called the API in the previous section, you can skip this and proceed to the `exploratory data analysis` section."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's read in the cleaned, rated `movies_rated.csv` file, which was included with this repo just in case you couldn't call the API."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "      <th>content_rating</th>\n",
       "      <th>genre</th>\n",
       "      <th>duration</th>\n",
       "      <th>gross</th>\n",
       "      <th>Internet Movie Database</th>\n",
       "      <th>Rotten Tomatoes</th>\n",
       "      <th>Metacritic</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>The Shawshank Redemption</td>\n",
       "      <td>1994</td>\n",
       "      <td>R</td>\n",
       "      <td>Drama</td>\n",
       "      <td>142</td>\n",
       "      <td>1963330</td>\n",
       "      <td>9.3</td>\n",
       "      <td>9.1</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>The Godfather</td>\n",
       "      <td>1972</td>\n",
       "      <td>R</td>\n",
       "      <td>Crime</td>\n",
       "      <td>175</td>\n",
       "      <td>28341469</td>\n",
       "      <td>9.2</td>\n",
       "      <td>9.8</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>The Dark Knight</td>\n",
       "      <td>2008</td>\n",
       "      <td>PG-13</td>\n",
       "      <td>Action</td>\n",
       "      <td>152</td>\n",
       "      <td>1344258</td>\n",
       "      <td>9.0</td>\n",
       "      <td>9.4</td>\n",
       "      <td>8.2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                      title  year content_rating              genre  duration  \\\n",
       "0  The Shawshank Redemption  1994              R  Drama                   142   \n",
       "1             The Godfather  1972              R              Crime       175   \n",
       "2           The Dark Knight  2008          PG-13             Action       152   \n",
       "\n",
       "      gross  Internet Movie Database  Rotten Tomatoes  Metacritic  \n",
       "0   1963330                      9.3              9.1         8.0  \n",
       "1  28341469                      9.2              9.8        10.0  \n",
       "2   1344258                      9.0              9.4         8.2  "
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movies_rated = pd.read_csv('./data/movies_rated.csv')\n",
    "movies_rated.head(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Check our datatypes. Notice anything potentially problematic?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "title                       object\n",
       "year                         int64\n",
       "content_rating              object\n",
       "genre                       object\n",
       "duration                     int64\n",
       "gross                        int64\n",
       "Internet Movie Database    float64\n",
       "Rotten Tomatoes            float64\n",
       "Metacritic                 float64\n",
       "dtype: object"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movies_rated.dtypes"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exploratory data analysis\n",
    "\n",
    "Let's transition to asking and answering some questions with our data."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "What are the top five R-Rated movies?\n",
    "\n",
    "*hint: Boolean filters needed! Then sorting!*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "      <th>content_rating</th>\n",
       "      <th>genre</th>\n",
       "      <th>duration</th>\n",
       "      <th>gross</th>\n",
       "      <th>Internet Movie Database</th>\n",
       "      <th>Rotten Tomatoes</th>\n",
       "      <th>Metacritic</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>The Shawshank Redemption</td>\n",
       "      <td>1994</td>\n",
       "      <td>R</td>\n",
       "      <td>Drama</td>\n",
       "      <td>142</td>\n",
       "      <td>1963330</td>\n",
       "      <td>9.3</td>\n",
       "      <td>9.1</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>The Godfather</td>\n",
       "      <td>1972</td>\n",
       "      <td>R</td>\n",
       "      <td>Crime</td>\n",
       "      <td>175</td>\n",
       "      <td>28341469</td>\n",
       "      <td>9.2</td>\n",
       "      <td>9.8</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>The Godfather: Part II</td>\n",
       "      <td>1974</td>\n",
       "      <td>R</td>\n",
       "      <td>Crime</td>\n",
       "      <td>202</td>\n",
       "      <td>134966411</td>\n",
       "      <td>9.0</td>\n",
       "      <td>9.7</td>\n",
       "      <td>9.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>Schindler's List</td>\n",
       "      <td>1993</td>\n",
       "      <td>R</td>\n",
       "      <td>Biography</td>\n",
       "      <td>195</td>\n",
       "      <td>534858444</td>\n",
       "      <td>8.9</td>\n",
       "      <td>9.7</td>\n",
       "      <td>9.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>The Good, the Bad and the Ugly</td>\n",
       "      <td>1966</td>\n",
       "      <td>R</td>\n",
       "      <td>Western</td>\n",
       "      <td>178</td>\n",
       "      <td>57300000</td>\n",
       "      <td>8.9</td>\n",
       "      <td>9.7</td>\n",
       "      <td>9.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                            title  year content_rating                genre  \\\n",
       "0        The Shawshank Redemption  1994              R    Drama               \n",
       "1                   The Godfather  1972              R                Crime   \n",
       "3          The Godfather: Part II  1974              R                Crime   \n",
       "5                Schindler's List  1993              R            Biography   \n",
       "7  The Good, the Bad and the Ugly  1966              R  Western               \n",
       "\n",
       "   duration      gross  Internet Movie Database  Rotten Tomatoes  Metacritic  \n",
       "0       142    1963330                      9.3              9.1         8.0  \n",
       "1       175   28341469                      9.2              9.8        10.0  \n",
       "3       202  134966411                      9.0              9.7         9.0  \n",
       "5       195  534858444                      8.9              9.7         9.3  \n",
       "7       178   57300000                      8.9              9.7         9.0  "
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movies_rated[movies_rated.content_rating == 'R'].sort_values(by='Internet Movie Database', ascending=False).head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "What is the average Rotten Tomato score for the top IMDB films?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9.087341772151897"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movies_rated['Rotten Tomatoes'].mean()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "What is the Five Number Summary like for top rated films as per IMDB? Is it skewed?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "count    79.000000\n",
       "mean      8.537975\n",
       "std       0.222056\n",
       "min       8.300000\n",
       "25%       8.400000\n",
       "50%       8.500000\n",
       "75%       8.600000\n",
       "max       9.300000\n",
       "Name: Internet Movie Database, dtype: float64"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movies_rated['Internet Movie Database'].describe()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The average is *slightly* higher than the median, so there's a small positive skew."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Create your own question...then answer it!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>year</th>\n",
       "      <th>duration</th>\n",
       "      <th>gross</th>\n",
       "      <th>Internet Movie Database</th>\n",
       "      <th>Rotten Tomatoes</th>\n",
       "      <th>Metacritic</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>year</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.145930</td>\n",
       "      <td>-0.107644</td>\n",
       "      <td>-0.044124</td>\n",
       "      <td>-0.479430</td>\n",
       "      <td>-0.487070</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>duration</th>\n",
       "      <td>0.145930</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.098006</td>\n",
       "      <td>0.416829</td>\n",
       "      <td>-0.088653</td>\n",
       "      <td>-0.020531</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>gross</th>\n",
       "      <td>-0.107644</td>\n",
       "      <td>0.098006</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.146099</td>\n",
       "      <td>-0.019891</td>\n",
       "      <td>-0.038350</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Internet Movie Database</th>\n",
       "      <td>-0.044124</td>\n",
       "      <td>0.416829</td>\n",
       "      <td>0.146099</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.062015</td>\n",
       "      <td>0.261009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Rotten Tomatoes</th>\n",
       "      <td>-0.479430</td>\n",
       "      <td>-0.088653</td>\n",
       "      <td>-0.019891</td>\n",
       "      <td>0.062015</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.765957</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Metacritic</th>\n",
       "      <td>-0.487070</td>\n",
       "      <td>-0.020531</td>\n",
       "      <td>-0.038350</td>\n",
       "      <td>0.261009</td>\n",
       "      <td>0.765957</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                             year  duration     gross  \\\n",
       "year                     1.000000  0.145930 -0.107644   \n",
       "duration                 0.145930  1.000000  0.098006   \n",
       "gross                   -0.107644  0.098006  1.000000   \n",
       "Internet Movie Database -0.044124  0.416829  0.146099   \n",
       "Rotten Tomatoes         -0.479430 -0.088653 -0.019891   \n",
       "Metacritic              -0.487070 -0.020531 -0.038350   \n",
       "\n",
       "                         Internet Movie Database  Rotten Tomatoes  Metacritic  \n",
       "year                                   -0.044124        -0.479430   -0.487070  \n",
       "duration                                0.416829        -0.088653   -0.020531  \n",
       "gross                                   0.146099        -0.019891   -0.038350  \n",
       "Internet Movie Database                 1.000000         0.062015    0.261009  \n",
       "Rotten Tomatoes                         0.062015         1.000000    0.765957  \n",
       "Metacritic                              0.261009         0.765957    1.000000  "
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# correlation between star rating and Rotten Tomato rating?\n",
    "movies_rated.corr()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Challenge:** Create a dataframe that is the ratio between Rotten Tomato rating vs IMDB rating. What film has the highest IMDB : Rotten Tomato ratio? The lowest?\n",
    "\n",
    "*[skip this if you are low on time]*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Ratings Ratio</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.021978</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.938776</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.957447</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Ratings Ratio\n",
       "0       1.021978\n",
       "1       0.938776\n",
       "2       0.957447"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rr = pd.DataFrame(movies_rated['Internet Movie Database'] / movies_rated['Rotten Tomatoes'], columns=['Ratings Ratio'])\n",
    "rr.head(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Top 3 ratings ratio movies (rated higher on IMBD compared to Rotten Tomatoes)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "      <th>content_rating</th>\n",
       "      <th>genre</th>\n",
       "      <th>duration</th>\n",
       "      <th>gross</th>\n",
       "      <th>Internet Movie Database</th>\n",
       "      <th>Rotten Tomatoes</th>\n",
       "      <th>Metacritic</th>\n",
       "      <th>Ratings Ratio</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>Forrest Gump</td>\n",
       "      <td>1994</td>\n",
       "      <td>PG-13</td>\n",
       "      <td>Drama</td>\n",
       "      <td>142</td>\n",
       "      <td>1401164</td>\n",
       "      <td>8.8</td>\n",
       "      <td>7.2</td>\n",
       "      <td>8.2</td>\n",
       "      <td>1.222222</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>Interstellar</td>\n",
       "      <td>2014</td>\n",
       "      <td>PG-13</td>\n",
       "      <td>Adventure</td>\n",
       "      <td>169</td>\n",
       "      <td>315544750</td>\n",
       "      <td>8.6</td>\n",
       "      <td>7.1</td>\n",
       "      <td>7.4</td>\n",
       "      <td>1.211268</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>42</th>\n",
       "      <td>The Intouchables</td>\n",
       "      <td>2011</td>\n",
       "      <td>R</td>\n",
       "      <td>Biography</td>\n",
       "      <td>112</td>\n",
       "      <td>1059654</td>\n",
       "      <td>8.5</td>\n",
       "      <td>7.4</td>\n",
       "      <td>5.7</td>\n",
       "      <td>1.148649</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               title  year content_rating      genre  duration      gross  \\\n",
       "12      Forrest Gump  1994          PG-13      Drama       142    1401164   \n",
       "19      Interstellar  2014          PG-13  Adventure       169  315544750   \n",
       "42  The Intouchables  2011              R  Biography       112    1059654   \n",
       "\n",
       "    Internet Movie Database  Rotten Tomatoes  Metacritic  Ratings Ratio  \n",
       "12                      8.8              7.2         8.2       1.222222  \n",
       "19                      8.6              7.1         7.4       1.211268  \n",
       "42                      8.5              7.4         5.7       1.148649  "
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movies_rated.merge(rr, left_index=True, right_index=True).sort_values('Ratings Ratio', ascending=False).head(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Bottom 3 ratings ratio movies (rated lower on IMBD compared to Rotten Tomatoes)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "      <th>content_rating</th>\n",
       "      <th>genre</th>\n",
       "      <th>duration</th>\n",
       "      <th>gross</th>\n",
       "      <th>Internet Movie Database</th>\n",
       "      <th>Rotten Tomatoes</th>\n",
       "      <th>Metacritic</th>\n",
       "      <th>Ratings Ratio</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>Toy Story 3</td>\n",
       "      <td>2010</td>\n",
       "      <td>R</td>\n",
       "      <td>Animation</td>\n",
       "      <td>103</td>\n",
       "      <td>499468</td>\n",
       "      <td>8.3</td>\n",
       "      <td>9.9</td>\n",
       "      <td>9.2</td>\n",
       "      <td>0.838384</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>74</th>\n",
       "      <td>L.A. Confidential</td>\n",
       "      <td>1997</td>\n",
       "      <td>R</td>\n",
       "      <td>Crime</td>\n",
       "      <td>138</td>\n",
       "      <td>13182281</td>\n",
       "      <td>8.3</td>\n",
       "      <td>9.9</td>\n",
       "      <td>9.0</td>\n",
       "      <td>0.838384</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>63</th>\n",
       "      <td>Toy Story</td>\n",
       "      <td>1995</td>\n",
       "      <td>R</td>\n",
       "      <td>Animation</td>\n",
       "      <td>81</td>\n",
       "      <td>83471511</td>\n",
       "      <td>8.3</td>\n",
       "      <td>10.0</td>\n",
       "      <td>9.5</td>\n",
       "      <td>0.830000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                title  year content_rating      genre  duration     gross  \\\n",
       "66        Toy Story 3  2010              R  Animation       103    499468   \n",
       "74  L.A. Confidential  1997              R      Crime       138  13182281   \n",
       "63          Toy Story  1995              R  Animation        81  83471511   \n",
       "\n",
       "    Internet Movie Database  Rotten Tomatoes  Metacritic  Ratings Ratio  \n",
       "66                      8.3              9.9         9.2       0.838384  \n",
       "74                      8.3              9.9         9.0       0.838384  \n",
       "63                      8.3             10.0         9.5       0.830000  "
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movies_rated.merge(rr, left_index=True, right_index=True).sort_values('Ratings Ratio', ascending=False).tail(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exploratory data analysis with visualizations\n",
    "\n",
    "For each of these prompts, create a plot to visualize the answer. Consider what plot is *most appropriate* to explore the given prompt.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "What is the relationship between IMDB ratings and Rotten Tomato ratings?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x7f53393ce198>"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 11396 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "movies_rated.plot(kind='scatter', x='Internet Movie Database', y='Rotten Tomatoes')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "What is the relationship between IMDB rating and movie duration?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x7f5339084da0>"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 11004 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "movies_rated.plot(kind='scatter', x='duration', y='Internet Movie Database')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "How many movies are there in each genre category? (Remember to create a plot here)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x7f5339006f98>"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 12308 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "movies_rated['genre'].value_counts().plot(kind='bar', color='dodgerblue')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "What does the distribution of Rotten Tomatoes ratings look like?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x7f5338f93780>"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 5904 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "movies_rated['Rotten Tomatoes'].plot(kind='hist', bins=15)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Bonus\n",
    "\n",
    "There are many things left unexplored! Consider investigating something about gross revenue and genres."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x7f5338f69f60>"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 6048 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "movies_rated['gross'].plot(kind='hist', bins=15, color='dodgerblue')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "      <th>content_rating</th>\n",
       "      <th>genre</th>\n",
       "      <th>duration</th>\n",
       "      <th>gross</th>\n",
       "      <th>Internet Movie Database</th>\n",
       "      <th>Rotten Tomatoes</th>\n",
       "      <th>Metacritic</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>One Flew Over the Cuckoo's Nest</td>\n",
       "      <td>1975</td>\n",
       "      <td>R</td>\n",
       "      <td>Drama</td>\n",
       "      <td>133</td>\n",
       "      <td>665845272</td>\n",
       "      <td>8.7</td>\n",
       "      <td>9.4</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>Schindler's List</td>\n",
       "      <td>1993</td>\n",
       "      <td>R</td>\n",
       "      <td>Biography</td>\n",
       "      <td>195</td>\n",
       "      <td>534858444</td>\n",
       "      <td>8.9</td>\n",
       "      <td>9.7</td>\n",
       "      <td>9.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>Fight Club</td>\n",
       "      <td>1999</td>\n",
       "      <td>R</td>\n",
       "      <td>Drama</td>\n",
       "      <td>139</td>\n",
       "      <td>377845905</td>\n",
       "      <td>8.8</td>\n",
       "      <td>7.9</td>\n",
       "      <td>6.6</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                              title  year content_rating              genre  \\\n",
       "17  One Flew Over the Cuckoo's Nest  1975              R  Drama               \n",
       "5                  Schindler's List  1993              R          Biography   \n",
       "13                       Fight Club  1999              R  Drama               \n",
       "\n",
       "    duration      gross  Internet Movie Database  Rotten Tomatoes  Metacritic  \n",
       "17       133  665845272                      8.7              9.4         8.0  \n",
       "5        195  534858444                      8.9              9.7         9.3  \n",
       "13       139  377845905                      8.8              7.9         6.6  "
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# top 10 grossing films\n",
    "movies_rated.sort_values(by='gross', ascending=False).head(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "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.7.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
