{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This video shows how to write code similar to the code required in your first homework assignment.  In this video, the code you see will not exactly work in the homework assignment.  This is on purpose.  You will need to change the name of tables and/or column names for the homework assignment.\n",
    "\n",
    "You are looking at a Jupyter Notebook. Jupyter Notebooks consist of Markdown cells like this one that do not contain executeable Python code and code cells like the next one.\n",
    "\n",
    "As with almost all assignments in this course, it is first necessary to run the code in the first code cell in order to load the software and data needed for the rest of the Python Program"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": [
     "remove_input"
    ]
   },
   "outputs": [],
   "source": [
    "from datascience import *\n",
    "path_data = 'http://www.millerjw.com/dom/mgmt462/pfiles/'\n",
    "import numpy as np\n",
    "%matplotlib inline\n",
    "import matplotlib.pyplot as plots\n",
    "plots.style.use('fivethirtyeight')\n",
    "\n",
    "cones = Table.read_table(path_data + 'cones.csv')\n",
    "nba = Table.read_table(path_data + 'nba_salaries.csv').relabeled(3, 'SALARY')\n",
    "movies = Table.read_table(path_data + 'movies_by_year.csv')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The statement in the cell below will display the first 10 rows of one of the three tables we have already read in. The movies table has 36 rows 10 of which are displayed."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "movies\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In this example, I would like to show all of the rows in a table (not just the first 10).  Since Jupyter will automatically displays a table if that table is on the last line of a code cell. The statement below will print all rows of the movies table. This allows me to see the last row. If I were to just code “movies”, only the first 10 rows of the movies table would be shown."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "movies.show(movies.num_rows)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In your homework, you are asked to create a new table by copying an existing table and dropping one of the columns.  In this example a table named no_salary is created by dropping the SALARY column from the nba table. The the first 10 rows of the no_salary table are shown. Note that SALARY must be in all caps because the person who setup the nba table named the Salary column that way"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "no_salary = nba.drop('SALARY')\n",
    "no_salary"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let’s suppose instead of eliminating column, we want to create a new table by picking one more more columns from an existing table.  In this example, a table named player_position will be created from the nba table and will contain just the player’s name and position. The table will then be shown by coding its name in the last line of the cell."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "player_position = nba.select('PLAYER','POSITION')\n",
    "player_position"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We have done enough work that it is worth saving what we have done.  Click File / Save and Checkpoint.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You are asked to sort a table.\n",
    "The first statement below sorts the nba table by TEAM.\n",
    "The second statement sorts the NBA table by Player name starting at the end of the alphabet."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "nba.sort('TEAM')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "nba.sort('PLAYER', descending=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Next, I am going to create a subset of the nba table by selecting only the team Orlando Magic. The statement below does not change the nba table.  Instead, it creates a new table with just the players from the team Orlando Magic. This is done by putting the name of the new table on the left side of an equals sign.  In this example, the name of the new table is magic. After creating the table magic, it is displayed by putting just the table name on the last line in the code cell."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "magic = nba.where('TEAM','Orlando Magic')\n",
    "magic"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "During the homework, you are asked to create new cells in a Jupyter Notebook.  Click Insert and the Insert cells below as shown"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This is documentation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This cell is set to markdown for documentation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# This cell is set to Code\n",
    "x = 1 + 2\n",
    "x"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To clear all the program results so you can start over, Select Kernel Restart and Clear Output.  To run all cells above this position in the program, click cell and select Run All Above"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "I think you now have enough information to complete the homework assignment.  If you do have any problems with the homework assignment feel free to email jmiller@dom.edu  If you paste the code you are having problems with and any error messages that Python has generated, I can do a better job of addressing your specific issue.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "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.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
