{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "tags": [
     "remove_input"
    ]
   },
   "outputs": [],
   "source": [
    "path_data = '../../data/'\n",
    "\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "\n",
    "%matplotlib inline\n",
    "import matplotlib.pyplot as plt\n",
    "plt.style.use('bmh')\n",
    "\n",
    "import warnings\n",
    "warnings.filterwarnings('ignore')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Visualizing Categorical Distributions\n",
    "\n",
    "Data come in many forms that are not numerical. Data can be pieces of music, or places on a map. They can also be categories into which you can place individuals. Here are some examples of *categorical* variables.\n",
    "\n",
    "- The individuals are cartons of ice-cream, and the variable is the flavor in the carton.\n",
    "- The individuals are professional basketball players, and the variable is the player's team.\n",
    "- The individuals are years, and the variable is the genre of the highest grossing movie of the year.\n",
    "- The individuals are survey respondents, and the variable is the response they choose from among \"Not at all satisfied,\" \"Somewhat satisfied,\" and \"Very satisfied.\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The DataFrame `icecream` contains data on 30 cartons of ice-cream. "
   ]
  },
  {
   "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>Flavor</th>\n",
       "      <th>Number of Cartons</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Chocolate</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Strawberry</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Vanilla</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       Flavor  Number of Cartons\n",
       "0   Chocolate                 16\n",
       "1  Strawberry                  5\n",
       "2     Vanilla                  9"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "icecream = pd.DataFrame({\n",
    "    'Flavor':np.array(['Chocolate', 'Strawberry', 'Vanilla']),\n",
    "    'Number of Cartons':np.array([16, 5, 9])}\n",
    ")\n",
    "icecream"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The *values* of the **categorical** variable \"flavor\" are chocolate, strawberry, and vanilla. The df shows the number of cartons of each flavor. We call this a *distribution table*. A *distribution* shows all the values of a variable, along with the frequency of each one."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Bar Chart (pandas)\n",
    "The bar chart (*as opposed to Histogram*) is a familiar way of visualizing categorical distributions. It displays a bar for each category. The bars are equally spaced and equally wide. The length of each bar is proportional to the frequency of the corresponding category.\n",
    "\n",
    "We will draw bar charts with horizontal bars because it's easier to label the bars that way. The *pandas* df method is therefore called `barh`. It takes two arguments: the first is the column label of the categories, and the second is the column label of the frequencies."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 15780 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "icecream.plot.barh('Flavor', 'Number of Cartons')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If the table consists just of a column of categories and a column of frequencies, as in `icecream`, the method call is even simpler. You can just specify the column containing the categories, and `barh` will use the values in the other column as frequencies."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 15780 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "icecream.plot.barh('Flavor')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Features of Categorical Distributions\n",
    "Apart from purely visual differences, there is an important fundamental distinction between bar charts and the two graphs that we saw in the previous sections. Those were the scatter plot and the line plot, both of which display two numerical variables – the variables on both axes are numerical. In contrast, the bar chart has categories on one axis and numerical frequencies on the other.\n",
    "\n",
    "This has consequences for the chart. First, the width of each bar and the space between consecutive bars is entirely up to the person who is producing the graph, or to the program being used to produce it. Python made those choices for us. If you were to draw the bar graph by hand, you could make completely different choices and still have a perfectly correct bar graph, provided you drew all the bars with the same width and kept all the spaces the same.\n",
    "\n",
    "Most importantly, the bars can be drawn in any order. The categories \"chocolate,\" \"vanilla,\" and \"strawberry\" have no universal rank order, unlike for example the numbers 5, 7, and 10.\n",
    "\n",
    "This means that we can draw a bar chart that is easier to interpret, by rearranging the bars in decreasing order. To do this, we first rearrange the rows of `icecream` in decreasing order of `Number of Cartons`, and then draw the bar chart."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 15776 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "icecream.sort_values('Number of Cartons', ascending=False).plot.barh('Flavor')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This bar chart contains exactly the same information as the previous ones, but it is a little easier to read. While this is not a huge gain in reading a chart with just three bars, it can be quite significant when the number of categories is large."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Grouping Categorical Data\n",
    "To construct the df `icecream`, someone had to look at all 30 cartons of ice-cream and count the number of each flavor. But if our data does not already include frequencies, we have to compute the frequencies before we can draw a bar chart. Here is an example where this is necessary.\n",
    "\n",
    "The df `top` consists of U.S.A.'s top grossing movies of all time. The first column contains the title of the movie; *Star Wars: The Force Awakens* has the top rank, with a box office gross amount of more than 900 million dollars in the United States. The second column contains the name of the studio that produced the movie. The third contains the domestic box office gross in dollars, and the fourth contains the  gross amount that would have been earned from ticket sales at 2016 prices. The fifth contains the release year of the movie. \n",
    "\n",
    "There are 200 movies on the list. Here are the top ten according to unadjusted gross receipts."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "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>Studio</th>\n",
       "      <th>Gross</th>\n",
       "      <th>Gross (Adjusted)</th>\n",
       "      <th>Year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Star Wars: The Force Awakens</td>\n",
       "      <td>Buena Vista (Disney)</td>\n",
       "      <td>906723418</td>\n",
       "      <td>906723400</td>\n",
       "      <td>2015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Avatar</td>\n",
       "      <td>Fox</td>\n",
       "      <td>760507625</td>\n",
       "      <td>846120800</td>\n",
       "      <td>2009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Titanic</td>\n",
       "      <td>Paramount</td>\n",
       "      <td>658672302</td>\n",
       "      <td>1178627900</td>\n",
       "      <td>1997</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Jurassic World</td>\n",
       "      <td>Universal</td>\n",
       "      <td>652270625</td>\n",
       "      <td>687728000</td>\n",
       "      <td>2015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Marvel's The Avengers</td>\n",
       "      <td>Buena Vista (Disney)</td>\n",
       "      <td>623357910</td>\n",
       "      <td>668866600</td>\n",
       "      <td>2012</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>195</th>\n",
       "      <td>The Caine Mutiny</td>\n",
       "      <td>Columbia</td>\n",
       "      <td>21750000</td>\n",
       "      <td>386173500</td>\n",
       "      <td>1954</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>196</th>\n",
       "      <td>The Bells of St. Mary's</td>\n",
       "      <td>RKO</td>\n",
       "      <td>21333333</td>\n",
       "      <td>545882400</td>\n",
       "      <td>1945</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>197</th>\n",
       "      <td>Duel in the Sun</td>\n",
       "      <td>Selz.</td>\n",
       "      <td>20408163</td>\n",
       "      <td>443877500</td>\n",
       "      <td>1946</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>198</th>\n",
       "      <td>Sergeant York</td>\n",
       "      <td>Warner Bros.</td>\n",
       "      <td>16361885</td>\n",
       "      <td>418671800</td>\n",
       "      <td>1941</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>199</th>\n",
       "      <td>The Four Horsemen of the Apocalypse</td>\n",
       "      <td>MPC</td>\n",
       "      <td>9183673</td>\n",
       "      <td>399489800</td>\n",
       "      <td>1921</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>200 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                   Title                Studio      Gross  \\\n",
       "0           Star Wars: The Force Awakens  Buena Vista (Disney)  906723418   \n",
       "1                                 Avatar                   Fox  760507625   \n",
       "2                                Titanic             Paramount  658672302   \n",
       "3                         Jurassic World             Universal  652270625   \n",
       "4                  Marvel's The Avengers  Buena Vista (Disney)  623357910   \n",
       "..                                   ...                   ...        ...   \n",
       "195                     The Caine Mutiny              Columbia   21750000   \n",
       "196              The Bells of St. Mary's                   RKO   21333333   \n",
       "197                      Duel in the Sun                 Selz.   20408163   \n",
       "198                        Sergeant York          Warner Bros.   16361885   \n",
       "199  The Four Horsemen of the Apocalypse                   MPC    9183673   \n",
       "\n",
       "     Gross (Adjusted)  Year  \n",
       "0           906723400  2015  \n",
       "1           846120800  2009  \n",
       "2          1178627900  1997  \n",
       "3           687728000  2015  \n",
       "4           668866600  2012  \n",
       "..                ...   ...  \n",
       "195         386173500  1954  \n",
       "196         545882400  1945  \n",
       "197         443877500  1946  \n",
       "198         418671800  1941  \n",
       "199         399489800  1921  \n",
       "\n",
       "[200 rows x 5 columns]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "top = pd.read_csv(path_data + 'top_movies.csv')\n",
    "top"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The Disney subsidiary Buena Vista shows up frequently in the top ten, as do Fox and Warner Brothers. Which studios will appear most frequently if we look among all 200 rows?\n",
    "\n",
    "To figure this out, first notice that all we need is a table with the movies and the studios; the other information is unnecessary. Again, notice that we use two sqaure brackets as we wish to use more than one column."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "movies_and_studios = top[['Title', 'Studio']]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The df methods `groupby()` and `count()` allows us to count how frequently each studio appears in the table, by calling each studio a category and assigning each row to one category. The `groupby` method takes as its argument the label of the column that contains the categories, the `count()` returns a table of counts of rows in each category. Unless we state which column we wish to `count()` the first column in the df will be used, notice how the name of the grouping column or category is shown below the name of the column being used for the count. There a number of ways by which we could 'remove' the name of the count column - can you think of any?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "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",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Studio</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>AVCO</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Buena Vista (Disney)</th>\n",
       "      <td>29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Columbia</th>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Disney</th>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dreamworks</th>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Fox</th>\n",
       "      <td>26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>IFC</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Lionsgate</th>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>MGM</th>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>MPC</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>NM</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>New Line</th>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Orion</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Paramount</th>\n",
       "      <td>25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Paramount/Dreamworks</th>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>RKO</th>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Selz.</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sony</th>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sum.</th>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>TriS</th>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UA</th>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Universal</th>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Warner Bros.</th>\n",
       "      <td>29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Warner Bros. (New Line)</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                         Title\n",
       "Studio                        \n",
       "AVCO                         1\n",
       "Buena Vista (Disney)        29\n",
       "Columbia                    10\n",
       "Disney                      11\n",
       "Dreamworks                   3\n",
       "Fox                         26\n",
       "IFC                          1\n",
       "Lionsgate                    3\n",
       "MGM                          7\n",
       "MPC                          1\n",
       "NM                           1\n",
       "New Line                     5\n",
       "Orion                        1\n",
       "Paramount                   25\n",
       "Paramount/Dreamworks         4\n",
       "RKO                          3\n",
       "Selz.                        1\n",
       "Sony                         6\n",
       "Sum.                         2\n",
       "TriS                         2\n",
       "UA                           6\n",
       "Universal                   22\n",
       "Warner Bros.                29\n",
       "Warner Bros. (New Line)      1"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movies_and_studios.groupby(['Studio']).count()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Thus `groupby` creates a distribution table that shows how the movies are distributed among the categories (studios). \n",
    "\n",
    "We can now use this table, along with the graphing skills that we acquired above, to draw a bar chart that shows which studios are most frequent among the 200 highest grossing movies."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 69264 characters]\n",
      "text/plain": [
       "<Figure size 720x1296 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#we can also use the '.size()' method as this will return the 'size' \n",
    "#i.e. an int representing the number of elements in and object.\n",
    "\n",
    "studio_distribution1 = movies_and_studios.groupby(['Studio'], as_index=False).count()\n",
    "studio_distribution = studio_distribution1.copy()\n",
    "studio_distribution.sort_values(by=['Title']).plot.barh('Studio', width=0.8, figsize=(10,18))\n",
    "\n",
    "plt.xlabel('count')\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Warner Brothers and Buena Vista are the most common studios among the top 200 movies. Warner Brothers produces the Harry Potter movies and Buena Vista produces Star Wars. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Because total gross receipts are being measured in unadjusted dollars, it is not very surprising that the top movies are more frequently from recent years than from bygone decades. In absolute terms, movie tickets cost more now than they used to, and thus gross receipts are higher. This is borne out by a bar chart that show the distribution of the 200 movies by year of release."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 159452 characters]\n",
      "text/plain": [
       "<Figure size 720x2736 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "movies_and_years = top[['Title', 'Year']]\n",
    "\n",
    "movies_and_years1 = movies_and_years.copy()\n",
    "\n",
    "movies_and_years = movies_and_years.groupby(['Year'], as_index=False).count()\n",
    "\n",
    "movies_and_years.sort_values(by=['Title']).plot.barh('Year', width=0.8, figsize=(10,38), color=\"blue\")\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "All of the longest bars correspond to years after 2000. This is consistent with our observation that recent years should be among the most frequent."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Towards numerical variables\n",
    "There is something unsettling about this chart. Though it does answer the question of which release years appear most frequently among the 200 top grossing movies, it doesn't list all the years in chronological order. It is treating `Year` as a categorical variable. \n",
    "\n",
    "But years are fixed chronological units that do have an order. They also have fixed numerical spacings relative to each other. Let's see what happens when we try to take that into account.\n",
    "\n",
    "By default, `barh` sorts the categories (years) from lowest to highest. So we will run the code without sorting by count. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 159468 characters]\n",
      "text/plain": [
       "<Figure size 720x2736 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#movies_and_years.group('Year').barh('Year')\n",
    "\n",
    "movies_and_years1.groupby(['Year'], as_index=False).count()\n",
    "\n",
    "movies_and_years.plot.barh('Year', width=0.8, figsize=(10,38), color ='blue')\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now the years are in increasing order. But there is still something disquieting about this bar chart. The bars at 1921 and 1937 are just as far apart from each other as the bars at 1937 and 1939. The bar chart doesn't show that none of the 200 movies were released in the years 1922 through 1936, nor in 1938. Such inconsistencies and omissions make the distribution in the early years hard to understand based on this visualization.\n",
    "\n",
    "Bar charts are intended as visualizations of categorical variables. When the variable is numerical, the numerical relations between its values have to be taken into account when we create visualizations. That is the topic of the next section."
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "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.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
