Created
April 3, 2013 21:44
-
-
Save jorisvandenbossche/5305681 to your computer and use it in GitHub Desktop.
test link
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"metadata": { | |
"name": "test_hierarchical_index" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "heading", | |
"level": 1, | |
"metadata": { | |
"slideshow": { | |
"slide_type": "slide" | |
} | |
}, | |
"source": [ | |
"Turin stationary data: Alphasenso CO sensor data investigation" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"link [example link](#Test met de heading)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"%pylab\n", | |
"import numpy as np\n", | |
"import matplotlib.pyplot as plt\n", | |
"import datetime as dt\n", | |
"import pandas as pd\n", | |
"import os" | |
], | |
"language": "python", | |
"metadata": { | |
"slideshow": { | |
"slide_type": "slide" | |
} | |
}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n", | |
"Welcome to pylab, a matplotlib-based Python environment [backend: Qt4Agg].\n", | |
"For more information, type 'help(pylab)'.\n" | |
] | |
} | |
], | |
"prompt_number": 1 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"arrays = [['SB1', 'SB1', 'SB2', 'SB2', 'SB3', 'SB3', 'SB4', 'SB4'],\n", | |
" ['co_alpha', 'temp', 'co_alpha', 'temp', 'co_alpha', 'temp', 'co_alpha', 'temp']]" | |
], | |
"language": "python", | |
"metadata": { | |
"slideshow": { | |
"slide_type": "slide" | |
} | |
}, | |
"outputs": [], | |
"prompt_number": 2 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"tuples = zip(*arrays)\n", | |
"tuples" | |
], | |
"language": "python", | |
"metadata": { | |
"slideshow": { | |
"slide_type": "fragment" | |
} | |
}, | |
"outputs": [ | |
{ | |
"output_type": "pyout", | |
"prompt_number": 3, | |
"text": [ | |
"[('SB1', 'co_alpha'),\n", | |
" ('SB1', 'temp'),\n", | |
" ('SB2', 'co_alpha'),\n", | |
" ('SB2', 'temp'),\n", | |
" ('SB3', 'co_alpha'),\n", | |
" ('SB3', 'temp'),\n", | |
" ('SB4', 'co_alpha'),\n", | |
" ('SB4', 'temp')]" | |
] | |
} | |
], | |
"prompt_number": 3 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"index = pd.MultiIndex.from_tuples(tuples, names=['first', 'second'])\n", | |
"index" | |
], | |
"language": "python", | |
"metadata": { | |
"slideshow": { | |
"slide_type": "slide" | |
} | |
}, | |
"outputs": [ | |
{ | |
"output_type": "pyout", | |
"prompt_number": 4, | |
"text": [ | |
"MultiIndex\n", | |
"[(SB1, co_alpha), (SB1, temp), (SB2, co_alpha), (SB2, temp), (SB3, co_alpha), (SB3, temp), (SB4, co_alpha), (SB4, temp)]" | |
] | |
} | |
], | |
"prompt_number": 4 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"s = pd.Series(randn(8), index=index)\n", | |
"s" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "pyout", | |
"prompt_number": 5, | |
"text": [ | |
"first second \n", | |
"SB1 co_alpha -0.672864\n", | |
" temp -1.785706\n", | |
"SB2 co_alpha -0.253444\n", | |
" temp 0.012696\n", | |
"SB3 co_alpha -1.071290\n", | |
" temp 0.665913\n", | |
"SB4 co_alpha -1.676434\n", | |
" temp 0.596448" | |
] | |
} | |
], | |
"prompt_number": 5 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"pd.Series(randn(8), index=arrays)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "pyout", | |
"prompt_number": 6, | |
"text": [ | |
"SB1 co_alpha -1.331681\n", | |
" temp -0.786089\n", | |
"SB2 co_alpha 2.325138\n", | |
" temp 0.910780\n", | |
"SB3 co_alpha 0.105687\n", | |
" temp 0.037443\n", | |
"SB4 co_alpha -0.832341\n", | |
" temp -1.389372" | |
] | |
} | |
], | |
"prompt_number": 6 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"df = pd.DataFrame(randn(4, 8), columns=arrays)\n", | |
"df" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"html": [ | |
"<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr>\n", | |
" <th></th>\n", | |
" <th colspan=\"2\" halign=\"left\">SB1</th>\n", | |
" <th colspan=\"2\" halign=\"left\">SB2</th>\n", | |
" <th colspan=\"2\" halign=\"left\">SB3</th>\n", | |
" <th colspan=\"2\" halign=\"left\">SB4</th>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th></th>\n", | |
" <th>co_alpha</th>\n", | |
" <th>temp</th>\n", | |
" <th>co_alpha</th>\n", | |
" <th>temp</th>\n", | |
" <th>co_alpha</th>\n", | |
" <th>temp</th>\n", | |
" <th>co_alpha</th>\n", | |
" <th>temp</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>-0.368326</td>\n", | |
" <td>-0.400795</td>\n", | |
" <td> 0.474947</td>\n", | |
" <td>-0.145894</td>\n", | |
" <td>-0.794057</td>\n", | |
" <td> 0.147168</td>\n", | |
" <td>-0.271703</td>\n", | |
" <td>-0.739156</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td> 0.244511</td>\n", | |
" <td>-0.225491</td>\n", | |
" <td>-0.441524</td>\n", | |
" <td>-0.017268</td>\n", | |
" <td> 0.673915</td>\n", | |
" <td>-0.830436</td>\n", | |
" <td>-0.522951</td>\n", | |
" <td>-0.088112</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td> 0.441055</td>\n", | |
" <td> 0.866874</td>\n", | |
" <td>-0.281293</td>\n", | |
" <td>-0.892865</td>\n", | |
" <td>-0.016720</td>\n", | |
" <td> 0.789519</td>\n", | |
" <td> 0.316520</td>\n", | |
" <td>-0.947715</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td> 1.137661</td>\n", | |
" <td>-0.103103</td>\n", | |
" <td> 0.258673</td>\n", | |
" <td>-0.801883</td>\n", | |
" <td> 1.613163</td>\n", | |
" <td> 1.246364</td>\n", | |
" <td> 0.118795</td>\n", | |
" <td>-0.960764</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"output_type": "pyout", | |
"prompt_number": 28, | |
"text": [ | |
" SB1 SB2 SB3 SB4 \n", | |
" co_alpha temp co_alpha temp co_alpha temp co_alpha temp\n", | |
"0 -0.368326 -0.400795 0.474947 -0.145894 -0.794057 0.147168 -0.271703 -0.739156\n", | |
"1 0.244511 -0.225491 -0.441524 -0.017268 0.673915 -0.830436 -0.522951 -0.088112\n", | |
"2 0.441055 0.866874 -0.281293 -0.892865 -0.016720 0.789519 0.316520 -0.947715\n", | |
"3 1.137661 -0.103103 0.258673 -0.801883 1.613163 1.246364 0.118795 -0.960764" | |
] | |
} | |
], | |
"prompt_number": 28 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"df['SB1']" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"html": [ | |
"<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>co_alpha</th>\n", | |
" <th>temp</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>-0.368326</td>\n", | |
" <td>-0.400795</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td> 0.244511</td>\n", | |
" <td>-0.225491</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td> 0.441055</td>\n", | |
" <td> 0.866874</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td> 1.137661</td>\n", | |
" <td>-0.103103</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"output_type": "pyout", | |
"prompt_number": 29, | |
"text": [ | |
" co_alpha temp\n", | |
"0 -0.368326 -0.400795\n", | |
"1 0.244511 -0.225491\n", | |
"2 0.441055 0.866874\n", | |
"3 1.137661 -0.103103" | |
] | |
} | |
], | |
"prompt_number": 29 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"df['SB1']['co_alpha']" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "pyout", | |
"prompt_number": 30, | |
"text": [ | |
"0 -0.368326\n", | |
"1 0.244511\n", | |
"2 0.441055\n", | |
"3 1.137661\n", | |
"Name: co_alpha" | |
] | |
} | |
], | |
"prompt_number": 30 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"df['SB1', 'co_alpha']" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "pyout", | |
"prompt_number": 31, | |
"text": [ | |
"0 -0.368326\n", | |
"1 0.244511\n", | |
"2 0.441055\n", | |
"3 1.137661\n", | |
"Name: (SB1, co_alpha)" | |
] | |
} | |
], | |
"prompt_number": 31 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"df.xs('temp', axis=1, level=1)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"html": [ | |
"<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>SB1</th>\n", | |
" <th>SB2</th>\n", | |
" <th>SB3</th>\n", | |
" <th>SB4</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>-0.400795</td>\n", | |
" <td>-0.145894</td>\n", | |
" <td> 0.147168</td>\n", | |
" <td>-0.739156</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>-0.225491</td>\n", | |
" <td>-0.017268</td>\n", | |
" <td>-0.830436</td>\n", | |
" <td>-0.088112</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td> 0.866874</td>\n", | |
" <td>-0.892865</td>\n", | |
" <td> 0.789519</td>\n", | |
" <td>-0.947715</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>-0.103103</td>\n", | |
" <td>-0.801883</td>\n", | |
" <td> 1.246364</td>\n", | |
" <td>-0.960764</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"output_type": "pyout", | |
"prompt_number": 32, | |
"text": [ | |
" SB1 SB2 SB3 SB4\n", | |
"0 -0.400795 -0.145894 0.147168 -0.739156\n", | |
"1 -0.225491 -0.017268 -0.830436 -0.088112\n", | |
"2 0.866874 -0.892865 0.789519 -0.947715\n", | |
"3 -0.103103 -0.801883 1.246364 -0.960764" | |
] | |
} | |
], | |
"prompt_number": 32 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"df['SB1', 'test'] = 0" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 38 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"df" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"html": [ | |
"<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr>\n", | |
" <th></th>\n", | |
" <th colspan=\"2\" halign=\"left\">SB1</th>\n", | |
" <th colspan=\"2\" halign=\"left\">SB2</th>\n", | |
" <th colspan=\"2\" halign=\"left\">SB3</th>\n", | |
" <th colspan=\"2\" halign=\"left\">SB4</th>\n", | |
" <th>SB1</th>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th></th>\n", | |
" <th>co_alpha</th>\n", | |
" <th>temp</th>\n", | |
" <th>co_alpha</th>\n", | |
" <th>temp</th>\n", | |
" <th>co_alpha</th>\n", | |
" <th>temp</th>\n", | |
" <th>co_alpha</th>\n", | |
" <th>temp</th>\n", | |
" <th>test</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>-0.368326</td>\n", | |
" <td>-0.400795</td>\n", | |
" <td> 0.474947</td>\n", | |
" <td>-0.145894</td>\n", | |
" <td>-0.794057</td>\n", | |
" <td> 0.147168</td>\n", | |
" <td>-0.271703</td>\n", | |
" <td>-0.739156</td>\n", | |
" <td> 0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td> 0.244511</td>\n", | |
" <td>-0.225491</td>\n", | |
" <td>-0.441524</td>\n", | |
" <td>-0.017268</td>\n", | |
" <td> 0.673915</td>\n", | |
" <td>-0.830436</td>\n", | |
" <td>-0.522951</td>\n", | |
" <td>-0.088112</td>\n", | |
" <td> 0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td> 0.441055</td>\n", | |
" <td> 0.866874</td>\n", | |
" <td>-0.281293</td>\n", | |
" <td>-0.892865</td>\n", | |
" <td>-0.016720</td>\n", | |
" <td> 0.789519</td>\n", | |
" <td> 0.316520</td>\n", | |
" <td>-0.947715</td>\n", | |
" <td> 0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td> 1.137661</td>\n", | |
" <td>-0.103103</td>\n", | |
" <td> 0.258673</td>\n", | |
" <td>-0.801883</td>\n", | |
" <td> 1.613163</td>\n", | |
" <td> 1.246364</td>\n", | |
" <td> 0.118795</td>\n", | |
" <td>-0.960764</td>\n", | |
" <td> 0</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"output_type": "pyout", | |
"prompt_number": 39, | |
"text": [ | |
" SB1 SB2 SB3 SB4 SB1\n", | |
" co_alpha temp co_alpha temp co_alpha temp co_alpha temp test\n", | |
"0 -0.368326 -0.400795 0.474947 -0.145894 -0.794057 0.147168 -0.271703 -0.739156 0\n", | |
"1 0.244511 -0.225491 -0.441524 -0.017268 0.673915 -0.830436 -0.522951 -0.088112 0\n", | |
"2 0.441055 0.866874 -0.281293 -0.892865 -0.016720 0.789519 0.316520 -0.947715 0\n", | |
"3 1.137661 -0.103103 0.258673 -0.801883 1.613163 1.246364 0.118795 -0.960764 0" | |
] | |
} | |
], | |
"prompt_number": 39 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"df['SB1']['test']" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "pyout", | |
"prompt_number": 17, | |
"text": [ | |
"0 0\n", | |
"1 0\n", | |
"2 0\n", | |
"3 0\n", | |
"Name: test" | |
] | |
} | |
], | |
"prompt_number": 17 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"df.columns" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "pyout", | |
"prompt_number": 40, | |
"text": [ | |
"MultiIndex\n", | |
"[(SB1, co_alpha), (SB1, temp), (SB2, co_alpha), (SB2, temp), (SB3, co_alpha), (SB3, temp), (SB4, co_alpha), (SB4, temp), (SB1, test)]" | |
] | |
} | |
], | |
"prompt_number": 40 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"df['SB1']" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"html": [ | |
"<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>co_alpha</th>\n", | |
" <th>temp</th>\n", | |
" <th>test</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>-0.368326</td>\n", | |
" <td>-0.400795</td>\n", | |
" <td> 0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td> 0.244511</td>\n", | |
" <td>-0.225491</td>\n", | |
" <td> 0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td> 0.441055</td>\n", | |
" <td> 0.866874</td>\n", | |
" <td> 0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td> 1.137661</td>\n", | |
" <td>-0.103103</td>\n", | |
" <td> 0</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"output_type": "pyout", | |
"prompt_number": 41, | |
"text": [ | |
" co_alpha temp test\n", | |
"0 -0.368326 -0.400795 0\n", | |
"1 0.244511 -0.225491 0\n", | |
"2 0.441055 0.866874 0\n", | |
"3 1.137661 -0.103103 0" | |
] | |
} | |
], | |
"prompt_number": 41 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"df = pd.DataFrame(randn(4, 8), columns=index)\n", | |
"df" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 2, | |
"metadata": {}, | |
"source": [ | |
"Test met de heading" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment