860 lines
55 KiB
Plaintext
860 lines
55 KiB
Plaintext
|
|
{
|
||
|
|
"cells": [
|
||
|
|
{
|
||
|
|
"cell_type": "markdown",
|
||
|
|
"metadata": {},
|
||
|
|
"source": [
|
||
|
|
"___\n",
|
||
|
|
"\n",
|
||
|
|
"<a href='http://www.pieriandata.com'> <img src='../Pierian_Data_Logo.png' /></a>\n",
|
||
|
|
"___\n",
|
||
|
|
"<center>*Copyright Pierian Data 2017*</center>\n",
|
||
|
|
"<center>*For more information, visit us at www.pieriandata.com*</center>"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "markdown",
|
||
|
|
"metadata": {},
|
||
|
|
"source": [
|
||
|
|
"# Time Resampling\n",
|
||
|
|
"\n",
|
||
|
|
"Let's learn how to sample time series data! This will be useful later on in the course!"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": 30,
|
||
|
|
"metadata": {
|
||
|
|
"collapsed": true
|
||
|
|
},
|
||
|
|
"outputs": [],
|
||
|
|
"source": [
|
||
|
|
"import numpy as np\n",
|
||
|
|
"import pandas as pd"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": 31,
|
||
|
|
"metadata": {
|
||
|
|
"collapsed": true
|
||
|
|
},
|
||
|
|
"outputs": [],
|
||
|
|
"source": [
|
||
|
|
"%matplotlib inline\n",
|
||
|
|
"import matplotlib.pyplot as plt"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": 2,
|
||
|
|
"metadata": {
|
||
|
|
"collapsed": true
|
||
|
|
},
|
||
|
|
"outputs": [],
|
||
|
|
"source": [
|
||
|
|
"# Grab data\n",
|
||
|
|
"# Faster alternative\n",
|
||
|
|
"# df = pd.read_csv('time_data/walmart_stock.csv',index_col='Date')\n",
|
||
|
|
"df = pd.read_csv('time_data/walmart_stock.csv')"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": 3,
|
||
|
|
"metadata": {
|
||
|
|
"collapsed": false
|
||
|
|
},
|
||
|
|
"outputs": [
|
||
|
|
{
|
||
|
|
"data": {
|
||
|
|
"text/html": [
|
||
|
|
"<div>\n",
|
||
|
|
"<table border=\"1\" class=\"dataframe\">\n",
|
||
|
|
" <thead>\n",
|
||
|
|
" <tr style=\"text-align: right;\">\n",
|
||
|
|
" <th></th>\n",
|
||
|
|
" <th>Date</th>\n",
|
||
|
|
" <th>Open</th>\n",
|
||
|
|
" <th>High</th>\n",
|
||
|
|
" <th>Low</th>\n",
|
||
|
|
" <th>Close</th>\n",
|
||
|
|
" <th>Volume</th>\n",
|
||
|
|
" <th>Adj Close</th>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" </thead>\n",
|
||
|
|
" <tbody>\n",
|
||
|
|
" <tr>\n",
|
||
|
|
" <th>0</th>\n",
|
||
|
|
" <td>2012-01-03</td>\n",
|
||
|
|
" <td>59.970001</td>\n",
|
||
|
|
" <td>61.060001</td>\n",
|
||
|
|
" <td>59.869999</td>\n",
|
||
|
|
" <td>60.330002</td>\n",
|
||
|
|
" <td>12668800</td>\n",
|
||
|
|
" <td>52.619235</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" <tr>\n",
|
||
|
|
" <th>1</th>\n",
|
||
|
|
" <td>2012-01-04</td>\n",
|
||
|
|
" <td>60.209999</td>\n",
|
||
|
|
" <td>60.349998</td>\n",
|
||
|
|
" <td>59.470001</td>\n",
|
||
|
|
" <td>59.709999</td>\n",
|
||
|
|
" <td>9593300</td>\n",
|
||
|
|
" <td>52.078475</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" <tr>\n",
|
||
|
|
" <th>2</th>\n",
|
||
|
|
" <td>2012-01-05</td>\n",
|
||
|
|
" <td>59.349998</td>\n",
|
||
|
|
" <td>59.619999</td>\n",
|
||
|
|
" <td>58.369999</td>\n",
|
||
|
|
" <td>59.419998</td>\n",
|
||
|
|
" <td>12768200</td>\n",
|
||
|
|
" <td>51.825539</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" <tr>\n",
|
||
|
|
" <th>3</th>\n",
|
||
|
|
" <td>2012-01-06</td>\n",
|
||
|
|
" <td>59.419998</td>\n",
|
||
|
|
" <td>59.450001</td>\n",
|
||
|
|
" <td>58.869999</td>\n",
|
||
|
|
" <td>59.000000</td>\n",
|
||
|
|
" <td>8069400</td>\n",
|
||
|
|
" <td>51.459220</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" <tr>\n",
|
||
|
|
" <th>4</th>\n",
|
||
|
|
" <td>2012-01-09</td>\n",
|
||
|
|
" <td>59.029999</td>\n",
|
||
|
|
" <td>59.549999</td>\n",
|
||
|
|
" <td>58.919998</td>\n",
|
||
|
|
" <td>59.180000</td>\n",
|
||
|
|
" <td>6679300</td>\n",
|
||
|
|
" <td>51.616215</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" </tbody>\n",
|
||
|
|
"</table>\n",
|
||
|
|
"</div>"
|
||
|
|
],
|
||
|
|
"text/plain": [
|
||
|
|
" Date Open High Low Close Volume Adj Close\n",
|
||
|
|
"0 2012-01-03 59.970001 61.060001 59.869999 60.330002 12668800 52.619235\n",
|
||
|
|
"1 2012-01-04 60.209999 60.349998 59.470001 59.709999 9593300 52.078475\n",
|
||
|
|
"2 2012-01-05 59.349998 59.619999 58.369999 59.419998 12768200 51.825539\n",
|
||
|
|
"3 2012-01-06 59.419998 59.450001 58.869999 59.000000 8069400 51.459220\n",
|
||
|
|
"4 2012-01-09 59.029999 59.549999 58.919998 59.180000 6679300 51.616215"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
"execution_count": 3,
|
||
|
|
"metadata": {},
|
||
|
|
"output_type": "execute_result"
|
||
|
|
}
|
||
|
|
],
|
||
|
|
"source": [
|
||
|
|
"df.head()"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "markdown",
|
||
|
|
"metadata": {},
|
||
|
|
"source": [
|
||
|
|
"Create a date index from the date column"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": 4,
|
||
|
|
"metadata": {
|
||
|
|
"collapsed": true
|
||
|
|
},
|
||
|
|
"outputs": [],
|
||
|
|
"source": [
|
||
|
|
"df['Date'] = df['Date'].apply(pd.to_datetime)"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": 5,
|
||
|
|
"metadata": {
|
||
|
|
"collapsed": false
|
||
|
|
},
|
||
|
|
"outputs": [
|
||
|
|
{
|
||
|
|
"data": {
|
||
|
|
"text/html": [
|
||
|
|
"<div>\n",
|
||
|
|
"<table border=\"1\" class=\"dataframe\">\n",
|
||
|
|
" <thead>\n",
|
||
|
|
" <tr style=\"text-align: right;\">\n",
|
||
|
|
" <th></th>\n",
|
||
|
|
" <th>Date</th>\n",
|
||
|
|
" <th>Open</th>\n",
|
||
|
|
" <th>High</th>\n",
|
||
|
|
" <th>Low</th>\n",
|
||
|
|
" <th>Close</th>\n",
|
||
|
|
" <th>Volume</th>\n",
|
||
|
|
" <th>Adj Close</th>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" </thead>\n",
|
||
|
|
" <tbody>\n",
|
||
|
|
" <tr>\n",
|
||
|
|
" <th>0</th>\n",
|
||
|
|
" <td>2012-01-03</td>\n",
|
||
|
|
" <td>59.970001</td>\n",
|
||
|
|
" <td>61.060001</td>\n",
|
||
|
|
" <td>59.869999</td>\n",
|
||
|
|
" <td>60.330002</td>\n",
|
||
|
|
" <td>12668800</td>\n",
|
||
|
|
" <td>52.619235</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" <tr>\n",
|
||
|
|
" <th>1</th>\n",
|
||
|
|
" <td>2012-01-04</td>\n",
|
||
|
|
" <td>60.209999</td>\n",
|
||
|
|
" <td>60.349998</td>\n",
|
||
|
|
" <td>59.470001</td>\n",
|
||
|
|
" <td>59.709999</td>\n",
|
||
|
|
" <td>9593300</td>\n",
|
||
|
|
" <td>52.078475</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" <tr>\n",
|
||
|
|
" <th>2</th>\n",
|
||
|
|
" <td>2012-01-05</td>\n",
|
||
|
|
" <td>59.349998</td>\n",
|
||
|
|
" <td>59.619999</td>\n",
|
||
|
|
" <td>58.369999</td>\n",
|
||
|
|
" <td>59.419998</td>\n",
|
||
|
|
" <td>12768200</td>\n",
|
||
|
|
" <td>51.825539</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" <tr>\n",
|
||
|
|
" <th>3</th>\n",
|
||
|
|
" <td>2012-01-06</td>\n",
|
||
|
|
" <td>59.419998</td>\n",
|
||
|
|
" <td>59.450001</td>\n",
|
||
|
|
" <td>58.869999</td>\n",
|
||
|
|
" <td>59.000000</td>\n",
|
||
|
|
" <td>8069400</td>\n",
|
||
|
|
" <td>51.459220</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" <tr>\n",
|
||
|
|
" <th>4</th>\n",
|
||
|
|
" <td>2012-01-09</td>\n",
|
||
|
|
" <td>59.029999</td>\n",
|
||
|
|
" <td>59.549999</td>\n",
|
||
|
|
" <td>58.919998</td>\n",
|
||
|
|
" <td>59.180000</td>\n",
|
||
|
|
" <td>6679300</td>\n",
|
||
|
|
" <td>51.616215</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" </tbody>\n",
|
||
|
|
"</table>\n",
|
||
|
|
"</div>"
|
||
|
|
],
|
||
|
|
"text/plain": [
|
||
|
|
" Date Open High Low Close Volume Adj Close\n",
|
||
|
|
"0 2012-01-03 59.970001 61.060001 59.869999 60.330002 12668800 52.619235\n",
|
||
|
|
"1 2012-01-04 60.209999 60.349998 59.470001 59.709999 9593300 52.078475\n",
|
||
|
|
"2 2012-01-05 59.349998 59.619999 58.369999 59.419998 12768200 51.825539\n",
|
||
|
|
"3 2012-01-06 59.419998 59.450001 58.869999 59.000000 8069400 51.459220\n",
|
||
|
|
"4 2012-01-09 59.029999 59.549999 58.919998 59.180000 6679300 51.616215"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
"execution_count": 5,
|
||
|
|
"metadata": {},
|
||
|
|
"output_type": "execute_result"
|
||
|
|
}
|
||
|
|
],
|
||
|
|
"source": [
|
||
|
|
"df.head()"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": 6,
|
||
|
|
"metadata": {
|
||
|
|
"collapsed": true
|
||
|
|
},
|
||
|
|
"outputs": [],
|
||
|
|
"source": [
|
||
|
|
"df.set_index('Date',inplace=True)"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": 8,
|
||
|
|
"metadata": {
|
||
|
|
"collapsed": false
|
||
|
|
},
|
||
|
|
"outputs": [
|
||
|
|
{
|
||
|
|
"data": {
|
||
|
|
"text/html": [
|
||
|
|
"<div>\n",
|
||
|
|
"<table border=\"1\" class=\"dataframe\">\n",
|
||
|
|
" <thead>\n",
|
||
|
|
" <tr style=\"text-align: right;\">\n",
|
||
|
|
" <th></th>\n",
|
||
|
|
" <th>Open</th>\n",
|
||
|
|
" <th>High</th>\n",
|
||
|
|
" <th>Low</th>\n",
|
||
|
|
" <th>Close</th>\n",
|
||
|
|
" <th>Volume</th>\n",
|
||
|
|
" <th>Adj Close</th>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" <tr>\n",
|
||
|
|
" <th>Date</th>\n",
|
||
|
|
" <th></th>\n",
|
||
|
|
" <th></th>\n",
|
||
|
|
" <th></th>\n",
|
||
|
|
" <th></th>\n",
|
||
|
|
" <th></th>\n",
|
||
|
|
" <th></th>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" </thead>\n",
|
||
|
|
" <tbody>\n",
|
||
|
|
" <tr>\n",
|
||
|
|
" <th>2012-01-03</th>\n",
|
||
|
|
" <td>59.970001</td>\n",
|
||
|
|
" <td>61.060001</td>\n",
|
||
|
|
" <td>59.869999</td>\n",
|
||
|
|
" <td>60.330002</td>\n",
|
||
|
|
" <td>12668800</td>\n",
|
||
|
|
" <td>52.619235</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" <tr>\n",
|
||
|
|
" <th>2012-01-04</th>\n",
|
||
|
|
" <td>60.209999</td>\n",
|
||
|
|
" <td>60.349998</td>\n",
|
||
|
|
" <td>59.470001</td>\n",
|
||
|
|
" <td>59.709999</td>\n",
|
||
|
|
" <td>9593300</td>\n",
|
||
|
|
" <td>52.078475</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" <tr>\n",
|
||
|
|
" <th>2012-01-05</th>\n",
|
||
|
|
" <td>59.349998</td>\n",
|
||
|
|
" <td>59.619999</td>\n",
|
||
|
|
" <td>58.369999</td>\n",
|
||
|
|
" <td>59.419998</td>\n",
|
||
|
|
" <td>12768200</td>\n",
|
||
|
|
" <td>51.825539</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" <tr>\n",
|
||
|
|
" <th>2012-01-06</th>\n",
|
||
|
|
" <td>59.419998</td>\n",
|
||
|
|
" <td>59.450001</td>\n",
|
||
|
|
" <td>58.869999</td>\n",
|
||
|
|
" <td>59.000000</td>\n",
|
||
|
|
" <td>8069400</td>\n",
|
||
|
|
" <td>51.459220</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" <tr>\n",
|
||
|
|
" <th>2012-01-09</th>\n",
|
||
|
|
" <td>59.029999</td>\n",
|
||
|
|
" <td>59.549999</td>\n",
|
||
|
|
" <td>58.919998</td>\n",
|
||
|
|
" <td>59.180000</td>\n",
|
||
|
|
" <td>6679300</td>\n",
|
||
|
|
" <td>51.616215</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" </tbody>\n",
|
||
|
|
"</table>\n",
|
||
|
|
"</div>"
|
||
|
|
],
|
||
|
|
"text/plain": [
|
||
|
|
" Open High Low Close Volume Adj Close\n",
|
||
|
|
"Date \n",
|
||
|
|
"2012-01-03 59.970001 61.060001 59.869999 60.330002 12668800 52.619235\n",
|
||
|
|
"2012-01-04 60.209999 60.349998 59.470001 59.709999 9593300 52.078475\n",
|
||
|
|
"2012-01-05 59.349998 59.619999 58.369999 59.419998 12768200 51.825539\n",
|
||
|
|
"2012-01-06 59.419998 59.450001 58.869999 59.000000 8069400 51.459220\n",
|
||
|
|
"2012-01-09 59.029999 59.549999 58.919998 59.180000 6679300 51.616215"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
"execution_count": 8,
|
||
|
|
"metadata": {},
|
||
|
|
"output_type": "execute_result"
|
||
|
|
}
|
||
|
|
],
|
||
|
|
"source": [
|
||
|
|
"df.head()"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "markdown",
|
||
|
|
"metadata": {},
|
||
|
|
"source": [
|
||
|
|
"## resample()\n",
|
||
|
|
"\n",
|
||
|
|
"A common operation with time series data is resamplling based on the time series index. Let see how to use the resample() method.\n",
|
||
|
|
"\n",
|
||
|
|
"#### All possible time series offest strings"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "markdown",
|
||
|
|
"metadata": {},
|
||
|
|
"source": [
|
||
|
|
"<table border=\"1\" class=\"docutils\">\n",
|
||
|
|
"<colgroup>\n",
|
||
|
|
"<col width=\"13%\" />\n",
|
||
|
|
"<col width=\"87%\" />\n",
|
||
|
|
"</colgroup>\n",
|
||
|
|
"<thead valign=\"bottom\">\n",
|
||
|
|
"<tr class=\"row-odd\"><th class=\"head\">Alias</th>\n",
|
||
|
|
"<th class=\"head\">Description</th>\n",
|
||
|
|
"</tr>\n",
|
||
|
|
"</thead>\n",
|
||
|
|
"<tbody valign=\"top\">\n",
|
||
|
|
"<tr class=\"row-even\"><td>B</td>\n",
|
||
|
|
"<td>business day frequency</td>\n",
|
||
|
|
"</tr>\n",
|
||
|
|
"<tr class=\"row-odd\"><td>C</td>\n",
|
||
|
|
"<td>custom business day frequency (experimental)</td>\n",
|
||
|
|
"</tr>\n",
|
||
|
|
"<tr class=\"row-even\"><td>D</td>\n",
|
||
|
|
"<td>calendar day frequency</td>\n",
|
||
|
|
"</tr>\n",
|
||
|
|
"<tr class=\"row-odd\"><td>W</td>\n",
|
||
|
|
"<td>weekly frequency</td>\n",
|
||
|
|
"</tr>\n",
|
||
|
|
"<tr class=\"row-even\"><td>M</td>\n",
|
||
|
|
"<td>month end frequency</td>\n",
|
||
|
|
"</tr>\n",
|
||
|
|
"<tr class=\"row-odd\"><td>SM</td>\n",
|
||
|
|
"<td>semi-month end frequency (15th and end of month)</td>\n",
|
||
|
|
"</tr>\n",
|
||
|
|
"<tr class=\"row-even\"><td>BM</td>\n",
|
||
|
|
"<td>business month end frequency</td>\n",
|
||
|
|
"</tr>\n",
|
||
|
|
"<tr class=\"row-odd\"><td>CBM</td>\n",
|
||
|
|
"<td>custom business month end frequency</td>\n",
|
||
|
|
"</tr>\n",
|
||
|
|
"<tr class=\"row-even\"><td>MS</td>\n",
|
||
|
|
"<td>month start frequency</td>\n",
|
||
|
|
"</tr>\n",
|
||
|
|
"<tr class=\"row-odd\"><td>SMS</td>\n",
|
||
|
|
"<td>semi-month start frequency (1st and 15th)</td>\n",
|
||
|
|
"</tr>\n",
|
||
|
|
"<tr class=\"row-even\"><td>BMS</td>\n",
|
||
|
|
"<td>business month start frequency</td>\n",
|
||
|
|
"</tr>\n",
|
||
|
|
"<tr class=\"row-odd\"><td>CBMS</td>\n",
|
||
|
|
"<td>custom business month start frequency</td>\n",
|
||
|
|
"</tr>\n",
|
||
|
|
"<tr class=\"row-even\"><td>Q</td>\n",
|
||
|
|
"<td>quarter end frequency</td>\n",
|
||
|
|
"</tr>\n",
|
||
|
|
"<tr class=\"row-odd\"><td>BQ</td>\n",
|
||
|
|
"<td>business quarter endfrequency</td>\n",
|
||
|
|
"</tr>\n",
|
||
|
|
"<tr class=\"row-even\"><td>QS</td>\n",
|
||
|
|
"<td>quarter start frequency</td>\n",
|
||
|
|
"</tr>\n",
|
||
|
|
"<tr class=\"row-odd\"><td>BQS</td>\n",
|
||
|
|
"<td>business quarter start frequency</td>\n",
|
||
|
|
"</tr>\n",
|
||
|
|
"<tr class=\"row-even\"><td>A</td>\n",
|
||
|
|
"<td>year end frequency</td>\n",
|
||
|
|
"</tr>\n",
|
||
|
|
"<tr class=\"row-odd\"><td>BA</td>\n",
|
||
|
|
"<td>business year end frequency</td>\n",
|
||
|
|
"</tr>\n",
|
||
|
|
"<tr class=\"row-even\"><td>AS</td>\n",
|
||
|
|
"<td>year start frequency</td>\n",
|
||
|
|
"</tr>\n",
|
||
|
|
"<tr class=\"row-odd\"><td>BAS</td>\n",
|
||
|
|
"<td>business year start frequency</td>\n",
|
||
|
|
"</tr>\n",
|
||
|
|
"<tr class=\"row-even\"><td>BH</td>\n",
|
||
|
|
"<td>business hour frequency</td>\n",
|
||
|
|
"</tr>\n",
|
||
|
|
"<tr class=\"row-odd\"><td>H</td>\n",
|
||
|
|
"<td>hourly frequency</td>\n",
|
||
|
|
"</tr>\n",
|
||
|
|
"<tr class=\"row-even\"><td>T, min</td>\n",
|
||
|
|
"<td>minutely frequency</td>\n",
|
||
|
|
"</tr>\n",
|
||
|
|
"<tr class=\"row-odd\"><td>S</td>\n",
|
||
|
|
"<td>secondly frequency</td>\n",
|
||
|
|
"</tr>\n",
|
||
|
|
"<tr class=\"row-even\"><td>L, ms</td>\n",
|
||
|
|
"<td>milliseconds</td>\n",
|
||
|
|
"</tr>\n",
|
||
|
|
"<tr class=\"row-odd\"><td>U, us</td>\n",
|
||
|
|
"<td>microseconds</td>\n",
|
||
|
|
"</tr>\n",
|
||
|
|
"<tr class=\"row-even\"><td>N</td>\n",
|
||
|
|
"<td>nanoseconds</td>\n",
|
||
|
|
"</tr>\n",
|
||
|
|
"</tbody>\n",
|
||
|
|
"</table>"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": 14,
|
||
|
|
"metadata": {
|
||
|
|
"collapsed": false
|
||
|
|
},
|
||
|
|
"outputs": [
|
||
|
|
{
|
||
|
|
"data": {
|
||
|
|
"text/plain": [
|
||
|
|
"DatetimeIndex(['2012-01-03', '2012-01-04', '2012-01-05', '2012-01-06',\n",
|
||
|
|
" '2012-01-09', '2012-01-10', '2012-01-11', '2012-01-12',\n",
|
||
|
|
" '2012-01-13', '2012-01-17',\n",
|
||
|
|
" ...\n",
|
||
|
|
" '2016-12-16', '2016-12-19', '2016-12-20', '2016-12-21',\n",
|
||
|
|
" '2016-12-22', '2016-12-23', '2016-12-27', '2016-12-28',\n",
|
||
|
|
" '2016-12-29', '2016-12-30'],\n",
|
||
|
|
" dtype='datetime64[ns]', name='Date', length=1258, freq=None)"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
"execution_count": 14,
|
||
|
|
"metadata": {},
|
||
|
|
"output_type": "execute_result"
|
||
|
|
}
|
||
|
|
],
|
||
|
|
"source": [
|
||
|
|
"# Our index\n",
|
||
|
|
"df.index"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "markdown",
|
||
|
|
"metadata": {},
|
||
|
|
"source": [
|
||
|
|
"You need to call resample with the rule parameter, then you need to call some sort of aggregation function. This is because due to resampling, we need some sort of mathematical rule to join the rows by (mean,sum,count,etc...)"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": 17,
|
||
|
|
"metadata": {
|
||
|
|
"collapsed": false
|
||
|
|
},
|
||
|
|
"outputs": [
|
||
|
|
{
|
||
|
|
"data": {
|
||
|
|
"text/html": [
|
||
|
|
"<div>\n",
|
||
|
|
"<table border=\"1\" class=\"dataframe\">\n",
|
||
|
|
" <thead>\n",
|
||
|
|
" <tr style=\"text-align: right;\">\n",
|
||
|
|
" <th></th>\n",
|
||
|
|
" <th>Open</th>\n",
|
||
|
|
" <th>High</th>\n",
|
||
|
|
" <th>Low</th>\n",
|
||
|
|
" <th>Close</th>\n",
|
||
|
|
" <th>Volume</th>\n",
|
||
|
|
" <th>Adj Close</th>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" <tr>\n",
|
||
|
|
" <th>Date</th>\n",
|
||
|
|
" <th></th>\n",
|
||
|
|
" <th></th>\n",
|
||
|
|
" <th></th>\n",
|
||
|
|
" <th></th>\n",
|
||
|
|
" <th></th>\n",
|
||
|
|
" <th></th>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" </thead>\n",
|
||
|
|
" <tbody>\n",
|
||
|
|
" <tr>\n",
|
||
|
|
" <th>2012-12-31</th>\n",
|
||
|
|
" <td>67.158680</td>\n",
|
||
|
|
" <td>67.602120</td>\n",
|
||
|
|
" <td>66.786520</td>\n",
|
||
|
|
" <td>67.215120</td>\n",
|
||
|
|
" <td>9239015</td>\n",
|
||
|
|
" <td>59.389349</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" <tr>\n",
|
||
|
|
" <th>2013-12-31</th>\n",
|
||
|
|
" <td>75.264048</td>\n",
|
||
|
|
" <td>75.729405</td>\n",
|
||
|
|
" <td>74.843055</td>\n",
|
||
|
|
" <td>75.320516</td>\n",
|
||
|
|
" <td>6951496</td>\n",
|
||
|
|
" <td>68.147179</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" <tr>\n",
|
||
|
|
" <th>2014-12-31</th>\n",
|
||
|
|
" <td>77.274524</td>\n",
|
||
|
|
" <td>77.740040</td>\n",
|
||
|
|
" <td>76.864405</td>\n",
|
||
|
|
" <td>77.327381</td>\n",
|
||
|
|
" <td>6515612</td>\n",
|
||
|
|
" <td>71.709712</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" <tr>\n",
|
||
|
|
" <th>2015-12-31</th>\n",
|
||
|
|
" <td>72.569405</td>\n",
|
||
|
|
" <td>73.064167</td>\n",
|
||
|
|
" <td>72.034802</td>\n",
|
||
|
|
" <td>72.491111</td>\n",
|
||
|
|
" <td>9040769</td>\n",
|
||
|
|
" <td>68.831426</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" <tr>\n",
|
||
|
|
" <th>2016-12-31</th>\n",
|
||
|
|
" <td>69.481349</td>\n",
|
||
|
|
" <td>70.019643</td>\n",
|
||
|
|
" <td>69.023492</td>\n",
|
||
|
|
" <td>69.547063</td>\n",
|
||
|
|
" <td>9371645</td>\n",
|
||
|
|
" <td>68.054229</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" </tbody>\n",
|
||
|
|
"</table>\n",
|
||
|
|
"</div>"
|
||
|
|
],
|
||
|
|
"text/plain": [
|
||
|
|
" Open High Low Close Volume Adj Close\n",
|
||
|
|
"Date \n",
|
||
|
|
"2012-12-31 67.158680 67.602120 66.786520 67.215120 9239015 59.389349\n",
|
||
|
|
"2013-12-31 75.264048 75.729405 74.843055 75.320516 6951496 68.147179\n",
|
||
|
|
"2014-12-31 77.274524 77.740040 76.864405 77.327381 6515612 71.709712\n",
|
||
|
|
"2015-12-31 72.569405 73.064167 72.034802 72.491111 9040769 68.831426\n",
|
||
|
|
"2016-12-31 69.481349 70.019643 69.023492 69.547063 9371645 68.054229"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
"execution_count": 17,
|
||
|
|
"metadata": {},
|
||
|
|
"output_type": "execute_result"
|
||
|
|
}
|
||
|
|
],
|
||
|
|
"source": [
|
||
|
|
"# Yearly Means\n",
|
||
|
|
"df.resample(rule='A').mean()"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "markdown",
|
||
|
|
"metadata": {
|
||
|
|
"collapsed": false
|
||
|
|
},
|
||
|
|
"source": [
|
||
|
|
"### Custom Resampling\n",
|
||
|
|
"\n",
|
||
|
|
"You could technically also create your own custom resampling function:"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": 23,
|
||
|
|
"metadata": {
|
||
|
|
"collapsed": true
|
||
|
|
},
|
||
|
|
"outputs": [],
|
||
|
|
"source": [
|
||
|
|
"def first_day(entry):\n",
|
||
|
|
" \"\"\"\n",
|
||
|
|
" Returns the first instance of the period, regardless of samplling rate.\n",
|
||
|
|
" \"\"\"\n",
|
||
|
|
" return entry[0]"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": 25,
|
||
|
|
"metadata": {
|
||
|
|
"collapsed": false
|
||
|
|
},
|
||
|
|
"outputs": [
|
||
|
|
{
|
||
|
|
"data": {
|
||
|
|
"text/html": [
|
||
|
|
"<div>\n",
|
||
|
|
"<table border=\"1\" class=\"dataframe\">\n",
|
||
|
|
" <thead>\n",
|
||
|
|
" <tr style=\"text-align: right;\">\n",
|
||
|
|
" <th></th>\n",
|
||
|
|
" <th>Open</th>\n",
|
||
|
|
" <th>High</th>\n",
|
||
|
|
" <th>Low</th>\n",
|
||
|
|
" <th>Close</th>\n",
|
||
|
|
" <th>Volume</th>\n",
|
||
|
|
" <th>Adj Close</th>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" <tr>\n",
|
||
|
|
" <th>Date</th>\n",
|
||
|
|
" <th></th>\n",
|
||
|
|
" <th></th>\n",
|
||
|
|
" <th></th>\n",
|
||
|
|
" <th></th>\n",
|
||
|
|
" <th></th>\n",
|
||
|
|
" <th></th>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" </thead>\n",
|
||
|
|
" <tbody>\n",
|
||
|
|
" <tr>\n",
|
||
|
|
" <th>2012-12-31</th>\n",
|
||
|
|
" <td>59.970001</td>\n",
|
||
|
|
" <td>61.060001</td>\n",
|
||
|
|
" <td>59.869999</td>\n",
|
||
|
|
" <td>60.330002</td>\n",
|
||
|
|
" <td>12668800</td>\n",
|
||
|
|
" <td>52.619235</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" <tr>\n",
|
||
|
|
" <th>2013-12-31</th>\n",
|
||
|
|
" <td>68.930000</td>\n",
|
||
|
|
" <td>69.239998</td>\n",
|
||
|
|
" <td>68.449997</td>\n",
|
||
|
|
" <td>69.239998</td>\n",
|
||
|
|
" <td>10390800</td>\n",
|
||
|
|
" <td>61.879708</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" <tr>\n",
|
||
|
|
" <th>2014-12-31</th>\n",
|
||
|
|
" <td>78.720001</td>\n",
|
||
|
|
" <td>79.470001</td>\n",
|
||
|
|
" <td>78.500000</td>\n",
|
||
|
|
" <td>78.910004</td>\n",
|
||
|
|
" <td>6878000</td>\n",
|
||
|
|
" <td>72.254228</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" <tr>\n",
|
||
|
|
" <th>2015-12-31</th>\n",
|
||
|
|
" <td>86.269997</td>\n",
|
||
|
|
" <td>86.720001</td>\n",
|
||
|
|
" <td>85.550003</td>\n",
|
||
|
|
" <td>85.900002</td>\n",
|
||
|
|
" <td>4501800</td>\n",
|
||
|
|
" <td>80.624861</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" <tr>\n",
|
||
|
|
" <th>2016-12-31</th>\n",
|
||
|
|
" <td>60.500000</td>\n",
|
||
|
|
" <td>61.490002</td>\n",
|
||
|
|
" <td>60.360001</td>\n",
|
||
|
|
" <td>61.459999</td>\n",
|
||
|
|
" <td>11989200</td>\n",
|
||
|
|
" <td>59.289713</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" </tbody>\n",
|
||
|
|
"</table>\n",
|
||
|
|
"</div>"
|
||
|
|
],
|
||
|
|
"text/plain": [
|
||
|
|
" Open High Low Close Volume Adj Close\n",
|
||
|
|
"Date \n",
|
||
|
|
"2012-12-31 59.970001 61.060001 59.869999 60.330002 12668800 52.619235\n",
|
||
|
|
"2013-12-31 68.930000 69.239998 68.449997 69.239998 10390800 61.879708\n",
|
||
|
|
"2014-12-31 78.720001 79.470001 78.500000 78.910004 6878000 72.254228\n",
|
||
|
|
"2015-12-31 86.269997 86.720001 85.550003 85.900002 4501800 80.624861\n",
|
||
|
|
"2016-12-31 60.500000 61.490002 60.360001 61.459999 11989200 59.289713"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
"execution_count": 25,
|
||
|
|
"metadata": {},
|
||
|
|
"output_type": "execute_result"
|
||
|
|
}
|
||
|
|
],
|
||
|
|
"source": [
|
||
|
|
"df.resample(rule='A').apply(first_day)"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": 38,
|
||
|
|
"metadata": {
|
||
|
|
"collapsed": false
|
||
|
|
},
|
||
|
|
"outputs": [
|
||
|
|
{
|
||
|
|
"data": {
|
||
|
|
"text/plain": [
|
||
|
|
"<matplotlib.text.Text at 0x11d782080>"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
"execution_count": 38,
|
||
|
|
"metadata": {},
|
||
|
|
"output_type": "execute_result"
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"data": {
|
||
|
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAF2CAYAAAB+q2NYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XmYpGV97vHvzcywCAgMNO0oy6iMIKhs7RZF0QEDARlM\nFHfGBJxzjHCIIVHkuB+PkmMOlwsumbiN4sKIGiaaYGAiIC5os6+TAWTYZmkGhh0R/OWP92mesqju\nqu6u7rf7qftzXX11vUtV/eru7l8/9bxVbykiMDOzmW+zugswM7PucEM3MyuEG7qZWSHc0M3MCuGG\nbmZWCDd0M7NCuKHPcJLOlPSRuuuYCpIOkXRL3XWMRtIqSQd1+TbnSbpY0v2S/qGbtz1RkmZLCknz\n667F3NC7LjXYrzWte6WkjZLm1VVXs9QcQ9L3mtYfmNafX1NdL5F0rqR7Jd0t6RJJx9ZUy3CzelDS\nA5Jul/QpSSP+3UTEnhHxsy6X8j+BO4GnRsT7JnJD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H9ddArec\ndkTdJViP8wjdzKwQbuhmZoVwQzczK4QbuplZIXxQdAbzgUAza+QRuplZIdzQzcwK4YZuZlYIN3Qz\ns0K4oZuZFcIN3cysEG7oZmaF8OvQzQrj9yf0Lo/QzcwK4YZuZlaItg1d0p6Srmj4uk/S30iaK+k8\nSavT9x2momAzM2utbUOPiFURsV9E7AccCDwE/BA4BVgZEQuAlWnZzMxqMtYpl4XATRGxBlgELEvr\nlwFHd7MwMzMbm7E29DcB30mX+yNibbq8DuhvdQVJSyQNShocGhoaZ5lmZtZOxy9blLQ5cBTw/uZt\nERGSotX1ImIpsBRgYGC
|
||
|
|
"text/plain": [
|
||
|
|
"<matplotlib.figure.Figure at 0x11ce18588>"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
"metadata": {},
|
||
|
|
"output_type": "display_data"
|
||
|
|
}
|
||
|
|
],
|
||
|
|
"source": [
|
||
|
|
"df['Close'].resample('A').mean().plot(kind='bar')\n",
|
||
|
|
"plt.title('Yearly Mean Close Price for Walmart')"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": 42,
|
||
|
|
"metadata": {
|
||
|
|
"collapsed": false
|
||
|
|
},
|
||
|
|
"outputs": [
|
||
|
|
{
|
||
|
|
"data": {
|
||
|
|
"text/plain": [
|
||
|
|
"<matplotlib.text.Text at 0x11e8ddda0>"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
"execution_count": 42,
|
||
|
|
"metadata": {},
|
||
|
|
"output_type": "execute_result"
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"data": {
|
||
|
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA6IAAAHjCAYAAAA5Y6JnAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XmYdGdZJ/7vDW/YSSCLEZNAGBaBUVkmssjIIrusjhrQ\nQYLigCDKMM4ALr+BUdCMCyIqIsNiFBGD+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0HxrI3rtzPZiXjbM25O3MM48105ySWvty8M5tT855/4XJ7kiC7yX\nAJjRiAKskOGcyTMOcPMvZPbhKh/JbA/jizL7gJ0x/iDJjw2fOvrMbZZ3SpLvzazxG2U4F/IDG2y/\nPLPzP0/N7GtdfjKzPVP7PSez8x9f2Vr7TGYN+nOr6ogNHusrmX34zwWZnXv4uSRPT/KrrbX1e1Jf\nlFkT9pEk/5LkqcNjnJHkv2T2ITiXZvbBOQ8f+zzHaq29KrMG+Q3DGPv31n5lB8Z6Z4YPgcrsHN83\n5Zt7Mh+W2R8DPpjZ8/2bbHB48wEe9x8ya6Bfmtke3htl/Pml+x/jC0nePdTwz2tuekuS78i3NqLP\nSHL1zI4KeHuSV29lrDkek9knK1+e5H9mth4PaDiv92lJ3jZ8Ku/tN7s/AAdW3/5HagD4dlV1p8z2\nwN5ggz2cK6+qzkvys0MjtRKq6uaZNWJXHT5cCQD2BHtEAZirqg5J8rgkz+2xCV0lVfUjVXXV4Wtt\n/neSv9OEArDXaEQB2NSw1+6yzA7dfMaSy9kNHpXZd6j+S5KvJ3n0cssBgOk5NBcAAIBJ2SMKAADA\npDSiAAAATGrflIMdeeS
|
||
|
|
"text/plain": [
|
||
|
|
"<matplotlib.figure.Figure at 0x11e090b70>"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
"metadata": {},
|
||
|
|
"output_type": "display_data"
|
||
|
|
}
|
||
|
|
],
|
||
|
|
"source": [
|
||
|
|
"df['Open'].resample('M').max().plot(kind='bar',figsize=(16,6))\n",
|
||
|
|
"plt.title('Monthly Max Opening Price for Walmart')"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "markdown",
|
||
|
|
"metadata": {},
|
||
|
|
"source": [
|
||
|
|
"That is it! Up next we'll learn about time shifts!"
|
||
|
|
]
|
||
|
|
}
|
||
|
|
],
|
||
|
|
"metadata": {
|
||
|
|
"anaconda-cloud": {},
|
||
|
|
"kernelspec": {
|
||
|
|
"display_name": "Python [conda root]",
|
||
|
|
"language": "python",
|
||
|
|
"name": "conda-root-py"
|
||
|
|
},
|
||
|
|
"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.5.3"
|
||
|
|
}
|
||
|
|
},
|
||
|
|
"nbformat": 4,
|
||
|
|
"nbformat_minor": 0
|
||
|
|
}
|