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.
1244 lines
202 KiB
1244 lines
202 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": [
|
||
|
"# Time Series with Pandas Project Exercise\n",
|
||
|
"\n",
|
||
|
"For this exercise, answer the questions below given the dataset: https://fred.stlouisfed.org/series/UMTMVS\n",
|
||
|
"\n",
|
||
|
"This dataset is the Value of Manufacturers' Shipments for All Manufacturing Industries."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"**Import any necessary libraries.**"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 42,
|
||
|
"metadata": {
|
||
|
"collapsed": true
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# CODE HERE"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 43,
|
||
|
"metadata": {
|
||
|
"collapsed": true
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"import numpy as np\n",
|
||
|
"import pandas as pd\n",
|
||
|
"%matplotlib inline"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"**Read in the data UMTMVS.csv file from the Data folder**"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 44,
|
||
|
"metadata": {
|
||
|
"collapsed": true
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# CODE HERE"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 45,
|
||
|
"metadata": {
|
||
|
"collapsed": true
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"df = pd.read_csv('../Data/UMTMVS.csv')"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"**Check the head of the data**"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 46,
|
||
|
"metadata": {
|
||
|
"collapsed": true
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# CODE HERE"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 47,
|
||
|
"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>DATE</th>\n",
|
||
|
" <th>UMTMVS</th>\n",
|
||
|
" </tr>\n",
|
||
|
" </thead>\n",
|
||
|
" <tbody>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>1992-01-01</td>\n",
|
||
|
" <td>209438.0</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>1</th>\n",
|
||
|
" <td>1992-02-01</td>\n",
|
||
|
" <td>232679.0</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>2</th>\n",
|
||
|
" <td>1992-03-01</td>\n",
|
||
|
" <td>249673.0</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>3</th>\n",
|
||
|
" <td>1992-04-01</td>\n",
|
||
|
" <td>239666.0</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>4</th>\n",
|
||
|
" <td>1992-05-01</td>\n",
|
||
|
" <td>243231.0</td>\n",
|
||
|
" </tr>\n",
|
||
|
" </tbody>\n",
|
||
|
"</table>\n",
|
||
|
"</div>"
|
||
|
],
|
||
|
"text/plain": [
|
||
|
" DATE UMTMVS\n",
|
||
|
"0 1992-01-01 209438.0\n",
|
||
|
"1 1992-02-01 232679.0\n",
|
||
|
"2 1992-03-01 249673.0\n",
|
||
|
"3 1992-04-01 239666.0\n",
|
||
|
"4 1992-05-01 243231.0"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 47,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"df.head()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"**Set the DATE column as the index.**"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 48,
|
||
|
"metadata": {
|
||
|
"collapsed": true
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# CODE HERE"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 49,
|
||
|
"metadata": {
|
||
|
"collapsed": true
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"df = df.set_index('DATE')"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 50,
|
||
|
"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>UMTMVS</th>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>DATE</th>\n",
|
||
|
" <th></th>\n",
|
||
|
" </tr>\n",
|
||
|
" </thead>\n",
|
||
|
" <tbody>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>1992-01-01</th>\n",
|
||
|
" <td>209438.0</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>1992-02-01</th>\n",
|
||
|
" <td>232679.0</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>1992-03-01</th>\n",
|
||
|
" <td>249673.0</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>1992-04-01</th>\n",
|
||
|
" <td>239666.0</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>1992-05-01</th>\n",
|
||
|
" <td>243231.0</td>\n",
|
||
|
" </tr>\n",
|
||
|
" </tbody>\n",
|
||
|
"</table>\n",
|
||
|
"</div>"
|
||
|
],
|
||
|
"text/plain": [
|
||
|
" UMTMVS\n",
|
||
|
"DATE \n",
|
||
|
"1992-01-01 209438.0\n",
|
||
|
"1992-02-01 232679.0\n",
|
||
|
"1992-03-01 249673.0\n",
|
||
|
"1992-04-01 239666.0\n",
|
||
|
"1992-05-01 243231.0"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 50,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"df.head()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"**Check the data type of the index.**"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 51,
|
||
|
"metadata": {
|
||
|
"collapsed": true
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# CODE HERE"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 52,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"Index(['1992-01-01', '1992-02-01', '1992-03-01', '1992-04-01', '1992-05-01',\n",
|
||
|
" '1992-06-01', '1992-07-01', '1992-08-01', '1992-09-01', '1992-10-01',\n",
|
||
|
" ...\n",
|
||
|
" '2018-04-01', '2018-05-01', '2018-06-01', '2018-07-01', '2018-08-01',\n",
|
||
|
" '2018-09-01', '2018-10-01', '2018-11-01', '2018-12-01', '2019-01-01'],\n",
|
||
|
" dtype='object', name='DATE', length=325)"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 52,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"df.index"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"**Convert the index to be a datetime index. Note, there are many, many correct ways to do this!**"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 53,
|
||
|
"metadata": {
|
||
|
"collapsed": true
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# CODE HERE"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 54,
|
||
|
"metadata": {
|
||
|
"collapsed": true
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"df.index = pd.to_datetime(df.index)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 55,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"DatetimeIndex(['1992-01-01', '1992-02-01', '1992-03-01', '1992-04-01',\n",
|
||
|
" '1992-05-01', '1992-06-01', '1992-07-01', '1992-08-01',\n",
|
||
|
" '1992-09-01', '1992-10-01',\n",
|
||
|
" ...\n",
|
||
|
" '2018-04-01', '2018-05-01', '2018-06-01', '2018-07-01',\n",
|
||
|
" '2018-08-01', '2018-09-01', '2018-10-01', '2018-11-01',\n",
|
||
|
" '2018-12-01', '2019-01-01'],\n",
|
||
|
" dtype='datetime64[ns]', name='DATE', length=325, freq=None)"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 55,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"df.index"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"**Plot out the data, choose a reasonable figure size**"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 56,
|
||
|
"metadata": {
|
||
|
"collapsed": true
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# CODE HERE"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 69,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"<matplotlib.axes._subplots.AxesSubplot at 0x1d10ba9bcc0>"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 69,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA1UAAAHjCAYAAADL8zWHAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzsvXmUJHd95XsjIzNyrazK2ruW3tSt\nfWlrBQsMYpEQYGDA8KRnMAb7gG08T8ZmPPbMwTDmccbbHOYxYzPwbAx4kYTn2RY2IBAyAoGQUAta\nUkutpZfqruqqrr0qs3KL9f0R8YuMyDWyKqu6qvt+ztGp6sjIiKjMrNLvxv1+71eyLAuEEEIIIYQQ\nQtZH6HxfACGEEEIIIYTsZCiqCCGEEEIIIWQDUFQRQgghhBBCyAagqCKEEEIIIYSQDUBRRQghhBBC\nCCEbgKKKEEIIIYQQQjYARRUhhBBCCCGEbACKKkIIIYQQQgjZABRVhBBCCCGEELIBwuf7AjpNf3+/\ntXfv3vN9GYQQQgghhJBtylNPPbVgWdZAp453wYmqvXv34vDhw+f7MgghhBBCCCHbFEmSTnfyeCz/\nI4QQQgghhJANQFFFCCGEEEIIIRuAoooQQgghhBBCNsAF11NVD03TMDU1hVKpdL4vZccRi8UwNjaG\nSCRyvi+FEEIIIYSQbclFIaqmpqbQ1dWFvXv3QpKk8305OwbLs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2EoooQQggh\ngSioOnJlHbnS1pTTEBI
|
||
|
"text/plain": [
|
||
|
"<Figure size 1008x576 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"df.plot(figsize=(14,8))"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"**What was the percent increase in value from Jan 2009 to Jan 2019?**"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 71,
|
||
|
"metadata": {
|
||
|
"collapsed": true
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"#CODE HERE"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 76,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"UMTMVS 38.472149\n",
|
||
|
"dtype: float64"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 76,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"100 * (df.loc['2019-01-01'] - df.loc['2009-01-01']) / df.loc['2009-01-01']"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"**What was the percent decrease from Jan 2008 to Jan 2009?**"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {
|
||
|
"collapsed": true
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"#CODE HERE"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 77,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"UMTMVS -22.022775\n",
|
||
|
"dtype: float64"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 77,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"100 * (df.loc['2009-01-01'] - df.loc['2008-01-01']) / df.loc['2008-01-01']"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"**What is the month with the least value after 2005?** [HINT](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.idxmin.html)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 59,
|
||
|
"metadata": {
|
||
|
"collapsed": true
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"#CODE HERE"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 61,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"UMTMVS 2009-01-01\n",
|
||
|
"dtype: datetime64[ns]"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 61,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"df.loc['2005-01-01':].idxmin()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"**What 6 months have the highest value?**"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 68,
|
||
|
"metadata": {
|
||
|
"collapsed": true
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# CODE HERE"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 80,
|
||
|
"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>UMTMVS</th>\n",
|
||
|
" <th>Yearly Mean</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>2018-08-01</th>\n",
|
||
|
" <td>529157.0</td>\n",
|
||
|
" <td>490453.500000</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>2018-10-01</th>\n",
|
||
|
" <td>527031.0</td>\n",
|
||
|
" <td>496482.333333</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>2018-06-01</th>\n",
|
||
|
" <td>525660.0</td>\n",
|
||
|
" <td>483611.000000</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>2018-03-01</th>\n",
|
||
|
" <td>518285.0</td>\n",
|
||
|
" <td>474351.250000</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>2018-09-01</th>\n",
|
||
|
" <td>516992.0</td>\n",
|
||
|
" <td>493075.583333</td>\n",
|
||
|
" </tr>\n",
|
||
|
" </tbody>\n",
|
||
|
"</table>\n",
|
||
|
"</div>"
|
||
|
],
|
||
|
"text/plain": [
|
||
|
" UMTMVS Yearly Mean\n",
|
||
|
"DATE \n",
|
||
|
"2018-08-01 529157.0 490453.500000\n",
|
||
|
"2018-10-01 527031.0 496482.333333\n",
|
||
|
"2018-06-01 525660.0 483611.000000\n",
|
||
|
"2018-03-01 518285.0 474351.250000\n",
|
||
|
"2018-09-01 516992.0 493075.583333"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 80,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"df.sort_values(by='UMTMVS',ascending=False).head(5)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"**How many millions of dollars in value was lost in 2008? (Another way of posing this question is what was the value difference between Jan 2008 and Jan 2009)**"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 17,
|
||
|
"metadata": {
|
||
|
"collapsed": true
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# CODE HERE"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 18,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"UMTMVS 95206.0\n",
|
||
|
"dtype: float64"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 18,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"df.loc['2008-01-01'] - df.loc['2009-01-01']"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"**Create a bar plot showing the average value in millions of dollars per year**"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 19,
|
||
|
"metadata": {
|
||
|
"collapsed": true
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# CODE HERE"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 20,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"<matplotlib.axes._subplots.AxesSubplot at 0x1d10a074588>"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 20,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA4MAAAJDCAYAAACxCMH6AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzs3X24ZWV9H/zvTwbEV0AkYBjIcClG\njIlECfDUpBoMAmLFmGCgjeBLg42aoImNpG0ixphikqf62KopTyVC0zCapAkkoEBR0jxtlDcJqIgQ\ngzK+Ii/G1KAi9/PHXgNnDmdemJm918y6P5/rOtfZ+1777O9e92/NOes3e+21qrUWAAAA+vKwsV8A\nAAAAi6cZBAAA6JBmEAAAoEOaQQAAgA5pBgEAADqkGQQAAOiQZhAAAKBDmkEAAIAOaQYBAAA6pBkE\nAADo0KqxX8D29vjHP76tWbNm7JcBAAAwimuuueZrrbV9Nve4yTWDa9asydVXXz32ywAAABhFVX1u\nSx7nMFEAAIAOaQYBAAA6pBkEAADo0OQ+M7iS73znO1m3bl3uueeesV/KTmf33XfP6tWrs+uuu479\nUgAAgO2oi2Zw3bp1ecxjHpM1a9akqsZ+OTuN1lruuOOOrFu3LgcddNDYLwcAANiOujhM9J577sne\ne++tEXyIqip77723d1QBAGCCumgGk2gEt5J5AwCAaeqmGRzbrbfemqc97WkbjJ155pn53d/93bzs\nZS/LIx/5yHzjG9+4f9npp5+eqspXvvKVHHrooTn00EOz3377Zf/997///re//e1UVV760pfe/3P3\n3ntv9tlnn7zgBS/IrbfemtWrV+e+++7bIPfQQw/NlVdemZtuuinPec5zcuihh+aQQw7JaaedNt9J\nAAAAdhhdfGZwuTVnXLRdn+/Ws47f5ud40pOelAsuuCA/+7M/m/vuuy8f+chHsv/++2eXXXbJdddd\nl2TWPD760Y/OG97whvt/7lGPelQ+8YlP5B//8R/ziEc8Ipdddln233//JMmaNWtywAEH5K/+6q/y\n7Gc/O0ny6U9/Ot/4xjdy+OGH55hjjsnrX//6nHDCCUmSG264YZvXAwAA2Dl4Z3AHcfLJJ+f9739/\nkuSKK67Is571rKxatWW9+nHHHZeLLpo1uOeff35OPvnkDZ537dq1999fu3bt/cu/9KUvZfXq1fcv\n+8Ef/MFtXg8AAGDnoBncQRx88MG5/fbbc9ddd+X888/PSSedtMU/e9JJJ2Xt2rW55557cv311+eI\nI464f9lLXvKS/Nmf/VnuvffeJMn73//++5/79a9/fY466qgcd9xxefvb35677757+64UAACww9IM\nLsjGTsSydPzFL35x1q5dm4997GP5sR/7sS1+7h/6oR/KrbfemvPPPz/Pf/7zN1i233775Qd+4Ady\n+eWX57rrrsuuu+56/2cXX/7yl+fGG2/MiSeemCuuuCJHHnlkvvWtb23F2gEAADsbzeCC7L333rnr\nrrs2GLvzzjvz+Mc//v77J510Un7t134tRx99dB72sIdWmhe+8IV5wxvesMEhouutP1R06SGi633v\n935vXvGKV+SCCy7IqlWr8olPfOIh5QIAADsnzeCCPPrRj84TnvCEXH755UlmjeCHPvSh/OiP/uj9\njznwwAPz1re+Na9+9asf8vO/4hWvyK//+q+v+Lm/n/qpn8rFF1+8wSGiSfKhD30o3/nOd5IkX/7y\nl3PHHXfcf/IZAABg2raoGayqW6vqhqq6rqqu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zbXuMrvcbTqurqqrr69ttvX+khAAAALLEl7ww+K8kLq+rWzA7h\nPCqzdwr3rKr11ylcneS
|
||
|
"text/plain": [
|
||
|
"<Figure size 1080x576 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"df.resample('Y').mean().plot.bar(figsize=(15,8))"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"**What year had the biggest increase in mean value from the previous year's mean value? (Lots of ways to get this answer!)**\n",
|
||
|
"\n",
|
||
|
"[HINT for a useful method](https://pandas.pydata.org/pandas-docs/version/0.21/generated/pandas.DataFrame.idxmax.html)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 21,
|
||
|
"metadata": {
|
||
|
"collapsed": true
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# CODE HERE"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 22,
|
||
|
"metadata": {
|
||
|
"collapsed": true
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"yearly_data = df.resample('Y').mean()\n",
|
||
|
"yearly_data_shift = yearly_data.shift(1)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 23,
|
||
|
"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>UMTMVS</th>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>DATE</th>\n",
|
||
|
" <th></th>\n",
|
||
|
" </tr>\n",
|
||
|
" </thead>\n",
|
||
|
" <tbody>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>1992-12-31</th>\n",
|
||
|
" <td>242002.000000</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>1993-12-31</th>\n",
|
||
|
" <td>251708.083333</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>1994-12-31</th>\n",
|
||
|
" <td>269842.666667</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>1995-12-31</th>\n",
|
||
|
" <td>289973.083333</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>1996-12-31</th>\n",
|
||
|
" <td>299765.666667</td>\n",
|
||
|
" </tr>\n",
|
||
|
" </tbody>\n",
|
||
|
"</table>\n",
|
||
|
"</div>"
|
||
|
],
|
||
|
"text/plain": [
|
||
|
" UMTMVS\n",
|
||
|
"DATE \n",
|
||
|
"1992-12-31 242002.000000\n",
|
||
|
"1993-12-31 251708.083333\n",
|
||
|
"1994-12-31 269842.666667\n",
|
||
|
"1995-12-31 289973.083333\n",
|
||
|
"1996-12-31 299765.666667"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 23,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"yearly_data.head()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 24,
|
||
|
"metadata": {
|
||
|
"collapsed": true
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"change = yearly_data - yearly_data_shift "
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 25,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"Timestamp('2011-12-31 00:00:00', freq='A-DEC')"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 25,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"change['UMTMVS'].idxmax()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"**Plot out the yearly rolling mean on top of the original data. Recall that this is monthly data and there are 12 months in a year!**"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 26,
|
||
|
"metadata": {
|
||
|
"collapsed": true
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# CODE HERE"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 78,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAuUAAAFACAYAAAAbAwI+AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzsnXeYVOXZxn9n+uyU7ZWl915VVOxd\nsUREkVgxEiOJxpLEfPGLxpJgNDFq/NLsFdRoMCo2FAQRFBTpvSwL2+v0er4/TpmZ3dkC7FLf33Vx\n7c6ZM+95z8wue5/73O/zSLIsIxAIB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/KVDqau+0mNb6S3inPdVoAun2xp6njXY4y5t8D\nlWu6dsyikXDB7A53u++++xg3bhwWi4UVK1awdu1a3nnnHZYuXYrJZGLmzJnMmTOH6dOnM3v2bHJy\ncohGo5xxxhlcccUVDBs2DACHw8GXX34JwLx58wA455xzuO2226irqyM3N5fnn3+eG2+8Me08zjnn\nHG666Sbi8Thz587l2Wef5Q9/+AMAH3zwAWVlZSxfvhxZlrnwwgtZunQpJ510Ei+++CI5OTn4/X4m\nTJjAlClTcLlcNDU1cdpppzF79mzuvPNOnnvuOe65556ueGcFAoHgkFNW76fhICzyEhxd+FWn3BNS\nFhgWuG0s2VpLgcvKxL45PAlUe0IMKHDx1fY6tlZ7efSKUcgy/PLfq/ludyPj1LJ8ggMjEE51yoOq\nc17oVkW5zaw45epCT3e
|
||
|
"text/plain": [
|
||
|
"<Figure size 864x360 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"df['Yearly Mean'] = df['UMTMVS'].rolling(window=12).mean()\n",
|
||
|
"df[['UMTMVS','Yearly Mean']].plot(figsize=(12,5)).autoscale(axis='x',tight=True);"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"**BONUS QUESTION (HARD).**\n",
|
||
|
"\n",
|
||
|
"**Some month in 2008 the value peaked for that year. How many months did it take to surpass that 2008 peak? (Since it crashed immediately after this peak) There are many ways to get this answer. NOTE: I get 70 months as my answer, you may get 69 or 68, depending on whether or not you count the start and end months. Refer to the video solutions for full explanation on this.**"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 91,
|
||
|
"metadata": {
|
||
|
"collapsed": true
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"#CODE HERE"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 97,
|
||
|
"metadata": {
|
||
|
"collapsed": true
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"df = pd.read_csv('../Data/UMTMVS.csv',index_col='DATE',parse_dates=True)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 98,
|
||
|
"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>UMTMVS</th>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>DATE</th>\n",
|
||
|
" <th></th>\n",
|
||
|
" </tr>\n",
|
||
|
" </thead>\n",
|
||
|
" <tbody>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>1992-01-01</th>\n",
|
||
|
" <td>209438.0</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>1992-02-01</th>\n",
|
||
|
" <td>232679.0</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>1992-03-01</th>\n",
|
||
|
" <td>249673.0</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>1992-04-01</th>\n",
|
||
|
" <td>239666.0</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>1992-05-01</th>\n",
|
||
|
" <td>243231.0</td>\n",
|
||
|
" </tr>\n",
|
||
|
" </tbody>\n",
|
||
|
"</table>\n",
|
||
|
"</div>"
|
||
|
],
|
||
|
"text/plain": [
|
||
|
" UMTMVS\n",
|
||
|
"DATE \n",
|
||
|
"1992-01-01 209438.0\n",
|
||
|
"1992-02-01 232679.0\n",
|
||
|
"1992-03-01 249673.0\n",
|
||
|
"1992-04-01 239666.0\n",
|
||
|
"1992-05-01 243231.0"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 98,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"df.head()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 99,
|
||
|
"metadata": {
|
||
|
"collapsed": true
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"df2008 = df.loc['2008-01-01':'2009-01-01']"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 100,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"UMTMVS 2008-06-01\n",
|
||
|
"dtype: datetime64[ns]"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 100,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"df2008.idxmax()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 101,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"UMTMVS 510081.0\n",
|
||
|
"dtype: float64"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 101,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"df2008.max()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 105,
|
||
|
"metadata": {
|
||
|
"collapsed": true
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"df_post_peak = df.loc['2008-06-01':]"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 106,
|
||
|
"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>UMTMVS</th>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>DATE</th>\n",
|
||
|
" <th></th>\n",
|
||
|
" </tr>\n",
|
||
|
" </thead>\n",
|
||
|
" <tbody>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>2008-06-01</th>\n",
|
||
|
" <td>510081.0</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>2014-03-01</th>\n",
|
||
|
" <td>513700.0</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>2014-06-01</th>\n",
|
||
|
" <td>516935.0</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>2014-09-01</th>\n",
|
||
|
" <td>512988.0</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>2018-03-01</th>\n",
|
||
|
" <td>518285.0</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>2018-05-01</th>\n",
|
||
|
" <td>515105.0</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>2018-06-01</th>\n",
|
||
|
" <td>525660.0</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>2018-08-01</th>\n",
|
||
|
" <td>529157.0</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>2018-09-01</th>\n",
|
||
|
" <td>516992.0</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>2018-10-01</th>\n",
|
||
|
" <td>527031.0</td>\n",
|
||
|
" </tr>\n",
|
||
|
" </tbody>\n",
|
||
|
"</table>\n",
|
||
|
"</div>"
|
||
|
],
|
||
|
"text/plain": [
|
||
|
" UMTMVS\n",
|
||
|
"DATE \n",
|
||
|
"2008-06-01 510081.0\n",
|
||
|
"2014-03-01 513700.0\n",
|
||
|
"2014-06-01 516935.0\n",
|
||
|
"2014-09-01 512988.0\n",
|
||
|
"2018-03-01 518285.0\n",
|
||
|
"2018-05-01 515105.0\n",
|
||
|
"2018-06-01 525660.0\n",
|
||
|
"2018-08-01 529157.0\n",
|
||
|
"2018-09-01 516992.0\n",
|
||
|
"2018-10-01 527031.0"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 106,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"df_post_peak[df_post_peak>=510081].dropna()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 108,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"70"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 108,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"len(df.loc['2008-06-01':'2014-03-01'])"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"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": 2
|
||
|
}
|