You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
544 lines
56 KiB
544 lines
56 KiB
2 years ago
|
{
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"___\n",
|
||
|
"\n",
|
||
|
"<a href='http://www.pieriandata.com'><img src='../Pierian_Data_Logo.png'/></a>\n",
|
||
|
"___\n",
|
||
|
"<center><em>Copyright Pierian Data</em></center>\n",
|
||
|
"<center><em>For more information, visit us at <a href='http://www.pieriandata.com'>www.pieriandata.com</a></em></center>"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# Pandas Time Series Exercise Set #1 - Solution\n",
|
||
|
"\n",
|
||
|
"For this set of exercises we'll use a dataset containing monthly milk production values in pounds per cow from January 1962 to December 1975.\n",
|
||
|
"\n",
|
||
|
"<div class=\"alert alert-danger\" style=\"margin: 10px\"><strong>IMPORTANT NOTE!</strong> Make sure you don't run the cells directly above the example output shown, <br>otherwise you will end up writing over the example output!</div>"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 16,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"168\n",
|
||
|
" Date Production\n",
|
||
|
"0 1962-01 589\n",
|
||
|
"1 1962-02 561\n",
|
||
|
"2 1962-03 640\n",
|
||
|
"3 1962-04 656\n",
|
||
|
"4 1962-05 727\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"# RUN THIS CELL\n",
|
||
|
"import pandas as pd\n",
|
||
|
"%matplotlib inline\n",
|
||
|
"\n",
|
||
|
"df = pd.read_csv('../Data/monthly_milk_production.csv', encoding='utf8')\n",
|
||
|
"title = \"Monthly milk production: pounds per cow. Jan '62 - Dec '75\"\n",
|
||
|
"\n",
|
||
|
"print(len(df))\n",
|
||
|
"print(df.head())"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"So <tt>df</tt> has 168 records and 2 columns."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"### 1. What is the current data type of the Date column?\n",
|
||
|
"HINT: We show how to list column dtypes in the first set of DataFrame lectures."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {
|
||
|
"collapsed": true
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# CODE HERE\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 17,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"Date object\n",
|
||
|
"Production int64\n",
|
||
|
"dtype: object"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 17,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"# DON'T WRITE HERE\n",
|
||
|
"df.dtypes"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"### 2. Change the Date column to a datetime format"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {
|
||
|
"collapsed": true
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": []
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 18,
|
||
|
"metadata": {
|
||
|
"scrolled": true
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"Date datetime64[ns]\n",
|
||
|
"Production int64\n",
|
||
|
"dtype: object"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 18,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"# DON'T WRITE HERE\n",
|
||
|
"df['Date']=pd.to_datetime(df['Date'])\n",
|
||
|
"df.dtypes"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"### 3. Set the Date column to be the new index"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {
|
||
|
"collapsed": true
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": []
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 19,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/html": [
|
||
|
"<div>\n",
|
||
|
"<style scoped>\n",
|
||
|
" .dataframe tbody tr th:only-of-type {\n",
|
||
|
" vertical-align: middle;\n",
|
||
|
" }\n",
|
||
|
"\n",
|
||
|
" .dataframe tbody tr th {\n",
|
||
|
" vertical-align: top;\n",
|
||
|
" }\n",
|
||
|
"\n",
|
||
|
" .dataframe thead th {\n",
|
||
|
" text-align: right;\n",
|
||
|
" }\n",
|
||
|
"</style>\n",
|
||
|
"<table border=\"1\" class=\"dataframe\">\n",
|
||
|
" <thead>\n",
|
||
|
" <tr style=\"text-align: right;\">\n",
|
||
|
" <th></th>\n",
|
||
|
" <th>Production</th>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>Date</th>\n",
|
||
|
" <th></th>\n",
|
||
|
" </tr>\n",
|
||
|
" </thead>\n",
|
||
|
" <tbody>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>1962-01-01</th>\n",
|
||
|
" <td>589</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>1962-02-01</th>\n",
|
||
|
" <td>561</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>1962-03-01</th>\n",
|
||
|
" <td>640</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>1962-04-01</th>\n",
|
||
|
" <td>656</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>1962-05-01</th>\n",
|
||
|
" <td>727</td>\n",
|
||
|
" </tr>\n",
|
||
|
" </tbody>\n",
|
||
|
"</table>\n",
|
||
|
"</div>"
|
||
|
],
|
||
|
"text/plain": [
|
||
|
" Production\n",
|
||
|
"Date \n",
|
||
|
"1962-01-01 589\n",
|
||
|
"1962-02-01 561\n",
|
||
|
"1962-03-01 640\n",
|
||
|
"1962-04-01 656\n",
|
||
|
"1962-05-01 727"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 19,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"# DON'T WRITE HERE\n",
|
||
|
"df.set_index('Date',inplace=True)\n",
|
||
|
"df.head()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"### 4. Plot the DataFrame with a simple line plot. What do you notice about the plot?"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {
|
||
|
"collapsed": true
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": []
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 20,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAEKCAYAAAAcgp5RAAA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DuilSsCwFJheOHMVxUEfB7ERD/SkYBrjU1G6yYm+hDweYa2bppNilKtrls3mSiP6DkczhWiKCmYiKli7JZ9o1ab+OD1EENE74LQVxTEg6pwTiVE10osS1LLuiGEuCLKrJfAmOQt1eqoyBtnBwQXeg7nKqEo1XHDlOp5u5WQzVcVxDRBzsa05KYLEb1qhbQ872UXIuRmk6IktyJvQPXpl4asuikaEtKAer0AsFzcOPYNF3oO5yqhUFVwTSYM0e9xbWZ6odqyQqIB1QpxJaKvtiL6dCSAZRfOLMntkTfgjs3SKjHtKNt0IVfhFlzoOZyrALneRK3eREz0Y2sy5Kp1wyJZQgiysQCWCsMLnFHoUxEBq2V56E1TrDM4EmgJfTYqDu3R6xG9waMH3EnyugUXeg7nKoCJUVT0YdtYCDMuTZksVNs3NGUi7tSQFwyNTelIAPUmbZt/44SSPufGcL3RANYrylCdt4WOc7nQczicK4JeBhn0Y+tYCBdWyq40NhWluh55A1qE7EbVjSEZm9aEc1j7xnizY2T1s5376UXDGAgASIUD8BAu9BwO5zLTEjk/JuIiynIDFXn4WvpCtVU/DkAfFDYMbPSxLvRhAcBwYgwYrBuj0OsJZOd2EysxZU82Xg/BWHhjdcdyoedwrgJaCzd8SGnCuTKkcDY0QY51VLHkq8NZIXq5otsRfa09aQoAmcjwTVOFHjeQjVZLb0noCSG/Qgh5lRDyGiHkV7X
|
||
|
"text/plain": [
|
||
|
"<Figure size 432x288 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {
|
||
|
"needs_background": "light"
|
||
|
},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"# DON'T WRITE HERE\n",
|
||
|
"df.plot();\n",
|
||
|
"\n",
|
||
|
"# THE PLOT SHOWS CONSISTENT SEASONALITY, AS WELL AS AN UPWARD TREND"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"### 5. Add a column called 'Month' that takes the month value from the index\n",
|
||
|
"HINT: You have to call <tt>df.index</tt> as <tt>df['Date']</tt> won't work.\n",
|
||
|
"\n",
|
||
|
"<strong>BONUS: See if you can obtain the <em>name</em> of the month instead of a number!</strong>"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {
|
||
|
"collapsed": true
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": []
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 28,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/html": [
|
||
|
"<div>\n",
|
||
|
"<style scoped>\n",
|
||
|
" .dataframe tbody tr th:only-of-type {\n",
|
||
|
" vertical-align: middle;\n",
|
||
|
" }\n",
|
||
|
"\n",
|
||
|
" .dataframe tbody tr th {\n",
|
||
|
" vertical-align: top;\n",
|
||
|
" }\n",
|
||
|
"\n",
|
||
|
" .dataframe thead th {\n",
|
||
|
" text-align: right;\n",
|
||
|
" }\n",
|
||
|
"</style>\n",
|
||
|
"<table border=\"1\" class=\"dataframe\">\n",
|
||
|
" <thead>\n",
|
||
|
" <tr style=\"text-align: right;\">\n",
|
||
|
" <th></th>\n",
|
||
|
" <th>Production</th>\n",
|
||
|
" <th>Month</th>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>Date</th>\n",
|
||
|
" <th></th>\n",
|
||
|
" <th></th>\n",
|
||
|
" </tr>\n",
|
||
|
" </thead>\n",
|
||
|
" <tbody>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>1962-01-01</th>\n",
|
||
|
" <td>589</td>\n",
|
||
|
" <td>1</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>1962-02-01</th>\n",
|
||
|
" <td>561</td>\n",
|
||
|
" <td>2</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>1962-03-01</th>\n",
|
||
|
" <td>640</td>\n",
|
||
|
" <td>3</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>1962-04-01</th>\n",
|
||
|
" <td>656</td>\n",
|
||
|
" <td>4</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>1962-05-01</th>\n",
|
||
|
" <td>727</td>\n",
|
||
|
" <td>5</td>\n",
|
||
|
" </tr>\n",
|
||
|
" </tbody>\n",
|
||
|
"</table>\n",
|
||
|
"</div>"
|
||
|
],
|
||
|
"text/plain": [
|
||
|
" Production Month\n",
|
||
|
"Date \n",
|
||
|
"1962-01-01 589 1\n",
|
||
|
"1962-02-01 561 2\n",
|
||
|
"1962-03-01 640 3\n",
|
||
|
"1962-04-01 656 4\n",
|
||
|
"1962-05-01 727 5"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 28,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"# DON'T WRITE HERE\n",
|
||
|
"df['Month']=df.index.month\n",
|
||
|
"df.head()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 22,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/html": [
|
||
|
"<div>\n",
|
||
|
"<style scoped>\n",
|
||
|
" .dataframe tbody tr th:only-of-type {\n",
|
||
|
" vertical-align: middle;\n",
|
||
|
" }\n",
|
||
|
"\n",
|
||
|
" .dataframe tbody tr th {\n",
|
||
|
" vertical-align: top;\n",
|
||
|
" }\n",
|
||
|
"\n",
|
||
|
" .dataframe thead th {\n",
|
||
|
" text-align: right;\n",
|
||
|
" }\n",
|
||
|
"</style>\n",
|
||
|
"<table border=\"1\" class=\"dataframe\">\n",
|
||
|
" <thead>\n",
|
||
|
" <tr style=\"text-align: right;\">\n",
|
||
|
" <th></th>\n",
|
||
|
" <th>Production</th>\n",
|
||
|
" <th>Month</th>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>Date</th>\n",
|
||
|
" <th></th>\n",
|
||
|
" <th></th>\n",
|
||
|
" </tr>\n",
|
||
|
" </thead>\n",
|
||
|
" <tbody>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>1962-01-01</th>\n",
|
||
|
" <td>589</td>\n",
|
||
|
" <td>January</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>1962-02-01</th>\n",
|
||
|
" <td>561</td>\n",
|
||
|
" <td>February</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>1962-03-01</th>\n",
|
||
|
" <td>640</td>\n",
|
||
|
" <td>March</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>1962-04-01</th>\n",
|
||
|
" <td>656</td>\n",
|
||
|
" <td>April</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>1962-05-01</th>\n",
|
||
|
" <td>727</td>\n",
|
||
|
" <td>May</td>\n",
|
||
|
" </tr>\n",
|
||
|
" </tbody>\n",
|
||
|
"</table>\n",
|
||
|
"</div>"
|
||
|
],
|
||
|
"text/plain": [
|
||
|
" Production Month\n",
|
||
|
"Date \n",
|
||
|
"1962-01-01 589 January\n",
|
||
|
"1962-02-01 561 February\n",
|
||
|
"1962-03-01 640 March\n",
|
||
|
"1962-04-01 656 April\n",
|
||
|
"1962-05-01 727 May"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 22,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"# BONUS SOLUTION:\n",
|
||
|
"df['Month']=df.index.strftime('%B')\n",
|
||
|
"df.head()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"### 6. Create a BoxPlot that groups by the Month field"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {
|
||
|
"collapsed": true
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": []
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 29,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAt4AAAFYCAYAAABklfsHAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAIABJREFUeJzt3Xm0pFV97vHvE0FluozaYQqtCVG8CAS5hsTEtBKNiIrJVaMhEb1GMhiH6LqhMQMhS5LmZnK6yxsjhEYRJcSBgGFBSB9dGcCgAg5IJAjSgoICLQ2taczv/vG+JxaHM3VVnbdOVX0/a9U6Ve9Qe++qMzxn1373TlUhSZIkaWV936grIEmSJE0Dg7ckSZLUAYO3JEmS1AGDtyRJktQBg7ckSZLUAYO3JEmS1AGDtyQtIcm5Sd4y6nqM2mKvQ5JXJPnHrus0TEluSfLTo66HpMll8JY0NtpgtC3J1iT3JLk0ycGjrlevJJXkh0Zdj3GWZKZ9HY+cs/0j7fZ1QyjDf6Ykdc7gLWncPL+qdgf2B74OvGPE9VkxaUzr7+l/A14++yDJvsCxwF0jq5EkDWhaf6FLGnNV9W3gIuBJs9uS7JnkvCR3Jbk1ye/MBtck70pyUc+xZyW5sg2365JsTvLmJN9oe9ZPWqjsJK9OclOSu5NcnOSAdvsn2kOua3vlf36ecx+R5E/bcr6c5DfaXtyd2v0zSc5M8k/AA8DjkxzQlnN3W+6re57vIT23s23peXxLktOSfKH9lOCvkjy6Z//zklyb5N4k/5z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ziHmkiSJEkdMHhLkiRJHTB4S5IkSR0weEuSJEkdMHhLkiRJHTB4S5IkSR0weEuSJEkdMHhLkiRJHTB4S5IkSR0
|
||
|
"text/plain": [
|
||
|
"<Figure size 864x360 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {
|
||
|
"needs_background": "light"
|
||
|
},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"# DON'T WRITE HERE\n",
|
||
|
"df.boxplot(by='Month',figsize=(12,5));"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# Great Job!"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"metadata": {
|
||
|
"kernelspec": {
|
||
|
"display_name": "Python 3",
|
||
|
"language": "python",
|
||
|
"name": "python3"
|
||
|
},
|
||
|
"language_info": {
|
||
|
"codemirror_mode": {
|
||
|
"name": "ipython",
|
||
|
"version": 3
|
||
|
},
|
||
|
"file_extension": ".py",
|
||
|
"mimetype": "text/x-python",
|
||
|
"name": "python",
|
||
|
"nbconvert_exporter": "python",
|
||
|
"pygments_lexer": "ipython3",
|
||
|
"version": "3.7.6"
|
||
|
}
|
||
|
},
|
||
|
"nbformat": 4,
|
||
|
"nbformat_minor": 1
|
||
|
}
|