mirror of
https://github.com/donnemartin/data-science-ipython-notebooks.git
synced 2024-03-22 13:30:56 +08:00
Added snippet to check for matching values in a specific column for replacement.
This commit is contained in:
parent
f087dcd6c6
commit
90baf301b6
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"metadata": {
|
||||
"name": "",
|
||||
"signature": "sha256:a3874e8de1273dccf0e0d39f584d1345a1c1d55f2b6c1ad780fedce8f9421bcf"
|
||||
"signature": "sha256:82be3772f18b2c96a1486b76adf812e774890e366b350dfd5b1257ab4b086b8e"
|
||||
},
|
||||
"nbformat": 3,
|
||||
"nbformat_minor": 0,
|
||||
|
@ -16,7 +16,8 @@
|
|||
"* Clean\n",
|
||||
"* Transform\n",
|
||||
"* Merge\n",
|
||||
"* Reshape"
|
||||
"* Reshape\n",
|
||||
"* Concatenate"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -35,7 +36,7 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Replace all occurrences of a string with another string, in place (no copy):"
|
||||
"Check for matching values in a specific column for replacement:"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -113,6 +114,70 @@
|
|||
],
|
||||
"prompt_number": 2
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"df_1[df_1['state'] == 'VA']"
|
||||
],
|
||||
"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>pop</th>\n",
|
||||
" <th>state</th>\n",
|
||||
" <th>year</th>\n",
|
||||
" </tr>\n",
|
||||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
" <tr>\n",
|
||||
" <th>0</th>\n",
|
||||
" <td> 5.0</td>\n",
|
||||
" <td> VA</td>\n",
|
||||
" <td> 2012</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>1</th>\n",
|
||||
" <td> 5.1</td>\n",
|
||||
" <td> VA</td>\n",
|
||||
" <td> 2013</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>2</th>\n",
|
||||
" <td> 5.2</td>\n",
|
||||
" <td> VA</td>\n",
|
||||
" <td> 2014</td>\n",
|
||||
" </tr>\n",
|
||||
" </tbody>\n",
|
||||
"</table>\n",
|
||||
"</div>"
|
||||
],
|
||||
"metadata": {},
|
||||
"output_type": "pyout",
|
||||
"prompt_number": 3,
|
||||
"text": [
|
||||
" pop state year\n",
|
||||
"0 5.0 VA 2012\n",
|
||||
"1 5.1 VA 2013\n",
|
||||
"2 5.2 VA 2014"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 3
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Replace all occurrences of a string with another string, in place (no copy):"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
|
@ -172,7 +237,7 @@
|
|||
],
|
||||
"metadata": {},
|
||||
"output_type": "pyout",
|
||||
"prompt_number": 3,
|
||||
"prompt_number": 4,
|
||||
"text": [
|
||||
" pop state year\n",
|
||||
"0 5.0 VIRGINIA 2012\n",
|
||||
|
@ -183,7 +248,7 @@
|
|||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 3
|
||||
"prompt_number": 4
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
|
@ -196,7 +261,8 @@
|
|||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"df_1.replace({'state' : { 'MD' : 'MARYLAND' }})"
|
||||
"df_1.replace({'state' : { 'MD' : 'MARYLAND' }})\n",
|
||||
"df_1"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
|
@ -250,7 +316,7 @@
|
|||
],
|
||||
"metadata": {},
|
||||
"output_type": "pyout",
|
||||
"prompt_number": 4,
|
||||
"prompt_number": 5,
|
||||
"text": [
|
||||
" pop state year\n",
|
||||
"0 5.0 VIRGINIA 2012\n",
|
||||
|
@ -261,7 +327,7 @@
|
|||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 4
|
||||
"prompt_number": 5
|
||||
}
|
||||
],
|
||||
"metadata": {}
|
||||
|
|
Loading…
Reference in New Issue
Block a user