Added snippets for Axis Indexes with Duplicate Values.

This commit is contained in:
Donne Martin 2015-02-06 08:21:46 -05:00
parent 12bbfb9678
commit c20545aff7

View File

@ -1,7 +1,7 @@
{
"metadata": {
"name": "",
"signature": "sha256:2b6aa402b58aa2da8c06d378f19732970903abe573b39f9a7490982d0e2ebcbc"
"signature": "sha256:a0f056a23acdf795f7de8660469dcb0323a659e710786e7d33a158a6b72c6c03"
},
"nbformat": 3,
"nbformat_minor": 0,
@ -5126,6 +5126,234 @@
}
],
"prompt_number": 97
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Axis Indexes with Duplicate Values"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Labels do not have to be unique in Pandas:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"ser_12 = Series(range(5), index=['foo', 'foo', 'bar', 'bar', 'baz'])\n",
"ser_12"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 98,
"text": [
"foo 0\n",
"foo 1\n",
"bar 2\n",
"bar 3\n",
"baz 4\n",
"dtype: int64"
]
}
],
"prompt_number": 98
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"ser_12.index.is_unique"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 99,
"text": [
"False"
]
}
],
"prompt_number": 99
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Select Series elements:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"ser_12['foo']"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 100,
"text": [
"foo 0\n",
"foo 1\n",
"dtype: int64"
]
}
],
"prompt_number": 100
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Select DataFrame elements:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"df_14 = DataFrame(np.random.randn(5, 4),\n",
" index=['foo', 'foo', 'bar', 'bar', 'baz'])\n",
"df_14"
],
"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>0</th>\n",
" <th>1</th>\n",
" <th>2</th>\n",
" <th>3</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>foo</th>\n",
" <td>-2.363469</td>\n",
" <td> 1.135345</td>\n",
" <td>-1.017014</td>\n",
" <td> 0.637362</td>\n",
" </tr>\n",
" <tr>\n",
" <th>foo</th>\n",
" <td>-0.859907</td>\n",
" <td> 1.772608</td>\n",
" <td>-1.110363</td>\n",
" <td> 0.181214</td>\n",
" </tr>\n",
" <tr>\n",
" <th>bar</th>\n",
" <td> 0.564345</td>\n",
" <td>-0.566510</td>\n",
" <td> 0.729976</td>\n",
" <td> 0.372994</td>\n",
" </tr>\n",
" <tr>\n",
" <th>bar</th>\n",
" <td> 0.533811</td>\n",
" <td>-0.091973</td>\n",
" <td> 1.913820</td>\n",
" <td> 0.330797</td>\n",
" </tr>\n",
" <tr>\n",
" <th>baz</th>\n",
" <td> 1.141943</td>\n",
" <td>-1.129595</td>\n",
" <td>-0.850052</td>\n",
" <td> 0.960820</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 101,
"text": [
" 0 1 2 3\n",
"foo -2.363469 1.135345 -1.017014 0.637362\n",
"foo -0.859907 1.772608 -1.110363 0.181214\n",
"bar 0.564345 -0.566510 0.729976 0.372994\n",
"bar 0.533811 -0.091973 1.913820 0.330797\n",
"baz 1.141943 -1.129595 -0.850052 0.960820"
]
}
],
"prompt_number": 101
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"df_14.ix['bar']"
],
"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>0</th>\n",
" <th>1</th>\n",
" <th>2</th>\n",
" <th>3</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>bar</th>\n",
" <td> 0.564345</td>\n",
" <td>-0.566510</td>\n",
" <td> 0.729976</td>\n",
" <td> 0.372994</td>\n",
" </tr>\n",
" <tr>\n",
" <th>bar</th>\n",
" <td> 0.533811</td>\n",
" <td>-0.091973</td>\n",
" <td> 1.913820</td>\n",
" <td> 0.330797</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 102,
"text": [
" 0 1 2 3\n",
"bar 0.564345 -0.566510 0.729976 0.372994\n",
"bar 0.533811 -0.091973 1.913820 0.330797"
]
}
],
"prompt_number": 102
}
],
"metadata": {}