mirror of
https://github.com/donnemartin/data-science-ipython-notebooks.git
synced 2024-03-22 13:30:56 +08:00
Added snippets for basic Arithmetic and Data Alignment for DataFrames.
This commit is contained in:
parent
c2bf4dfda5
commit
418676f075
|
@ -3415,6 +3415,192 @@
|
|||
}
|
||||
],
|
||||
"prompt_number": 66
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"frame_8 = DataFrame(np.random.rand(9).reshape((3, 3)),\n",
|
||||
" columns=['a', 'b', 'c'])\n",
|
||||
"frame_8"
|
||||
],
|
||||
"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>a</th>\n",
|
||||
" <th>b</th>\n",
|
||||
" <th>c</th>\n",
|
||||
" </tr>\n",
|
||||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
" <tr>\n",
|
||||
" <th>0</th>\n",
|
||||
" <td> 0.529893</td>\n",
|
||||
" <td> 0.251433</td>\n",
|
||||
" <td> 0.111151</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>1</th>\n",
|
||||
" <td> 0.088052</td>\n",
|
||||
" <td> 0.595180</td>\n",
|
||||
" <td> 0.128917</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>2</th>\n",
|
||||
" <td> 0.237248</td>\n",
|
||||
" <td> 0.515434</td>\n",
|
||||
" <td> 0.720097</td>\n",
|
||||
" </tr>\n",
|
||||
" </tbody>\n",
|
||||
"</table>\n",
|
||||
"</div>"
|
||||
],
|
||||
"metadata": {},
|
||||
"output_type": "pyout",
|
||||
"prompt_number": 67,
|
||||
"text": [
|
||||
" a b c\n",
|
||||
"0 0.529893 0.251433 0.111151\n",
|
||||
"1 0.088052 0.595180 0.128917\n",
|
||||
"2 0.237248 0.515434 0.720097"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 67
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"frame_9 = DataFrame(np.random.rand(9).reshape((3, 3)),\n",
|
||||
" columns=['b', 'c', 'd'])\n",
|
||||
"frame_9"
|
||||
],
|
||||
"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>b</th>\n",
|
||||
" <th>c</th>\n",
|
||||
" <th>d</th>\n",
|
||||
" </tr>\n",
|
||||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
" <tr>\n",
|
||||
" <th>0</th>\n",
|
||||
" <td> 0.924304</td>\n",
|
||||
" <td> 0.058943</td>\n",
|
||||
" <td> 0.434582</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>1</th>\n",
|
||||
" <td> 0.730805</td>\n",
|
||||
" <td> 0.545480</td>\n",
|
||||
" <td> 0.299172</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>2</th>\n",
|
||||
" <td> 0.280603</td>\n",
|
||||
" <td> 0.703927</td>\n",
|
||||
" <td> 0.790074</td>\n",
|
||||
" </tr>\n",
|
||||
" </tbody>\n",
|
||||
"</table>\n",
|
||||
"</div>"
|
||||
],
|
||||
"metadata": {},
|
||||
"output_type": "pyout",
|
||||
"prompt_number": 68,
|
||||
"text": [
|
||||
" b c d\n",
|
||||
"0 0.924304 0.058943 0.434582\n",
|
||||
"1 0.730805 0.545480 0.299172\n",
|
||||
"2 0.280603 0.703927 0.790074"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 68
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Adding objects results in the union of index pairs for rows and columns if the pairs are not the same, resulting in NAs for indices that do not overlap:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"frame_8 + frame_9"
|
||||
],
|
||||
"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>a</th>\n",
|
||||
" <th>b</th>\n",
|
||||
" <th>c</th>\n",
|
||||
" <th>d</th>\n",
|
||||
" </tr>\n",
|
||||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
" <tr>\n",
|
||||
" <th>0</th>\n",
|
||||
" <td>NaN</td>\n",
|
||||
" <td> 1.175738</td>\n",
|
||||
" <td> 0.170094</td>\n",
|
||||
" <td>NaN</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>1</th>\n",
|
||||
" <td>NaN</td>\n",
|
||||
" <td> 1.325985</td>\n",
|
||||
" <td> 0.674397</td>\n",
|
||||
" <td>NaN</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>2</th>\n",
|
||||
" <td>NaN</td>\n",
|
||||
" <td> 0.796037</td>\n",
|
||||
" <td> 1.424024</td>\n",
|
||||
" <td>NaN</td>\n",
|
||||
" </tr>\n",
|
||||
" </tbody>\n",
|
||||
"</table>\n",
|
||||
"</div>"
|
||||
],
|
||||
"metadata": {},
|
||||
"output_type": "pyout",
|
||||
"prompt_number": 69,
|
||||
"text": [
|
||||
" a b c d\n",
|
||||
"0 NaN 1.175738 0.170094 NaN\n",
|
||||
"1 NaN 1.325985 0.674397 NaN\n",
|
||||
"2 NaN 0.796037 1.424024 NaN"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 69
|
||||
}
|
||||
],
|
||||
"metadata": {}
|
||||
|
|
Loading…
Reference in New Issue
Block a user