From 91a061adc1583ccd73aedd5fd34fda6492edf13b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20M=C3=A9ndez?= Date: Wed, 2 Jun 2021 18:35:27 +0200 Subject: [PATCH] final --- .../.ipynb_checkpoints/main-checkpoint.ipynb | 803 +++++ your-code/main.ipynb | 2613 ++++++++++++++++- 2 files changed, 3328 insertions(+), 88 deletions(-) create mode 100755 your-code/.ipynb_checkpoints/main-checkpoint.ipynb diff --git a/your-code/.ipynb_checkpoints/main-checkpoint.ipynb b/your-code/.ipynb_checkpoints/main-checkpoint.ipynb new file mode 100755 index 0000000..f387f80 --- /dev/null +++ b/your-code/.ipynb_checkpoints/main-checkpoint.ipynb @@ -0,0 +1,803 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Before your start:\n", + "- Read the README.md file\n", + "- Comment as much as you can and use the resources in the README.md file\n", + "- Happy learning!" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "#Import your libraries\n", + "\n", + "import warnings\n", + "warnings.simplefilter('ignore')\n", + "\n", + "import pandas as pd\n", + "pd.set_option('display.max_columns', None)\n", + "import numpy as np\n", + "\n", + "import pylab as plt\n", + "import seaborn as sns\n", + "%matplotlib inline" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "# Challenge 1 - Import and Describe the Dataset" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### In this challenge we will use the `austin_weather.csv` file. \n", + "\n", + "#### First import it into a data frame called `austin`." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "ename": "FileNotFoundError", + "evalue": "[Errno 2] No such file or directory: 'austin_weather.csv'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# Your code here\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0maustin\u001b[0m\u001b[0;34m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mread_csv\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"austin_weather.csv\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0maustin\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhead\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/opt/miniconda3/envs/clase/lib/python3.8/site-packages/pandas/io/parsers.py\u001b[0m in \u001b[0;36mread_csv\u001b[0;34m(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, skipfooter, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, cache_dates, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, doublequote, escapechar, comment, encoding, dialect, error_bad_lines, warn_bad_lines, delim_whitespace, low_memory, memory_map, float_precision, storage_options)\u001b[0m\n\u001b[1;32m 608\u001b[0m \u001b[0mkwds\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mupdate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkwds_defaults\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 609\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 610\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0m_read\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfilepath_or_buffer\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkwds\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 611\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 612\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/opt/miniconda3/envs/clase/lib/python3.8/site-packages/pandas/io/parsers.py\u001b[0m in \u001b[0;36m_read\u001b[0;34m(filepath_or_buffer, kwds)\u001b[0m\n\u001b[1;32m 460\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 461\u001b[0m \u001b[0;31m# Create the parser.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 462\u001b[0;31m \u001b[0mparser\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mTextFileReader\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfilepath_or_buffer\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwds\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 463\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 464\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mchunksize\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0miterator\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/opt/miniconda3/envs/clase/lib/python3.8/site-packages/pandas/io/parsers.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, f, engine, **kwds)\u001b[0m\n\u001b[1;32m 817\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0moptions\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"has_index_names\"\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mkwds\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"has_index_names\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 818\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 819\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_engine\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_make_engine\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mengine\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 820\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 821\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mclose\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/opt/miniconda3/envs/clase/lib/python3.8/site-packages/pandas/io/parsers.py\u001b[0m in \u001b[0;36m_make_engine\u001b[0;34m(self, engine)\u001b[0m\n\u001b[1;32m 1048\u001b[0m )\n\u001b[1;32m 1049\u001b[0m \u001b[0;31m# error: Too many arguments for \"ParserBase\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1050\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mmapping\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mengine\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mf\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0moptions\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# type: ignore[call-arg]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1051\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1052\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m_failover_to_python\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/opt/miniconda3/envs/clase/lib/python3.8/site-packages/pandas/io/parsers.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, src, **kwds)\u001b[0m\n\u001b[1;32m 1865\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1866\u001b[0m \u001b[0;31m# open handles\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1867\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_open_handles\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msrc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkwds\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1868\u001b[0m \u001b[0;32massert\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhandles\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1869\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mkey\u001b[0m \u001b[0;32min\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;34m\"storage_options\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"encoding\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"memory_map\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"compression\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/opt/miniconda3/envs/clase/lib/python3.8/site-packages/pandas/io/parsers.py\u001b[0m in \u001b[0;36m_open_handles\u001b[0;34m(self, src, kwds)\u001b[0m\n\u001b[1;32m 1360\u001b[0m \u001b[0mLet\u001b[0m \u001b[0mthe\u001b[0m \u001b[0mreaders\u001b[0m \u001b[0mopen\u001b[0m \u001b[0mIOHanldes\u001b[0m \u001b[0mafter\u001b[0m \u001b[0mthey\u001b[0m \u001b[0mare\u001b[0m \u001b[0mdone\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mtheir\u001b[0m \u001b[0mpotential\u001b[0m \u001b[0mraises\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1361\u001b[0m \"\"\"\n\u001b[0;32m-> 1362\u001b[0;31m self.handles = get_handle(\n\u001b[0m\u001b[1;32m 1363\u001b[0m \u001b[0msrc\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1364\u001b[0m \u001b[0;34m\"r\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/opt/miniconda3/envs/clase/lib/python3.8/site-packages/pandas/io/common.py\u001b[0m in \u001b[0;36mget_handle\u001b[0;34m(path_or_buf, mode, encoding, compression, memory_map, is_text, errors, storage_options)\u001b[0m\n\u001b[1;32m 640\u001b[0m \u001b[0merrors\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m\"replace\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 641\u001b[0m \u001b[0;31m# Encoding\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 642\u001b[0;31m handle = open(\n\u001b[0m\u001b[1;32m 643\u001b[0m \u001b[0mhandle\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 644\u001b[0m \u001b[0mioargs\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmode\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'austin_weather.csv'" + ] + } + ], + "source": [ + "# Your code here\n", + "\n", + "austin= pd.read_csv(\"austin_weather.csv\")\n", + "austin.head()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Next, describe the dataset you have loaded: \n", + "- Look at the variables and their types\n", + "- Examine the descriptive statistics of the numeric variables \n", + "- Look at the first five rows of all variables to evaluate the categorical variables as well" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Your code here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Your code here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Your code here\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Given the information you have learned from examining the dataset, write down three insights about the data in a markdown cell below" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Your Insights:\n", + "\n", + "1. There are 21 variables in the dataset. 3 of them are numeric and the rest contain some text.\n", + "\n", + "2. The average temperature in Austin ranged between around 70 degrees F and around 93 degrees F. The highest temperature observed during this period was 107 degrees F and the lowest was 19 degrees F.\n", + "\n", + "3. When we look at the head function, we see that a lot of variables contain numeric data even though these columns are of object type. This means we might have to do some data cleansing.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Let's examine the DewPointAvgF variable by using the `unique()` function to list all unique values in this dataframe.\n", + "\n", + "Describe what you find in a markdown cell below the code. What did you notice? What do you think made Pandas to treat this column as *object* instead of *int64*? " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Your code here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Your observation here\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The following is a list of columns misrepresented as `object`. Use this list to convert the columns to numeric using the `pandas.to_numeric` function in the next cell. If you encounter errors in converting strings to numeric values, you need to catch those errors and force the conversion by supplying `errors='coerce'` as an argument for `pandas.to_numeric`. Coercing will replace non-convertable elements with `NaN` which represents an undefined numeric value. This makes it possible for us to conveniently handle missing values in subsequent data processing.\n", + "\n", + "*Hint: you may use a loop to change one column at a time but it is more efficient to use `apply`.*" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "wrong_type_columns = ['DewPointHighF', 'DewPointAvgF', 'DewPointLowF', 'HumidityHighPercent', \n", + " 'HumidityAvgPercent', 'HumidityLowPercent', 'SeaLevelPressureHighInches', \n", + " 'SeaLevelPressureAvgInches' ,'SeaLevelPressureLowInches', 'VisibilityHighMiles',\n", + " 'VisibilityAvgMiles', 'VisibilityLowMiles', 'WindHighMPH', 'WindAvgMPH', \n", + " 'WindGustMPH', 'PrecipitationSumInches']" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Your code here\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Check if your code has worked by printing the data types again. You should see only two `object` columns (`Date` and `Events`) now. All other columns should be `int64` or `float64`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Your code here\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Challenge 2 - Handle the Missing Data" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Now that we have fixed the type mismatch, let's address the missing data.\n", + "\n", + "By coercing the columns to numeric, we have created `NaN` for each cell containing characters. We should choose a strategy to address these missing data.\n", + "\n", + "The first step is to examine how many rows contain missing data.\n", + "\n", + "We check how much missing data we have by applying the `.isnull()` function to our dataset. To find the rows with missing data in any of its cells, we apply `.any(axis=1)` to the function. `austin.isnull().any(axis=1)` will return a column containing true if the row contains at least one missing value and false otherwise. Therefore we must subset our dataframe with this column. This will give us all rows with at least one missing value. \n", + "\n", + "#### In the next cell, identify all rows containing at least one missing value. Assign the dataframes with missing values to a variable called `missing_values`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Your code here\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "There are multiple strategies to handle missing data. Below lists the most common ones data scientists use:\n", + "\n", + "* Removing all rows or all columns containing missing data. This is the simplest strategy. It may work in some cases but not others.\n", + "\n", + "* Filling all missing values with a placeholder value. \n", + " * For categorical data, `0`, `-1`, and `9999` are some commonly used placeholder values. \n", + " * For continuous data, some may opt to fill all missing data with the mean. This strategy is not optimal since it can increase the fit of the model.\n", + "\n", + "* Filling the values using some algorithm. \n", + "\n", + "#### In our case, we will use a hybrid approach which is to first remove the data that contain most missing values then fill in the rest of the missing values with the *linear interpolation* algorithm." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Next, count the number of rows of `austin` and `missing_values`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Your code here\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Calculate the ratio of missing rows to total rows" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Your code here\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "As you can see, there is a large proportion of missing data (over 10%). Perhaps we should evaluate which columns have the most missing data and remove those columns. For the remaining columns, we will perform a linear approximation of the missing data.\n", + "\n", + "We can find the number of missing rows in each column using the `.isna()` function. We then chain the `.sum` function to the `.isna()` function and find the number of missing rows per column" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Your code here\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### As you can see from the output, the majority of missing data is in one column called `PrecipitationSumInches`. What's the number of missing values in this column in ratio to its total number of rows?" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Your code here\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Over 10% data missing! Therefore, we prefer to remove this column instead of filling its missing values. It doesn't make sense to *guess* its missing values because the estimation will be too \n", + "\n", + "#### Remove this column from `austin` using the `.drop()` function. Use the `inplace=True` argument.\n", + "\n", + "*Hints:*\n", + "\n", + "* By supplying `inplace=True` to `drop()`, the original dataframe object will be changed in place and the function will return `None`. In contrast, if you don't supply `inplace=True`, which is equivalent to supplying `inplace=False` because `False` is the default value, the original dataframe object will be kept and the function returns a copy of the transformed dataframe object. In the latter case, you'll have to assign the returned object back to your variable.\n", + "\n", + "* Also, since you are dropping a column instead of a row, you'll need to supply `axis=1` to `drop()`.\n", + "\n", + "[Reference for `pandas.DataFrame.drop`](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.drop.html)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Your code here \n", + "\n", + "\n", + "# Print `austin` to confirm the column is indeed removed\n", + "\n", + "austin" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Next we will perform linear interpolation of the missing data.\n", + "\n", + "This means that we will use a linear algorithm to estimate the missing data. Linear interpolation assumes that there is a straight line between the points and the missing point will fall on that line. This is a good enough approximation for weather related data. Weather related data is typically a time series. Therefore, we do not want to drop rows from our data if possible. It is prefereable to estimate the missing values rather than remove the rows. However, if you have data from a single point in time, perhaps a better solution would be to remove the rows. \n", + "\n", + "If you would like to read more about linear interpolation, you can do so [here](https://en.wikipedia.org/wiki/Linear_interpolation).\n", + "\n", + "In the following cell, use the `.interpolate()` function on the entire dataframe. This time pass the `inplace=False` argument to the function and assign the interpolated dataframe to a new variable called `austin_fixed` so that we can compare with `austin`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Your code here\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Check to make sure `austin_fixed` contains no missing data. Also check `austin` - it still contains missing data." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Your code here\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Challenge 3 - Processing the `Events` Column" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Our dataframe contains one true text column - the Events column. We should evaluate this column to determine how to process it.\n", + "\n", + "Use the `value_counts()` function to evaluate the contents of this column" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Your code here:\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Reading the values of `Events` and reflecting what those values mean in the context of data, you realize this column indicates what weather events had happened in a particular day.\n", + "\n", + "#### What is the largest number of events happened in a single day? Enter your answer in the next cell." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Your answer:\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### We want to transform the string-type `Events` values to the numbers. This will allow us to apply machine learning algorithms easily.\n", + "\n", + "How? We will create a new column for each type of events (i.e. *Rain*, *Snow*, *Fog*, *Thunderstorm*. In each column, we use `1` to indicate if the corresponding event happened in that day and use `0` otherwise.\n", + "\n", + "Below we provide you a list of all event types. Loop the list and create a dummy column with `0` values for each event in `austin_fixed`. To create a new dummy column with `0` values, simply use `austin_fixed[event] = 0`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "event_list = ['Snow', 'Fog', 'Rain', 'Thunderstorm']\n", + "\n", + "# Your code here\n", + "\n", + "\n", + "# Print your new dataframe to check whether new columns have been created:\n", + "\n", + "austin_fixed" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Next, populate the actual values in the dummy columns of `austin_fixed`.\n", + "\n", + "You will check the *Events* column. If its string value contains `Rain`, then the *Rain* column should be `1`. The same for `Snow`, `Fog`, and `Thunderstorm`.\n", + "\n", + "*Hints:*\n", + "\n", + "* Use [`pandas.Series.str.contains()`](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.contains.html) to create the value series of each new column.\n", + "\n", + "* What if the values you populated are booleans instead of numbers? You can cast the boolean values to numbers by using `.astype(int)`. For instance, `pd.Series([True, True, False]).astype(int)` will return a new series with values of `[1, 1, 0]`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Your code here\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Print out `austin_fixed` to check if the event columns are populated with the intended values" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Your code here\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### If your code worked correctly, now we can drop the `Events` column as we don't need it any more." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Your code here\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Challenge 4 - Processing The `Date` Column\n", + "\n", + "The `Date` column is another non-numeric field in our dataset. A value in that field looks like `'2014-01-06'` which consists of the year, month, and day connected with hyphens. One way to convert the date string to numerical is using a similar approach as we used for `Events`, namely splitting the column into numerical `Year`, `Month`, and `Day` columns. In this challenge we'll show you another way which is to use the Python `datetime` library's `toordinal()` function. Depending on what actual machine learning analysis you will conduct, each approach has its pros and cons. Our goal today is to practice data preparation so we'll skip the discussion here.\n", + "\n", + "Here you can find the [reference](https://docs.python.org/3/library/datetime.html) and [example](https://stackoverflow.com/questions/39846918/convert-date-to-ordinal-python) for `toordinal`. The basic process is to first convert the string to a `datetime` object using `datetime.datetime.strptime`, then convert the `datetime` object to numerical using `toordinal`.\n", + "\n", + "#### In the cell below, convert the `Date` column values from string to numeric values using `toordinal()`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Your code here\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Print `austin_fixed` to check your `Date` column." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "austin_fixed.head(5)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Challenge 5 - Sampling and Holdout Sets" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Now that we have processed the data for machine learning, we will separate the data to test and training sets.\n", + "\n", + "We first train the model using only the training set. We check our metrics on the training set. We then apply the model to the test set and check our metrics on the test set as well. If the metrics are significantly more optimal on the training set, then we know we have overfit our model. We will need to revise our model to ensure it will be more applicable to data outside the test set." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### In the next cells we will separate the data into a training set and a test set using the `train_test_split()` function in scikit-learn.\n", + "\n", + "When using `scikit-learn` for machine learning, we first separate the data to predictor and response variables. This is the standard way of passing datasets into a model in `scikit-learn`. The `scikit-learn` will then find out whether the predictors and responses fit the model.\n", + "\n", + "In the next cell, assign the `TempAvgF` column to `y` and the remaining columns to `X`. Your `X` should be a subset of `austin_fixed` containing the following columns: \n", + "\n", + "```['Date',\n", + " 'TempHighF',\n", + " 'TempLowF',\n", + " 'DewPointHighF',\n", + " 'DewPointAvgF',\n", + " 'DewPointLowF',\n", + " 'HumidityHighPercent',\n", + " 'HumidityAvgPercent',\n", + " 'HumidityLowPercent',\n", + " 'SeaLevelPressureHighInches',\n", + " 'SeaLevelPressureAvgInches',\n", + " 'SeaLevelPressureLowInches',\n", + " 'VisibilityHighMiles',\n", + " 'VisibilityAvgMiles',\n", + " 'VisibilityLowMiles',\n", + " 'WindHighMPH',\n", + " 'WindAvgMPH',\n", + " 'WindGustMPH',\n", + " 'Snow',\n", + " 'Fog',\n", + " 'Rain',\n", + " 'Thunderstorm']```\n", + " \n", + " Your `y` should be a subset of `austin_fixed` containing one column `TempAvgF`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Your code here:\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In the next cell, import `train_test_split` from `sklearn.model_selection`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#Your code here:\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now that we have split the data to predictor and response variables and imported the `train_test_split()` function, split `X` and `y` into `X_train`, `X_test`, `y_train`, and `y_test`. 80% of the data should be in the training set and 20% in the test set. `train_test_split()` reference can be accessed [here](https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.train_test_split.html).\n", + "\n", + "\n", + "Enter your code in the cell below:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#Your code here:\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Congratulations! Now you have finished the preparation of the dataset!" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Bonus Challenge 1\n", + "\n", + "#### While the above is the common practice to prepare most datasets, when it comes to time series data, we sometimes do not want to randomly select rows from our dataset.\n", + "\n", + "This is because many time series algorithms rely on observations having equal time distances between them. In such cases, we typically select the majority of rows as the test data and the last few rows as the training data. We don't use `train_test_split()` to select the train/test data because it returns random selections.\n", + "\n", + "In the following cell, compute the number of rows that account for 80% of our data and round it to the next integer. Assign this number to `ts_rows`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Your code here:\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Assign the first `ts_rows` rows of `X` to `X_ts_train` and the remaining rows to `X_ts_test`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Your code here:\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Assign the first `ts_rows` rows of `y` to `y_ts_train` and the remaining rows to `y_ts_test`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Your code here:\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Bonus Challenge 2\n", + "\n", + "As explained in the README, the main purpose of this lab is to show you the typical process of preparing data for machine learning which sometimes takes up 90% of your time. Data cleaning is a valuable skill to learn and you need to be proficient at various techniques including the ones we showed you above as well as others you'll learn in the future. In the real world this skill will help you perform your job successfully and efficiently.\n", + "\n", + "Now that we're done with data praparation, if you want to expeirence what you'll do in the rest 10% of your time, let's make the final leap.\n", + "\n", + "We will use scikit-learn's [*Support Vector Machines*](https://scikit-learn.org/stable/modules/svm.html) to compute the fit of our training data set, the test on our test data set.\n", + "\n", + "#### In the cell below, import `svm` from `sklearn`:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Your code here\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Now, call `svm.SVC.fit()` on `X_train` and `y_train`. Assign the returned value to a variable called `clf` which stands for *classifier*. Then obtain the test score for `X_test` and `y_test` by calling `clf.score()`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Your code here\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### You now see the model fit score of your test data set. If it's extremely low, it means your selected model is not a good fit and you should try other models.\n", + "\n", + "#### In addition to fitting `X_train`, `y_train`, `X_test`, and `y_test`, you can also fit `X_ts_train`, `y_ts_train`, `X_ts_test`, and `y_ts_test` if you completed Bonus Challenge 1." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Your code here\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### We hope you have learned a lot of useful stuff in this lab!" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "clase", + "language": "python", + "name": "clase" + }, + "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.8" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 759a044..10a5ced 100755 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -12,11 +12,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ - "#Import your libraries\n" + "#Import your libraries\n", + "\n", + "import warnings\n", + "warnings.simplefilter('ignore')\n", + "\n", + "import pandas as pd\n", + "pd.set_option('display.max_columns', None)\n", + "import numpy as np\n", + "\n", + "import pylab as plt\n", + "import seaborn as sns\n", + "%matplotlib inline" ] }, { @@ -38,11 +49,232 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
DateTempHighFTempAvgFTempLowFDewPointHighFDewPointAvgFDewPointLowFHumidityHighPercentHumidityAvgPercentHumidityLowPercentSeaLevelPressureHighInchesSeaLevelPressureAvgInchesSeaLevelPressureLowInchesVisibilityHighMilesVisibilityAvgMilesVisibilityLowMilesWindHighMPHWindAvgMPHWindGustMPHPrecipitationSumInchesEvents
02013-12-2174604567494393755729.8629.6829.591072204310.46Rain , Thunderstorm
12013-12-2256483943362893684330.4130.1329.8710105166250
22013-12-2358453231272376522730.5630.4930.4110101083120
32013-12-2461463136282189562230.5630.4530.310107124200
42013-12-2558504144403686715630.4130.3330.271010710216T
\n", + "
" + ], + "text/plain": [ + " Date TempHighF TempAvgF TempLowF DewPointHighF DewPointAvgF \\\n", + "0 2013-12-21 74 60 45 67 49 \n", + "1 2013-12-22 56 48 39 43 36 \n", + "2 2013-12-23 58 45 32 31 27 \n", + "3 2013-12-24 61 46 31 36 28 \n", + "4 2013-12-25 58 50 41 44 40 \n", + "\n", + " DewPointLowF HumidityHighPercent HumidityAvgPercent HumidityLowPercent \\\n", + "0 43 93 75 57 \n", + "1 28 93 68 43 \n", + "2 23 76 52 27 \n", + "3 21 89 56 22 \n", + "4 36 86 71 56 \n", + "\n", + " SeaLevelPressureHighInches SeaLevelPressureAvgInches \\\n", + "0 29.86 29.68 \n", + "1 30.41 30.13 \n", + "2 30.56 30.49 \n", + "3 30.56 30.45 \n", + "4 30.41 30.33 \n", + "\n", + " SeaLevelPressureLowInches VisibilityHighMiles VisibilityAvgMiles \\\n", + "0 29.59 10 7 \n", + "1 29.87 10 10 \n", + "2 30.41 10 10 \n", + "3 30.3 10 10 \n", + "4 30.27 10 10 \n", + "\n", + " VisibilityLowMiles WindHighMPH WindAvgMPH WindGustMPH \\\n", + "0 2 20 4 31 \n", + "1 5 16 6 25 \n", + "2 10 8 3 12 \n", + "3 7 12 4 20 \n", + "4 7 10 2 16 \n", + "\n", + " PrecipitationSumInches Events \n", + "0 0.46 Rain , Thunderstorm \n", + "1 0 \n", + "2 0 \n", + "3 0 \n", + "4 T " + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "\n", + "austin= pd.read_csv(\"../austin_weather.csv\")\n", + "austin.head()" ] }, { @@ -57,29 +289,164 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
TempHighFTempAvgFTempLowF
count1319.0000001319.0000001319.000000
mean80.86277570.64291159.902957
std14.76652314.04590414.190648
min32.00000029.00000019.000000
25%72.00000062.00000049.000000
50%83.00000073.00000063.000000
75%92.00000083.00000073.000000
max107.00000093.00000081.000000
\n", + "
" + ], + "text/plain": [ + " TempHighF TempAvgF TempLowF\n", + "count 1319.000000 1319.000000 1319.000000\n", + "mean 80.862775 70.642911 59.902957\n", + "std 14.766523 14.045904 14.190648\n", + "min 32.000000 29.000000 19.000000\n", + "25% 72.000000 62.000000 49.000000\n", + "50% 83.000000 73.000000 63.000000\n", + "75% 92.000000 83.000000 73.000000\n", + "max 107.000000 93.000000 81.000000" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "austin.describe()" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "RangeIndex: 1319 entries, 0 to 1318\n", + "Data columns (total 21 columns):\n", + " # Column Non-Null Count Dtype \n", + "--- ------ -------------- ----- \n", + " 0 Date 1319 non-null object\n", + " 1 TempHighF 1319 non-null int64 \n", + " 2 TempAvgF 1319 non-null int64 \n", + " 3 TempLowF 1319 non-null int64 \n", + " 4 DewPointHighF 1319 non-null object\n", + " 5 DewPointAvgF 1319 non-null object\n", + " 6 DewPointLowF 1319 non-null object\n", + " 7 HumidityHighPercent 1319 non-null object\n", + " 8 HumidityAvgPercent 1319 non-null object\n", + " 9 HumidityLowPercent 1319 non-null object\n", + " 10 SeaLevelPressureHighInches 1319 non-null object\n", + " 11 SeaLevelPressureAvgInches 1319 non-null object\n", + " 12 SeaLevelPressureLowInches 1319 non-null object\n", + " 13 VisibilityHighMiles 1319 non-null object\n", + " 14 VisibilityAvgMiles 1319 non-null object\n", + " 15 VisibilityLowMiles 1319 non-null object\n", + " 16 WindHighMPH 1319 non-null object\n", + " 17 WindAvgMPH 1319 non-null object\n", + " 18 WindGustMPH 1319 non-null object\n", + " 19 PrecipitationSumInches 1319 non-null object\n", + " 20 Events 1319 non-null object\n", + "dtypes: int64(3), object(18)\n", + "memory usage: 216.5+ KB\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "austin.info()" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "# Your code here\n", + "#comprobando la cabeza la mayoría de las variables son numéricas aunque han sido asignadas como tipo de objeto (sólo tenemos 3 objetos y el resto es int)\n", + "#la media está entre 70 y 93, la temperatura alta está entre 107 y 81 y la mínima entre 32 y 19." ] }, { @@ -113,20 +480,39 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array(['49', '36', '27', '28', '40', '39', '41', '26', '42', '22', '48',\n", + " '32', '8', '11', '45', '55', '61', '37', '47', '25', '23', '20',\n", + " '33', '30', '29', '17', '14', '13', '54', '59', '15', '24', '34',\n", + " '35', '57', '50', '53', '60', '46', '56', '51', '31', '38', '62',\n", + " '43', '63', '64', '67', '66', '58', '70', '68', '65', '69', '71',\n", + " '72', '-', '73', '74', '21', '44', '52', '12', '75', '76', '18'],\n", + " dtype=object)" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "austin.DewPointAvgF.unique()" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ - "# Your observation here\n" + "# Your observation here\n", + "#todos son int. Convertirlos de objeto a int ayudará a reducir la memoria y también se pueden tratar los números." ] }, { @@ -140,7 +526,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -153,11 +539,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "# Your code here\n", + "austin[wrong_type_columns] = austin[wrong_type_columns].apply(pd.to_numeric, errors='coerce')" ] }, { @@ -169,11 +556,47 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "RangeIndex: 1319 entries, 0 to 1318\n", + "Data columns (total 21 columns):\n", + " # Column Non-Null Count Dtype \n", + "--- ------ -------------- ----- \n", + " 0 Date 1319 non-null object \n", + " 1 TempHighF 1319 non-null int64 \n", + " 2 TempAvgF 1319 non-null int64 \n", + " 3 TempLowF 1319 non-null int64 \n", + " 4 DewPointHighF 1312 non-null float64\n", + " 5 DewPointAvgF 1312 non-null float64\n", + " 6 DewPointLowF 1312 non-null float64\n", + " 7 HumidityHighPercent 1317 non-null float64\n", + " 8 HumidityAvgPercent 1317 non-null float64\n", + " 9 HumidityLowPercent 1317 non-null float64\n", + " 10 SeaLevelPressureHighInches 1316 non-null float64\n", + " 11 SeaLevelPressureAvgInches 1316 non-null float64\n", + " 12 SeaLevelPressureLowInches 1316 non-null float64\n", + " 13 VisibilityHighMiles 1307 non-null float64\n", + " 14 VisibilityAvgMiles 1307 non-null float64\n", + " 15 VisibilityLowMiles 1307 non-null float64\n", + " 16 WindHighMPH 1317 non-null float64\n", + " 17 WindAvgMPH 1317 non-null float64\n", + " 18 WindGustMPH 1315 non-null float64\n", + " 19 PrecipitationSumInches 1195 non-null float64\n", + " 20 Events 1319 non-null object \n", + "dtypes: float64(16), int64(3), object(2)\n", + "memory usage: 216.5+ KB\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "austin.info()" ] }, { @@ -200,11 +623,428 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
DateTempHighFTempAvgFTempLowFDewPointHighFDewPointAvgFDewPointLowFHumidityHighPercentHumidityAvgPercentHumidityLowPercentSeaLevelPressureHighInchesSeaLevelPressureAvgInchesSeaLevelPressureLowInchesVisibilityHighMilesVisibilityAvgMilesVisibilityLowMilesWindHighMPHWindAvgMPHWindGustMPHPrecipitationSumInchesEvents
42013-12-2558504144.040.036.086.071.056.030.4130.3330.2710.010.07.010.02.016.0NaN
62013-12-2760534541.039.037.083.065.047.030.4630.3930.3410.09.07.07.01.011.0NaN
72013-12-2862514043.039.033.092.064.036.030.3330.1730.0410.010.07.010.02.014.0NaN
422014-02-0176665562.059.041.081.071.060.029.9129.8129.7510.010.09.014.06.026.0NaNRain
512014-02-1060483549.036.030.082.074.066.030.2330.1530.0210.08.04.015.09.023.0NaNRain
..................................................................
12692017-06-1294857572.068.062.087.062.036.029.9629.8929.8110.010.02.015.07.022.0NaNRain
12882017-07-0198897976.072.066.085.062.038.030.1330.0229.9210.09.06.015.07.024.0NaN
13042017-07-1798887775.071.066.088.063.038.029.9429.9029.8410.010.010.016.03.023.0NaNRain , Thunderstorm
13082017-07-21104917774.068.061.085.056.027.030.0129.9529.8610.010.010.014.05.024.0NaN
13132017-07-26103917875.070.061.091.058.025.030.1330.0329.9310.010.010.015.06.027.0NaN
\n", + "

136 rows × 21 columns

\n", + "
" + ], + "text/plain": [ + " Date TempHighF TempAvgF TempLowF DewPointHighF DewPointAvgF \\\n", + "4 2013-12-25 58 50 41 44.0 40.0 \n", + "6 2013-12-27 60 53 45 41.0 39.0 \n", + "7 2013-12-28 62 51 40 43.0 39.0 \n", + "42 2014-02-01 76 66 55 62.0 59.0 \n", + "51 2014-02-10 60 48 35 49.0 36.0 \n", + "... ... ... ... ... ... ... \n", + "1269 2017-06-12 94 85 75 72.0 68.0 \n", + "1288 2017-07-01 98 89 79 76.0 72.0 \n", + "1304 2017-07-17 98 88 77 75.0 71.0 \n", + "1308 2017-07-21 104 91 77 74.0 68.0 \n", + "1313 2017-07-26 103 91 78 75.0 70.0 \n", + "\n", + " DewPointLowF HumidityHighPercent HumidityAvgPercent \\\n", + "4 36.0 86.0 71.0 \n", + "6 37.0 83.0 65.0 \n", + "7 33.0 92.0 64.0 \n", + "42 41.0 81.0 71.0 \n", + "51 30.0 82.0 74.0 \n", + "... ... ... ... \n", + "1269 62.0 87.0 62.0 \n", + "1288 66.0 85.0 62.0 \n", + "1304 66.0 88.0 63.0 \n", + "1308 61.0 85.0 56.0 \n", + "1313 61.0 91.0 58.0 \n", + "\n", + " HumidityLowPercent SeaLevelPressureHighInches \\\n", + "4 56.0 30.41 \n", + "6 47.0 30.46 \n", + "7 36.0 30.33 \n", + "42 60.0 29.91 \n", + "51 66.0 30.23 \n", + "... ... ... \n", + "1269 36.0 29.96 \n", + "1288 38.0 30.13 \n", + "1304 38.0 29.94 \n", + "1308 27.0 30.01 \n", + "1313 25.0 30.13 \n", + "\n", + " SeaLevelPressureAvgInches SeaLevelPressureLowInches \\\n", + "4 30.33 30.27 \n", + "6 30.39 30.34 \n", + "7 30.17 30.04 \n", + "42 29.81 29.75 \n", + "51 30.15 30.02 \n", + "... ... ... \n", + "1269 29.89 29.81 \n", + "1288 30.02 29.92 \n", + "1304 29.90 29.84 \n", + "1308 29.95 29.86 \n", + "1313 30.03 29.93 \n", + "\n", + " VisibilityHighMiles VisibilityAvgMiles VisibilityLowMiles \\\n", + "4 10.0 10.0 7.0 \n", + "6 10.0 9.0 7.0 \n", + "7 10.0 10.0 7.0 \n", + "42 10.0 10.0 9.0 \n", + "51 10.0 8.0 4.0 \n", + "... ... ... ... \n", + "1269 10.0 10.0 2.0 \n", + "1288 10.0 9.0 6.0 \n", + "1304 10.0 10.0 10.0 \n", + "1308 10.0 10.0 10.0 \n", + "1313 10.0 10.0 10.0 \n", + "\n", + " WindHighMPH WindAvgMPH WindGustMPH PrecipitationSumInches \\\n", + "4 10.0 2.0 16.0 NaN \n", + "6 7.0 1.0 11.0 NaN \n", + "7 10.0 2.0 14.0 NaN \n", + "42 14.0 6.0 26.0 NaN \n", + "51 15.0 9.0 23.0 NaN \n", + "... ... ... ... ... \n", + "1269 15.0 7.0 22.0 NaN \n", + "1288 15.0 7.0 24.0 NaN \n", + "1304 16.0 3.0 23.0 NaN \n", + "1308 14.0 5.0 24.0 NaN \n", + "1313 15.0 6.0 27.0 NaN \n", + "\n", + " Events \n", + "4 \n", + "6 \n", + "7 \n", + "42 Rain \n", + "51 Rain \n", + "... ... \n", + "1269 Rain \n", + "1288 \n", + "1304 Rain , Thunderstorm \n", + "1308 \n", + "1313 \n", + "\n", + "[136 rows x 21 columns]" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "missing_values=austin[austin.isnull().any(axis=1)]\n", + "\n", + "missing_values" ] }, { @@ -233,11 +1073,23 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "((1319, 21), (136, 21))" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "austin.shape , missing_values.shape" ] }, { @@ -249,11 +1101,24 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "10.310841546626232" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "ratio=(136/1319)*100\n", + "ratio" ] }, { @@ -267,11 +1132,45 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Date 0\n", + "TempHighF 0\n", + "TempAvgF 0\n", + "TempLowF 0\n", + "DewPointHighF 7\n", + "DewPointAvgF 7\n", + "DewPointLowF 7\n", + "HumidityHighPercent 2\n", + "HumidityAvgPercent 2\n", + "HumidityLowPercent 2\n", + "SeaLevelPressureHighInches 3\n", + "SeaLevelPressureAvgInches 3\n", + "SeaLevelPressureLowInches 3\n", + "VisibilityHighMiles 12\n", + "VisibilityAvgMiles 12\n", + "VisibilityLowMiles 12\n", + "WindHighMPH 2\n", + "WindAvgMPH 2\n", + "WindGustMPH 4\n", + "PrecipitationSumInches 124\n", + "Events 0\n", + "dtype: int64" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "null_cols = austin.isnull().sum()\n", + "null_cols" ] }, { @@ -283,11 +1182,24 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "9.401061410159212" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "rationull=(124/1319)*100\n", + "rationull" ] }, { @@ -309,13 +1221,402 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
DateTempHighFTempAvgFTempLowFDewPointHighFDewPointAvgFDewPointLowFHumidityHighPercentHumidityAvgPercentHumidityLowPercentSeaLevelPressureHighInchesSeaLevelPressureAvgInchesSeaLevelPressureLowInchesVisibilityHighMilesVisibilityAvgMilesVisibilityLowMilesWindHighMPHWindAvgMPHWindGustMPHEvents
02013-12-2174604567.049.043.093.075.057.029.8629.6829.5910.07.02.020.04.031.0Rain , Thunderstorm
12013-12-2256483943.036.028.093.068.043.030.4130.1329.8710.010.05.016.06.025.0
22013-12-2358453231.027.023.076.052.027.030.5630.4930.4110.010.010.08.03.012.0
32013-12-2461463136.028.021.089.056.022.030.5630.4530.3010.010.07.012.04.020.0
42013-12-2558504144.040.036.086.071.056.030.4130.3330.2710.010.07.010.02.016.0
...............................................................
13142017-07-27103897571.067.061.082.054.025.030.0429.9729.8810.010.010.012.05.021.0
13152017-07-28105917671.064.055.087.054.020.029.9729.9029.8110.010.010.014.05.020.0
13162017-07-29107927772.064.055.082.051.019.029.9129.8629.7910.010.010.012.04.017.0
13172017-07-30106937970.068.063.069.048.027.029.9629.9129.8710.010.010.013.04.020.0
13182017-07-3199887766.061.054.064.043.022.030.0429.9729.9110.010.010.012.04.020.0
\n", + "

1319 rows × 20 columns

\n", + "
" + ], + "text/plain": [ + " Date TempHighF TempAvgF TempLowF DewPointHighF DewPointAvgF \\\n", + "0 2013-12-21 74 60 45 67.0 49.0 \n", + "1 2013-12-22 56 48 39 43.0 36.0 \n", + "2 2013-12-23 58 45 32 31.0 27.0 \n", + "3 2013-12-24 61 46 31 36.0 28.0 \n", + "4 2013-12-25 58 50 41 44.0 40.0 \n", + "... ... ... ... ... ... ... \n", + "1314 2017-07-27 103 89 75 71.0 67.0 \n", + "1315 2017-07-28 105 91 76 71.0 64.0 \n", + "1316 2017-07-29 107 92 77 72.0 64.0 \n", + "1317 2017-07-30 106 93 79 70.0 68.0 \n", + "1318 2017-07-31 99 88 77 66.0 61.0 \n", + "\n", + " DewPointLowF HumidityHighPercent HumidityAvgPercent \\\n", + "0 43.0 93.0 75.0 \n", + "1 28.0 93.0 68.0 \n", + "2 23.0 76.0 52.0 \n", + "3 21.0 89.0 56.0 \n", + "4 36.0 86.0 71.0 \n", + "... ... ... ... \n", + "1314 61.0 82.0 54.0 \n", + "1315 55.0 87.0 54.0 \n", + "1316 55.0 82.0 51.0 \n", + "1317 63.0 69.0 48.0 \n", + "1318 54.0 64.0 43.0 \n", + "\n", + " HumidityLowPercent SeaLevelPressureHighInches \\\n", + "0 57.0 29.86 \n", + "1 43.0 30.41 \n", + "2 27.0 30.56 \n", + "3 22.0 30.56 \n", + "4 56.0 30.41 \n", + "... ... ... \n", + "1314 25.0 30.04 \n", + "1315 20.0 29.97 \n", + "1316 19.0 29.91 \n", + "1317 27.0 29.96 \n", + "1318 22.0 30.04 \n", + "\n", + " SeaLevelPressureAvgInches SeaLevelPressureLowInches \\\n", + "0 29.68 29.59 \n", + "1 30.13 29.87 \n", + "2 30.49 30.41 \n", + "3 30.45 30.30 \n", + "4 30.33 30.27 \n", + "... ... ... \n", + "1314 29.97 29.88 \n", + "1315 29.90 29.81 \n", + "1316 29.86 29.79 \n", + "1317 29.91 29.87 \n", + "1318 29.97 29.91 \n", + "\n", + " VisibilityHighMiles VisibilityAvgMiles VisibilityLowMiles \\\n", + "0 10.0 7.0 2.0 \n", + "1 10.0 10.0 5.0 \n", + "2 10.0 10.0 10.0 \n", + "3 10.0 10.0 7.0 \n", + "4 10.0 10.0 7.0 \n", + "... ... ... ... \n", + "1314 10.0 10.0 10.0 \n", + "1315 10.0 10.0 10.0 \n", + "1316 10.0 10.0 10.0 \n", + "1317 10.0 10.0 10.0 \n", + "1318 10.0 10.0 10.0 \n", + "\n", + " WindHighMPH WindAvgMPH WindGustMPH Events \n", + "0 20.0 4.0 31.0 Rain , Thunderstorm \n", + "1 16.0 6.0 25.0 \n", + "2 8.0 3.0 12.0 \n", + "3 12.0 4.0 20.0 \n", + "4 10.0 2.0 16.0 \n", + "... ... ... ... ... \n", + "1314 12.0 5.0 21.0 \n", + "1315 14.0 5.0 20.0 \n", + "1316 12.0 4.0 17.0 \n", + "1317 13.0 4.0 20.0 \n", + "1318 12.0 4.0 20.0 \n", + "\n", + "[1319 rows x 20 columns]" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Your code here \n", - "\n", - "\n", + "austin.drop(columns=[\"PrecipitationSumInches\"] ,inplace=True,axis=1)\n", + " \n", "# Print `austin` to confirm the column is indeed removed\n", "\n", "austin" @@ -336,11 +1637,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "# Your code here\n", + "austin_fixed = austin.interpolate(inplace=False)" ] }, { @@ -352,11 +1654,86 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Date 0\n", + "TempHighF 0\n", + "TempAvgF 0\n", + "TempLowF 0\n", + "DewPointHighF 0\n", + "DewPointAvgF 0\n", + "DewPointLowF 0\n", + "HumidityHighPercent 0\n", + "HumidityAvgPercent 0\n", + "HumidityLowPercent 0\n", + "SeaLevelPressureHighInches 0\n", + "SeaLevelPressureAvgInches 0\n", + "SeaLevelPressureLowInches 0\n", + "VisibilityHighMiles 0\n", + "VisibilityAvgMiles 0\n", + "VisibilityLowMiles 0\n", + "WindHighMPH 0\n", + "WindAvgMPH 0\n", + "WindGustMPH 0\n", + "Events 0\n", + "dtype: int64" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "austin_fixed.isnull().sum()\n", + "#no missing value in austin_fixed" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Date 0\n", + "TempHighF 0\n", + "TempAvgF 0\n", + "TempLowF 0\n", + "DewPointHighF 7\n", + "DewPointAvgF 7\n", + "DewPointLowF 7\n", + "HumidityHighPercent 2\n", + "HumidityAvgPercent 2\n", + "HumidityLowPercent 2\n", + "SeaLevelPressureHighInches 3\n", + "SeaLevelPressureAvgInches 3\n", + "SeaLevelPressureLowInches 3\n", + "VisibilityHighMiles 12\n", + "VisibilityAvgMiles 12\n", + "VisibilityLowMiles 12\n", + "WindHighMPH 2\n", + "WindAvgMPH 2\n", + "WindGustMPH 4\n", + "Events 0\n", + "dtype: int64" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Your code here\n", + "austin.isnull().sum()\n", + "#still has missing values." ] }, { @@ -377,11 +1754,32 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here:\n" + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + " 903\n", + "Rain 192\n", + "Rain , Thunderstorm 137\n", + "Fog , Rain , Thunderstorm 33\n", + "Fog 21\n", + "Thunderstorm 17\n", + "Fog , Rain 14\n", + "Fog , Thunderstorm 1\n", + "Rain , Snow 1\n", + "Name: Events, dtype: int64" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Your code here:\n", + "austin.Events.value_counts()" ] }, { @@ -395,11 +1793,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": {}, "outputs": [], "source": [ - "# Your answer:\n" + "# Your answer:\n", + "#Fog , Rain , Thunderstorm" ] }, { @@ -415,14 +1814,466 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
DateTempHighFTempAvgFTempLowFDewPointHighFDewPointAvgFDewPointLowFHumidityHighPercentHumidityAvgPercentHumidityLowPercentSeaLevelPressureHighInchesSeaLevelPressureAvgInchesSeaLevelPressureLowInchesVisibilityHighMilesVisibilityAvgMilesVisibilityLowMilesWindHighMPHWindAvgMPHWindGustMPHEventsSnowFogRainThunderstorm
02013-12-2174604567.049.043.093.075.057.029.8629.6829.5910.07.02.020.04.031.0Rain , Thunderstorm0000
12013-12-2256483943.036.028.093.068.043.030.4130.1329.8710.010.05.016.06.025.00000
22013-12-2358453231.027.023.076.052.027.030.5630.4930.4110.010.010.08.03.012.00000
32013-12-2461463136.028.021.089.056.022.030.5630.4530.3010.010.07.012.04.020.00000
42013-12-2558504144.040.036.086.071.056.030.4130.3330.2710.010.07.010.02.016.00000
...........................................................................
13142017-07-27103897571.067.061.082.054.025.030.0429.9729.8810.010.010.012.05.021.00000
13152017-07-28105917671.064.055.087.054.020.029.9729.9029.8110.010.010.014.05.020.00000
13162017-07-29107927772.064.055.082.051.019.029.9129.8629.7910.010.010.012.04.017.00000
13172017-07-30106937970.068.063.069.048.027.029.9629.9129.8710.010.010.013.04.020.00000
13182017-07-3199887766.061.054.064.043.022.030.0429.9729.9110.010.010.012.04.020.00000
\n", + "

1319 rows × 24 columns

\n", + "
" + ], + "text/plain": [ + " Date TempHighF TempAvgF TempLowF DewPointHighF DewPointAvgF \\\n", + "0 2013-12-21 74 60 45 67.0 49.0 \n", + "1 2013-12-22 56 48 39 43.0 36.0 \n", + "2 2013-12-23 58 45 32 31.0 27.0 \n", + "3 2013-12-24 61 46 31 36.0 28.0 \n", + "4 2013-12-25 58 50 41 44.0 40.0 \n", + "... ... ... ... ... ... ... \n", + "1314 2017-07-27 103 89 75 71.0 67.0 \n", + "1315 2017-07-28 105 91 76 71.0 64.0 \n", + "1316 2017-07-29 107 92 77 72.0 64.0 \n", + "1317 2017-07-30 106 93 79 70.0 68.0 \n", + "1318 2017-07-31 99 88 77 66.0 61.0 \n", + "\n", + " DewPointLowF HumidityHighPercent HumidityAvgPercent \\\n", + "0 43.0 93.0 75.0 \n", + "1 28.0 93.0 68.0 \n", + "2 23.0 76.0 52.0 \n", + "3 21.0 89.0 56.0 \n", + "4 36.0 86.0 71.0 \n", + "... ... ... ... \n", + "1314 61.0 82.0 54.0 \n", + "1315 55.0 87.0 54.0 \n", + "1316 55.0 82.0 51.0 \n", + "1317 63.0 69.0 48.0 \n", + "1318 54.0 64.0 43.0 \n", + "\n", + " HumidityLowPercent SeaLevelPressureHighInches \\\n", + "0 57.0 29.86 \n", + "1 43.0 30.41 \n", + "2 27.0 30.56 \n", + "3 22.0 30.56 \n", + "4 56.0 30.41 \n", + "... ... ... \n", + "1314 25.0 30.04 \n", + "1315 20.0 29.97 \n", + "1316 19.0 29.91 \n", + "1317 27.0 29.96 \n", + "1318 22.0 30.04 \n", + "\n", + " SeaLevelPressureAvgInches SeaLevelPressureLowInches \\\n", + "0 29.68 29.59 \n", + "1 30.13 29.87 \n", + "2 30.49 30.41 \n", + "3 30.45 30.30 \n", + "4 30.33 30.27 \n", + "... ... ... \n", + "1314 29.97 29.88 \n", + "1315 29.90 29.81 \n", + "1316 29.86 29.79 \n", + "1317 29.91 29.87 \n", + "1318 29.97 29.91 \n", + "\n", + " VisibilityHighMiles VisibilityAvgMiles VisibilityLowMiles \\\n", + "0 10.0 7.0 2.0 \n", + "1 10.0 10.0 5.0 \n", + "2 10.0 10.0 10.0 \n", + "3 10.0 10.0 7.0 \n", + "4 10.0 10.0 7.0 \n", + "... ... ... ... \n", + "1314 10.0 10.0 10.0 \n", + "1315 10.0 10.0 10.0 \n", + "1316 10.0 10.0 10.0 \n", + "1317 10.0 10.0 10.0 \n", + "1318 10.0 10.0 10.0 \n", + "\n", + " WindHighMPH WindAvgMPH WindGustMPH Events Snow Fog \\\n", + "0 20.0 4.0 31.0 Rain , Thunderstorm 0 0 \n", + "1 16.0 6.0 25.0 0 0 \n", + "2 8.0 3.0 12.0 0 0 \n", + "3 12.0 4.0 20.0 0 0 \n", + "4 10.0 2.0 16.0 0 0 \n", + "... ... ... ... ... ... ... \n", + "1314 12.0 5.0 21.0 0 0 \n", + "1315 14.0 5.0 20.0 0 0 \n", + "1316 12.0 4.0 17.0 0 0 \n", + "1317 13.0 4.0 20.0 0 0 \n", + "1318 12.0 4.0 20.0 0 0 \n", + "\n", + " Rain Thunderstorm \n", + "0 0 0 \n", + "1 0 0 \n", + "2 0 0 \n", + "3 0 0 \n", + "4 0 0 \n", + "... ... ... \n", + "1314 0 0 \n", + "1315 0 0 \n", + "1316 0 0 \n", + "1317 0 0 \n", + "1318 0 0 \n", + "\n", + "[1319 rows x 24 columns]" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "event_list = ['Snow', 'Fog', 'Rain', 'Thunderstorm']\n", "\n", "# Your code here\n", "\n", + "for event in event_list:\n", + " austin_fixed[event] = 0\n", "\n", "# Print your new dataframe to check whether new columns have been created:\n", "\n", @@ -446,11 +2297,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "# Your code here\n", + "for e in event_list:\n", + " austin_fixed[e] = austin_fixed['Events'].str.contains(event).astype(int)" ] }, { @@ -462,11 +2315,111 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Date TempHighF TempAvgF TempLowF DewPointHighF DewPointAvgF \\\n", + "0 2013-12-21 74 60 45 67.0 49.0 \n", + "1 2013-12-22 56 48 39 43.0 36.0 \n", + "2 2013-12-23 58 45 32 31.0 27.0 \n", + "3 2013-12-24 61 46 31 36.0 28.0 \n", + "4 2013-12-25 58 50 41 44.0 40.0 \n", + "... ... ... ... ... ... ... \n", + "1314 2017-07-27 103 89 75 71.0 67.0 \n", + "1315 2017-07-28 105 91 76 71.0 64.0 \n", + "1316 2017-07-29 107 92 77 72.0 64.0 \n", + "1317 2017-07-30 106 93 79 70.0 68.0 \n", + "1318 2017-07-31 99 88 77 66.0 61.0 \n", + "\n", + " DewPointLowF HumidityHighPercent HumidityAvgPercent \\\n", + "0 43.0 93.0 75.0 \n", + "1 28.0 93.0 68.0 \n", + "2 23.0 76.0 52.0 \n", + "3 21.0 89.0 56.0 \n", + "4 36.0 86.0 71.0 \n", + "... ... ... ... \n", + "1314 61.0 82.0 54.0 \n", + "1315 55.0 87.0 54.0 \n", + "1316 55.0 82.0 51.0 \n", + "1317 63.0 69.0 48.0 \n", + "1318 54.0 64.0 43.0 \n", + "\n", + " HumidityLowPercent SeaLevelPressureHighInches \\\n", + "0 57.0 29.86 \n", + "1 43.0 30.41 \n", + "2 27.0 30.56 \n", + "3 22.0 30.56 \n", + "4 56.0 30.41 \n", + "... ... ... \n", + "1314 25.0 30.04 \n", + "1315 20.0 29.97 \n", + "1316 19.0 29.91 \n", + "1317 27.0 29.96 \n", + "1318 22.0 30.04 \n", + "\n", + " SeaLevelPressureAvgInches SeaLevelPressureLowInches \\\n", + "0 29.68 29.59 \n", + "1 30.13 29.87 \n", + "2 30.49 30.41 \n", + "3 30.45 30.30 \n", + "4 30.33 30.27 \n", + "... ... ... \n", + "1314 29.97 29.88 \n", + "1315 29.90 29.81 \n", + "1316 29.86 29.79 \n", + "1317 29.91 29.87 \n", + "1318 29.97 29.91 \n", + "\n", + " VisibilityHighMiles VisibilityAvgMiles VisibilityLowMiles \\\n", + "0 10.0 7.0 2.0 \n", + "1 10.0 10.0 5.0 \n", + "2 10.0 10.0 10.0 \n", + "3 10.0 10.0 7.0 \n", + "4 10.0 10.0 7.0 \n", + "... ... ... ... \n", + "1314 10.0 10.0 10.0 \n", + "1315 10.0 10.0 10.0 \n", + "1316 10.0 10.0 10.0 \n", + "1317 10.0 10.0 10.0 \n", + "1318 10.0 10.0 10.0 \n", + "\n", + " WindHighMPH WindAvgMPH WindGustMPH Events Snow Fog \\\n", + "0 20.0 4.0 31.0 Rain , Thunderstorm 1 1 \n", + "1 16.0 6.0 25.0 0 0 \n", + "2 8.0 3.0 12.0 0 0 \n", + "3 12.0 4.0 20.0 0 0 \n", + "4 10.0 2.0 16.0 0 0 \n", + "... ... ... ... ... ... ... \n", + "1314 12.0 5.0 21.0 0 0 \n", + "1315 14.0 5.0 20.0 0 0 \n", + "1316 12.0 4.0 17.0 0 0 \n", + "1317 13.0 4.0 20.0 0 0 \n", + "1318 12.0 4.0 20.0 0 0 \n", + "\n", + " Rain Thunderstorm \n", + "0 1 1 \n", + "1 0 0 \n", + "2 0 0 \n", + "3 0 0 \n", + "4 0 0 \n", + "... ... ... \n", + "1314 0 0 \n", + "1315 0 0 \n", + "1316 0 0 \n", + "1317 0 0 \n", + "1318 0 0 \n", + "\n", + "[1319 rows x 24 columns]\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "print(austin_fixed)" ] }, { @@ -478,11 +2431,251 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 31, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "# Your code here\n", + "austin_fixed.drop(columns=[\"Events\"] ,inplace=True,axis=1)" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
DateTempHighFTempAvgFTempLowFDewPointHighFDewPointAvgFDewPointLowFHumidityHighPercentHumidityAvgPercentHumidityLowPercentSeaLevelPressureHighInchesSeaLevelPressureAvgInchesSeaLevelPressureLowInchesVisibilityHighMilesVisibilityAvgMilesVisibilityLowMilesWindHighMPHWindAvgMPHWindGustMPHSnowFogRainThunderstorm
02013-12-2174604567.049.043.093.075.057.029.8629.6829.5910.07.02.020.04.031.01111
12013-12-2256483943.036.028.093.068.043.030.4130.1329.8710.010.05.016.06.025.00000
22013-12-2358453231.027.023.076.052.027.030.5630.4930.4110.010.010.08.03.012.00000
32013-12-2461463136.028.021.089.056.022.030.5630.4530.3010.010.07.012.04.020.00000
42013-12-2558504144.040.036.086.071.056.030.4130.3330.2710.010.07.010.02.016.00000
\n", + "
" + ], + "text/plain": [ + " Date TempHighF TempAvgF TempLowF DewPointHighF DewPointAvgF \\\n", + "0 2013-12-21 74 60 45 67.0 49.0 \n", + "1 2013-12-22 56 48 39 43.0 36.0 \n", + "2 2013-12-23 58 45 32 31.0 27.0 \n", + "3 2013-12-24 61 46 31 36.0 28.0 \n", + "4 2013-12-25 58 50 41 44.0 40.0 \n", + "\n", + " DewPointLowF HumidityHighPercent HumidityAvgPercent HumidityLowPercent \\\n", + "0 43.0 93.0 75.0 57.0 \n", + "1 28.0 93.0 68.0 43.0 \n", + "2 23.0 76.0 52.0 27.0 \n", + "3 21.0 89.0 56.0 22.0 \n", + "4 36.0 86.0 71.0 56.0 \n", + "\n", + " SeaLevelPressureHighInches SeaLevelPressureAvgInches \\\n", + "0 29.86 29.68 \n", + "1 30.41 30.13 \n", + "2 30.56 30.49 \n", + "3 30.56 30.45 \n", + "4 30.41 30.33 \n", + "\n", + " SeaLevelPressureLowInches VisibilityHighMiles VisibilityAvgMiles \\\n", + "0 29.59 10.0 7.0 \n", + "1 29.87 10.0 10.0 \n", + "2 30.41 10.0 10.0 \n", + "3 30.30 10.0 10.0 \n", + "4 30.27 10.0 10.0 \n", + "\n", + " VisibilityLowMiles WindHighMPH WindAvgMPH WindGustMPH Snow Fog Rain \\\n", + "0 2.0 20.0 4.0 31.0 1 1 1 \n", + "1 5.0 16.0 6.0 25.0 0 0 0 \n", + "2 10.0 8.0 3.0 12.0 0 0 0 \n", + "3 7.0 12.0 4.0 20.0 0 0 0 \n", + "4 7.0 10.0 2.0 16.0 0 0 0 \n", + "\n", + " Thunderstorm \n", + "0 1 \n", + "1 0 \n", + "2 0 \n", + "3 0 \n", + "4 0 " + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "austin_fixed.head()\n" ] }, { @@ -500,11 +2693,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 33, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "# Your code here\n", + "import datetime\n", + "from datetime import datetime\n", + "import datetime as dt" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [], + "source": [ + "austin_fixed[\"Date\"] = pd.to_datetime(austin_fixed[\"Date\"])" ] }, { @@ -516,9 +2721,239 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
DateTempHighFTempAvgFTempLowFDewPointHighFDewPointAvgFDewPointLowFHumidityHighPercentHumidityAvgPercentHumidityLowPercentSeaLevelPressureHighInchesSeaLevelPressureAvgInchesSeaLevelPressureLowInchesVisibilityHighMilesVisibilityAvgMilesVisibilityLowMilesWindHighMPHWindAvgMPHWindGustMPHSnowFogRainThunderstorm
02013-12-2174604567.049.043.093.075.057.029.8629.6829.5910.07.02.020.04.031.01111
12013-12-2256483943.036.028.093.068.043.030.4130.1329.8710.010.05.016.06.025.00000
22013-12-2358453231.027.023.076.052.027.030.5630.4930.4110.010.010.08.03.012.00000
32013-12-2461463136.028.021.089.056.022.030.5630.4530.3010.010.07.012.04.020.00000
42013-12-2558504144.040.036.086.071.056.030.4130.3330.2710.010.07.010.02.016.00000
\n", + "
" + ], + "text/plain": [ + " Date TempHighF TempAvgF TempLowF DewPointHighF DewPointAvgF \\\n", + "0 2013-12-21 74 60 45 67.0 49.0 \n", + "1 2013-12-22 56 48 39 43.0 36.0 \n", + "2 2013-12-23 58 45 32 31.0 27.0 \n", + "3 2013-12-24 61 46 31 36.0 28.0 \n", + "4 2013-12-25 58 50 41 44.0 40.0 \n", + "\n", + " DewPointLowF HumidityHighPercent HumidityAvgPercent HumidityLowPercent \\\n", + "0 43.0 93.0 75.0 57.0 \n", + "1 28.0 93.0 68.0 43.0 \n", + "2 23.0 76.0 52.0 27.0 \n", + "3 21.0 89.0 56.0 22.0 \n", + "4 36.0 86.0 71.0 56.0 \n", + "\n", + " SeaLevelPressureHighInches SeaLevelPressureAvgInches \\\n", + "0 29.86 29.68 \n", + "1 30.41 30.13 \n", + "2 30.56 30.49 \n", + "3 30.56 30.45 \n", + "4 30.41 30.33 \n", + "\n", + " SeaLevelPressureLowInches VisibilityHighMiles VisibilityAvgMiles \\\n", + "0 29.59 10.0 7.0 \n", + "1 29.87 10.0 10.0 \n", + "2 30.41 10.0 10.0 \n", + "3 30.30 10.0 10.0 \n", + "4 30.27 10.0 10.0 \n", + "\n", + " VisibilityLowMiles WindHighMPH WindAvgMPH WindGustMPH Snow Fog Rain \\\n", + "0 2.0 20.0 4.0 31.0 1 1 1 \n", + "1 5.0 16.0 6.0 25.0 0 0 0 \n", + "2 10.0 8.0 3.0 12.0 0 0 0 \n", + "3 7.0 12.0 4.0 20.0 0 0 0 \n", + "4 7.0 10.0 2.0 16.0 0 0 0 \n", + "\n", + " Thunderstorm \n", + "0 1 \n", + "1 0 \n", + "2 0 \n", + "3 0 \n", + "4 0 " + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "austin_fixed.head(5)" ] @@ -577,11 +3012,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 36, "metadata": {}, "outputs": [], "source": [ - "# Your code here:\n" + "# train_test_split\n", + "from sklearn.model_selection import train_test_split as tts\n", + "from sklearn.model_selection import train_test_split" ] }, { @@ -748,9 +3185,9 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "clase", "language": "python", - "name": "python3" + "name": "clase" }, "language_info": { "codemirror_mode": { @@ -762,7 +3199,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.6" + "version": "3.8.8" } }, "nbformat": 4,