{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "a9215f5c-525b-4508-8b0d-700f55cbd252",
   "metadata": {},
   "source": [
    "## Introduction to Data Science\n",
    "\n",
    "#### University of Redlands - DATA 101\n",
    "#### Prof: Joanna Bieri [joanna_bieri@redlands.edu](mailto:joanna_bieri@redlands.edu)\n",
    "#### [Class Website: data101.joannabieri.com](https://data101.joannabieri.com)\n",
    "\n",
    "---------------------------------------\n",
    "# Homework Day 8\n",
    "---------------------------------------\n",
    "\n",
    "GOALS:\n",
    "\n",
    "1. Load data into Python that you find online\n",
    "2. Understand data types and fix some errors\n",
    "3. Find your own data to play with\n",
    "\n",
    "----------------------------------------------------------\n",
    "\n",
    "This homework has **5 questions** and **1 problem**.\n",
    "\n",
    "NOTE: Be kind to yourself. Working with data can be hard! Every data set is different. **Seriously** come get help! Come to office hours!\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "049c24b6-a6c1-4ccc-b2de-5ea0366d09f8",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-16T23:06:10.479206Z",
     "iopub.status.busy": "2026-09-16T23:06:10.478676Z",
     "iopub.status.idle": "2026-09-16T23:06:12.272539Z",
     "shell.execute_reply": "2026-09-16T23:06:12.271902Z"
    }
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "import plotly.express as px\n",
    "from plotly.subplots import make_subplots\n",
    "import plotly.io as pio\n",
    "pio.renderers.default = 'notebook_connected'"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "23773272-c059-4148-a5a8-91e9da594c46",
   "metadata": {},
   "source": [
    "## Try reading in some data - csv\n",
    "\n",
    "Go to the [Cal Fire Website](https://www.fire.ca.gov/incidents) and scroll to the bottom to see the Incident Data. We will download the file named **ALL DATA AS CSV** this should put the data file into your Downloads folder. \n",
    "\n",
    "Next you need to move the file **mapdataall.csv** from your Downloads folder into your Day8 folder where you are doing your homework. You can open your Downloads folder and drag the file into JupyterLab side bar. Then I can run the command\n",
    "\n",
    "    DF_raw = pd.read_csv('mapdataall.csv')\n",
    "\n",
    "to load the data and look at the data frame.\n",
    "\n",
    "NOTE: If you have downloaded this file before, your computer might name the new one **mapdataall (1).csv**. Rename it to **mapdataall.csv** before you run the code."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "e90fdd5f-bd17-4c94-b3f4-7ddc998bd001",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-16T23:06:12.274775Z",
     "iopub.status.busy": "2026-09-16T23:06:12.274600Z",
     "iopub.status.idle": "2026-09-16T23:06:12.277057Z",
     "shell.execute_reply": "2026-09-16T23:06:12.276501Z"
    }
   },
   "outputs": [],
   "source": [
    "# Your code here"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "941e4499-edd1-4210-b3ff-292dd2eb4df7",
   "metadata": {},
   "source": [
    "**Q1** How many variables and observations?\n",
    "\n",
    "**Q2** How many different incident types are there?\n",
    "\n",
    "**Q3** Make a histogram of the acres burned and color the bars by whether or not the incident was a calfire incident. You will probably need to make a mask to remove very small and very large fires. How many fires burned more than 100,000 acres? What is the largest fire in the data?\n",
    "\n",
    "**Extra Q** EXTRA - CHALLENGE - See if you can create a graph that answers the question: Are fires getting bigger or more frequent over time? You get complete creative control on how to answer this question!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "df36876b-02c2-4d86-b55b-62819a368bf6",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-16T23:06:12.278859Z",
     "iopub.status.busy": "2026-09-16T23:06:12.278696Z",
     "iopub.status.idle": "2026-09-16T23:06:12.280664Z",
     "shell.execute_reply": "2026-09-16T23:06:12.280295Z"
    }
   },
   "outputs": [],
   "source": [
    "# You will need to write some code to answer the questions.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0e1f769b-d87d-429a-9de8-c35af020525d",
   "metadata": {},
   "source": [
    "**(Click Here)**\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "0388222e-a80b-4392-99cd-3966254c4017",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-16T23:06:12.282588Z",
     "iopub.status.busy": "2026-09-16T23:06:12.282229Z",
     "iopub.status.idle": "2026-09-16T23:06:12.284648Z",
     "shell.execute_reply": "2026-09-16T23:06:12.284277Z"
    }
   },
   "outputs": [],
   "source": [
    "# Extra Code\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fa09683e-ac6a-4cb5-a47d-6cbf580524d2",
   "metadata": {},
   "source": [
    "## Try reading in some data from a website\n",
    "\n",
    "Here we will explore academy award winning films. Go to the [Wiki for the List of Academy Award Winning Films](https://en.wikipedia.org/wiki/List_of_Academy_Award%E2%80%93winning_films). Look at what type of data is there. How many tables? Any weird looking data?\n",
    "\n",
    "More and more websites block Python from reading their pages directly (you will see an error like **HTTP Error 403: Forbidden**). So I saved a copy of the main table from this page as a .csv file on the class website. The helper code below reads it in and fixes the Year column for you."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "ddd62d4d-675f-4706-9b79-993e5b5ad343",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-16T23:06:12.286397Z",
     "iopub.status.busy": "2026-09-16T23:06:12.286228Z",
     "iopub.status.idle": "2026-09-16T23:06:12.549209Z",
     "shell.execute_reply": "2026-09-16T23:06:12.548686Z"
    }
   },
   "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>Film</th>\n",
       "      <th>Year</th>\n",
       "      <th>Awards</th>\n",
       "      <th>Nominations</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>One Battle After Another</td>\n",
       "      <td>2025</td>\n",
       "      <td>6</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Sinners</td>\n",
       "      <td>2025</td>\n",
       "      <td>4</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Frankenstein</td>\n",
       "      <td>2025</td>\n",
       "      <td>3</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>KPop Demon Hunters</td>\n",
       "      <td>2025</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Hamnet</td>\n",
       "      <td>2025</td>\n",
       "      <td>1</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1396</th>\n",
       "      <td>The Yankee Doodle Mouse</td>\n",
       "      <td>1943</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1397</th>\n",
       "      <td>The Yearling</td>\n",
       "      <td>1946</td>\n",
       "      <td>2</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1398</th>\n",
       "      <td>Yesterday, Today and Tomorrow (Ieri, oggi, dom...</td>\n",
       "      <td>1964</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1399</th>\n",
       "      <td>You Can't Take It with You</td>\n",
       "      <td>1938</td>\n",
       "      <td>2</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1400</th>\n",
       "      <td>Zorba the Greek (Alexis Zorbas)</td>\n",
       "      <td>1964</td>\n",
       "      <td>3</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1401 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                   Film  Year Awards  \\\n",
       "0                              One Battle After Another  2025      6   \n",
       "1                                               Sinners  2025      4   \n",
       "2                                          Frankenstein  2025      3   \n",
       "3                                    KPop Demon Hunters  2025      2   \n",
       "4                                                Hamnet  2025      1   \n",
       "...                                                 ...   ...    ...   \n",
       "1396                            The Yankee Doodle Mouse  1943      1   \n",
       "1397                                       The Yearling  1946      2   \n",
       "1398  Yesterday, Today and Tomorrow (Ieri, oggi, dom...  1964      1   \n",
       "1399                         You Can't Take It with You  1938      2   \n",
       "1400                    Zorba the Greek (Alexis Zorbas)  1964      3   \n",
       "\n",
       "     Nominations  \n",
       "0             13  \n",
       "1             16  \n",
       "2              9  \n",
       "3              2  \n",
       "4              8  \n",
       "...          ...  \n",
       "1396           1  \n",
       "1397           7  \n",
       "1398           1  \n",
       "1399           7  \n",
       "1400           7  \n",
       "\n",
       "[1401 rows x 4 columns]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Here is some helper code\n",
    "# This is code that will read in the data and then fix the Year column\n",
    "file = 'https://joannabieri.com/introdatascience/data/academy_award_films.csv'\n",
    "DF_raw = pd.read_csv(file)\n",
    "DF_raw['Year'] = DF_raw['Year'].apply(lambda x: int(x.split('/')[0]))\n",
    "DF_raw"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4c70b364-4c59-4631-87a4-552d7abaac2a",
   "metadata": {},
   "source": [
    "**Q4** Following along with the lecture notes or video, fix the data in the 'Awards' column."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "e51c0742-d796-4f63-a3e9-c98cdec76247",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-16T23:06:12.551112Z",
     "iopub.status.busy": "2026-09-16T23:06:12.550946Z",
     "iopub.status.idle": "2026-09-16T23:06:12.553135Z",
     "shell.execute_reply": "2026-09-16T23:06:12.552639Z"
    }
   },
   "outputs": [],
   "source": [
    "# Your code here\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ada5ce86-e820-481b-a8c8-ab5f063b0ad5",
   "metadata": {},
   "source": [
    "**Q5** Now try to fix the data in the \"Nominations\" column - see if you can do it without looking at the answer."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "57571cc2-dbca-4354-b0db-676b03005f3c",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-16T23:06:12.554969Z",
     "iopub.status.busy": "2026-09-16T23:06:12.554750Z",
     "iopub.status.idle": "2026-09-16T23:06:12.557102Z",
     "shell.execute_reply": "2026-09-16T23:06:12.556674Z"
    }
   },
   "outputs": [],
   "source": [
    "# Your code here\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8f1c8227-7b3e-4067-9b49-bd9c58752402",
   "metadata": {},
   "source": [
    "## Problem 1\n",
    "\n",
    "Your homework today will be to see if you can find some data of your own. This can be the first steps you take toward your final project. \n",
    "\n",
    "You should:\n",
    "\n",
    "* Find some data online\n",
    "* Read that data into Python using the Pandas commands we learned\n",
    "* Look at the DataFrame - number of variables, number of observations, AND the dtypes. Comment on what you see.\n",
    "* Try to do summary statistics (.describe()). Does it work like expected?\n",
    "* Attempt to fix any data, or explain why the data does not need to be fixed.\n",
    "* Make some sort of graph using columns in your data."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "578ad570-5dfa-46a0-86c8-f4610bacaf36",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.13.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
