mirror of
https://github.com/rasbt/python_reference.git
synced 2025-02-17 13:58:13 +00:00
Updating Columns update
This commit is contained in:
parent
f681bd6e5d
commit
c68623a5aa
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"metadata": {
|
||||
"name": "",
|
||||
"signature": "sha256:1ba931b3466a0506e031f8b9bdffcb2ba39138b42f3676b74376988bf095be97"
|
||||
"signature": "sha256:d1e515a46e85e308d5673229e5a6f87c3db1d616a30cee44a09e0af3e088e19c"
|
||||
},
|
||||
"nbformat": 3,
|
||||
"nbformat_minor": 0,
|
||||
|
@ -84,13 +84,18 @@
|
|||
"source": [
|
||||
"- [Loading Some Example Data](#Loading-Some-Example-Data)\n",
|
||||
"- [Renaming Columns](#Renaming-Columns)\n",
|
||||
" - [Converting Column Names to Lowercase](#Converting-Column-Names-to-Lowercase)\n",
|
||||
" - [Renaming Particular Columns](#Renaming-Particular-Columns)\n",
|
||||
"- [Applying Computations Rows-wise](#Applying-Computations-Rows-wise)\n",
|
||||
" - [Changing Values in a Column](#Changing-Values-in-a-Column)\n",
|
||||
" - [Adding a New Column](#Adding-a-New-Column)\n",
|
||||
"- [Missing Values aka NaNs](#Missing-Values-aka-NaNs)\n",
|
||||
" - [Selecting NaN Rows](#Selecting-NaN-Rows)\n",
|
||||
" - [Dropping NaN Rows](#Dropping-NaN-Rows)\n",
|
||||
" - [Selecting non-NaN Rows](#Selecting-non-NaN-Rows)\n",
|
||||
" - [Filling NaN Rows](#Filling-NaN-Rows)\n",
|
||||
"- [Appending Rows to a DataFrame](#Appending-Rows-to-a-DataFrame)\n",
|
||||
"- [Sorting and Reindexing DataFrames](#Sorting-and-Reindexing-DataFrames)"
|
||||
"- [Sorting and Reindexing DataFrames](#Sorting-and-Reindexing-DataFrames)\n",
|
||||
"- [Updating Columns](#Updating-Columns)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -322,6 +327,22 @@
|
|||
"[[back to section overview](#Sections)]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<br>\n",
|
||||
"<br>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "heading",
|
||||
"level": 3,
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Converting Column Names to Lowercase"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
|
@ -333,7 +354,7 @@
|
|||
"# or\n",
|
||||
"# df.rename(columns=lambda x : x.lower())\n",
|
||||
"\n",
|
||||
"df.tail()"
|
||||
"df.tail(3)"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
|
@ -357,28 +378,6 @@
|
|||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
" <tr>\n",
|
||||
" <th>5</th>\n",
|
||||
" <td> Santiago Cazorla\\n Midfield \u2014 Arsenal</td>\n",
|
||||
" <td> $14.8m</td>\n",
|
||||
" <td> 20</td>\n",
|
||||
" <td> 4</td>\n",
|
||||
" <td>NaN</td>\n",
|
||||
" <td> 20</td>\n",
|
||||
" <td> 9.97</td>\n",
|
||||
" <td> NaN</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>6</th>\n",
|
||||
" <td> David Silva\\n Midfield \u2014 Manchester City</td>\n",
|
||||
" <td> $14.3m</td>\n",
|
||||
" <td> 15</td>\n",
|
||||
" <td> 6</td>\n",
|
||||
" <td> 2</td>\n",
|
||||
" <td> 11</td>\n",
|
||||
" <td> 10.35</td>\n",
|
||||
" <td> 155.26</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>7</th>\n",
|
||||
" <td> Cesc F\u00e0bregas\\n Midfield \u2014 Chelsea</td>\n",
|
||||
" <td> $14.0m</td>\n",
|
||||
|
@ -420,15 +419,11 @@
|
|||
"prompt_number": 3,
|
||||
"text": [
|
||||
" player salary gp g a sot ppg \\\n",
|
||||
"5 Santiago Cazorla\\n Midfield \u2014 Arsenal $14.8m 20 4 NaN 20 9.97 \n",
|
||||
"6 David Silva\\n Midfield \u2014 Manchester City $14.3m 15 6 2 11 10.35 \n",
|
||||
"7 Cesc F\u00e0bregas\\n Midfield \u2014 Chelsea $14.0m 20 2 14 10 10.47 \n",
|
||||
"8 Saido Berahino\\n Forward \u2014 West Brom $13.8m 21 9 0 20 7.02 \n",
|
||||
"9 Steven Gerrard\\n Midfield \u2014 Liverpool $13.8m 20 5 1 11 7.50 \n",
|
||||
"\n",
|
||||
" p \n",
|
||||
"5 NaN \n",
|
||||
"6 155.26 \n",
|
||||
"7 209.49 \n",
|
||||
"8 147.43 \n",
|
||||
"9 150.01 "
|
||||
|
@ -437,12 +432,26 @@
|
|||
],
|
||||
"prompt_number": 3
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<br>\n",
|
||||
"<br>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "heading",
|
||||
"level": 3,
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Renaming Particular Columns"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"# Renaming particular columns\n",
|
||||
"\n",
|
||||
"df = df.rename(columns={'p': 'points', \n",
|
||||
" 'gp': 'games',\n",
|
||||
" 'sot': 'shots_on_target',\n",
|
||||
|
@ -450,7 +459,7 @@
|
|||
" 'ppg': 'points_per_game',\n",
|
||||
" 'a': 'assists',})\n",
|
||||
"\n",
|
||||
"df.tail()"
|
||||
"df.tail(3)"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
|
@ -474,28 +483,6 @@
|
|||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
" <tr>\n",
|
||||
" <th>5</th>\n",
|
||||
" <td> Santiago Cazorla\\n Midfield \u2014 Arsenal</td>\n",
|
||||
" <td> $14.8m</td>\n",
|
||||
" <td> 20</td>\n",
|
||||
" <td> 4</td>\n",
|
||||
" <td>NaN</td>\n",
|
||||
" <td> 20</td>\n",
|
||||
" <td> 9.97</td>\n",
|
||||
" <td> NaN</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>6</th>\n",
|
||||
" <td> David Silva\\n Midfield \u2014 Manchester City</td>\n",
|
||||
" <td> $14.3m</td>\n",
|
||||
" <td> 15</td>\n",
|
||||
" <td> 6</td>\n",
|
||||
" <td> 2</td>\n",
|
||||
" <td> 11</td>\n",
|
||||
" <td> 10.35</td>\n",
|
||||
" <td> 155.26</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>7</th>\n",
|
||||
" <td> Cesc F\u00e0bregas\\n Midfield \u2014 Chelsea</td>\n",
|
||||
" <td> $14.0m</td>\n",
|
||||
|
@ -537,15 +524,11 @@
|
|||
"prompt_number": 4,
|
||||
"text": [
|
||||
" player salary games goals assists \\\n",
|
||||
"5 Santiago Cazorla\\n Midfield \u2014 Arsenal $14.8m 20 4 NaN \n",
|
||||
"6 David Silva\\n Midfield \u2014 Manchester City $14.3m 15 6 2 \n",
|
||||
"7 Cesc F\u00e0bregas\\n Midfield \u2014 Chelsea $14.0m 20 2 14 \n",
|
||||
"8 Saido Berahino\\n Forward \u2014 West Brom $13.8m 21 9 0 \n",
|
||||
"9 Steven Gerrard\\n Midfield \u2014 Liverpool $13.8m 20 5 1 \n",
|
||||
"\n",
|
||||
" shots_on_target points_per_game points \n",
|
||||
"5 20 9.97 NaN \n",
|
||||
"6 11 10.35 155.26 \n",
|
||||
"7 10 10.47 209.49 \n",
|
||||
"8 20 7.02 147.43 \n",
|
||||
"9 11 7.50 150.01 "
|
||||
|
@ -577,6 +560,22 @@
|
|||
"[[back to section overview](#Sections)]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<br>\n",
|
||||
"<br>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "heading",
|
||||
"level": 3,
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Changing Values in a Column"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
|
@ -688,12 +687,26 @@
|
|||
],
|
||||
"prompt_number": 5
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<br>\n",
|
||||
"<br>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "heading",
|
||||
"level": 3,
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Adding a New Column"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"# Creating a new column\n",
|
||||
"\n",
|
||||
"df['team'] = pd.Series('', index=df.index)\n",
|
||||
"\n",
|
||||
"# or\n",
|
||||
|
@ -794,9 +807,10 @@
|
|||
"\n",
|
||||
"for idx,row in df.iterrows():\n",
|
||||
" name, position, team = process_player_col(row['player'])\n",
|
||||
"\n",
|
||||
" df.ix[idx, 'player'], df.ix[idx, 'position'], df.ix[idx, 'team'] = name, position, team\n",
|
||||
" \n",
|
||||
"df.tail()"
|
||||
"df.tail(3)"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
|
@ -822,32 +836,6 @@
|
|||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
" <tr>\n",
|
||||
" <th>5</th>\n",
|
||||
" <td> Santiago Cazorla</td>\n",
|
||||
" <td> 14.8</td>\n",
|
||||
" <td> 20</td>\n",
|
||||
" <td> 4</td>\n",
|
||||
" <td>NaN</td>\n",
|
||||
" <td> 20</td>\n",
|
||||
" <td> 9.97</td>\n",
|
||||
" <td> NaN</td>\n",
|
||||
" <td> Arsenal</td>\n",
|
||||
" <td> Midfield</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>6</th>\n",
|
||||
" <td> David Silva</td>\n",
|
||||
" <td> 14.3</td>\n",
|
||||
" <td> 15</td>\n",
|
||||
" <td> 6</td>\n",
|
||||
" <td> 2</td>\n",
|
||||
" <td> 11</td>\n",
|
||||
" <td> 10.35</td>\n",
|
||||
" <td> 155.26</td>\n",
|
||||
" <td> Manchester City</td>\n",
|
||||
" <td> Midfield</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>7</th>\n",
|
||||
" <td> Cesc F\u00e0bregas</td>\n",
|
||||
" <td> 14.0</td>\n",
|
||||
|
@ -895,15 +883,11 @@
|
|||
"prompt_number": 7,
|
||||
"text": [
|
||||
" player salary games goals assists shots_on_target \\\n",
|
||||
"5 Santiago Cazorla 14.8 20 4 NaN 20 \n",
|
||||
"6 David Silva 14.3 15 6 2 11 \n",
|
||||
"7 Cesc F\u00e0bregas 14.0 20 2 14 10 \n",
|
||||
"8 Saido Berahino 13.8 21 9 0 20 \n",
|
||||
"9 Steven Gerrard 13.8 20 5 1 11 \n",
|
||||
"\n",
|
||||
" points_per_game points team position \n",
|
||||
"5 9.97 NaN Arsenal Midfield \n",
|
||||
"6 10.35 155.26 Manchester City Midfield \n",
|
||||
"7 10.47 209.49 Chelsea Midfield \n",
|
||||
"8 7.02 147.43 West Brom Forward \n",
|
||||
"9 7.50 150.01 Liverpool Midfield "
|
||||
|
@ -945,25 +929,19 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "heading",
|
||||
"level": 2,
|
||||
"level": 3,
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Selecting NaN Rows"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"[[back to section overview](#Sections)]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"# Selecting all rows that have NaNs in the `assists` column\n",
|
||||
"df[~df['assists'].notnull()]"
|
||||
"\n",
|
||||
"df[df['assists'].isnull()]"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
|
@ -1044,25 +1022,16 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "heading",
|
||||
"level": 2,
|
||||
"level": 3,
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Dropping NaN Rows"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"[[back to section overview](#Sections)]"
|
||||
"Selecting non-NaN Rows"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"# Dropping all rows that have NaNs in the `assists` column\n",
|
||||
"\n",
|
||||
"df[df['assists'].notnull()]"
|
||||
],
|
||||
"language": "python",
|
||||
|
@ -1234,19 +1203,12 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "heading",
|
||||
"level": 2,
|
||||
"level": 3,
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Filling NaN Rows"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"[[back to section overview](#Sections)]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
|
@ -1481,7 +1443,7 @@
|
|||
" index=df.columns), \n",
|
||||
" ignore_index=True)\n",
|
||||
"\n",
|
||||
"df.tail()"
|
||||
"df.tail(3)"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
|
@ -1507,32 +1469,6 @@
|
|||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
" <tr>\n",
|
||||
" <th>6 </th>\n",
|
||||
" <td> David Silva</td>\n",
|
||||
" <td> 14.3</td>\n",
|
||||
" <td> 15</td>\n",
|
||||
" <td> 6</td>\n",
|
||||
" <td> 2</td>\n",
|
||||
" <td> 11</td>\n",
|
||||
" <td> 10.35</td>\n",
|
||||
" <td> 155.26</td>\n",
|
||||
" <td> Manchester City</td>\n",
|
||||
" <td> Midfield</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>7 </th>\n",
|
||||
" <td> Cesc F\u00e0bregas</td>\n",
|
||||
" <td> 14.0</td>\n",
|
||||
" <td> 20</td>\n",
|
||||
" <td> 2</td>\n",
|
||||
" <td> 14</td>\n",
|
||||
" <td> 10</td>\n",
|
||||
" <td> 10.47</td>\n",
|
||||
" <td> 209.49</td>\n",
|
||||
" <td> Chelsea</td>\n",
|
||||
" <td> Midfield</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>8 </th>\n",
|
||||
" <td> Saido Berahino</td>\n",
|
||||
" <td> 13.8</td>\n",
|
||||
|
@ -1580,15 +1516,11 @@
|
|||
"prompt_number": 11,
|
||||
"text": [
|
||||
" player salary games goals assists shots_on_target \\\n",
|
||||
"6 David Silva 14.3 15 6 2 11 \n",
|
||||
"7 Cesc F\u00e0bregas 14.0 20 2 14 10 \n",
|
||||
"8 Saido Berahino 13.8 21 9 0 20 \n",
|
||||
"9 Steven Gerrard 13.8 20 5 1 11 \n",
|
||||
"10 NaN NaN NaN NaN NaN NaN \n",
|
||||
"\n",
|
||||
" points_per_game points team position \n",
|
||||
"6 10.35 155.26 Manchester City Midfield \n",
|
||||
"7 10.47 209.49 Chelsea Midfield \n",
|
||||
"8 7.02 147.43 West Brom Forward \n",
|
||||
"9 7.50 150.01 Liverpool Midfield \n",
|
||||
"10 NaN NaN NaN NaN "
|
||||
|
@ -1605,7 +1537,7 @@
|
|||
"\n",
|
||||
"df.loc[df.index[-1], 'player'] = 'New Player'\n",
|
||||
"df.loc[df.index[-1], 'salary'] = 12.3\n",
|
||||
"df.tail()"
|
||||
"df.tail(3)"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
|
@ -1631,32 +1563,6 @@
|
|||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
" <tr>\n",
|
||||
" <th>6 </th>\n",
|
||||
" <td> David Silva</td>\n",
|
||||
" <td> 14.3</td>\n",
|
||||
" <td> 15</td>\n",
|
||||
" <td> 6</td>\n",
|
||||
" <td> 2</td>\n",
|
||||
" <td> 11</td>\n",
|
||||
" <td> 10.35</td>\n",
|
||||
" <td> 155.26</td>\n",
|
||||
" <td> Manchester City</td>\n",
|
||||
" <td> Midfield</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>7 </th>\n",
|
||||
" <td> Cesc F\u00e0bregas</td>\n",
|
||||
" <td> 14.0</td>\n",
|
||||
" <td> 20</td>\n",
|
||||
" <td> 2</td>\n",
|
||||
" <td> 14</td>\n",
|
||||
" <td> 10</td>\n",
|
||||
" <td> 10.47</td>\n",
|
||||
" <td> 209.49</td>\n",
|
||||
" <td> Chelsea</td>\n",
|
||||
" <td> Midfield</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>8 </th>\n",
|
||||
" <td> Saido Berahino</td>\n",
|
||||
" <td> 13.8</td>\n",
|
||||
|
@ -1704,15 +1610,11 @@
|
|||
"prompt_number": 12,
|
||||
"text": [
|
||||
" player salary games goals assists shots_on_target \\\n",
|
||||
"6 David Silva 14.3 15 6 2 11 \n",
|
||||
"7 Cesc F\u00e0bregas 14.0 20 2 14 10 \n",
|
||||
"8 Saido Berahino 13.8 21 9 0 20 \n",
|
||||
"9 Steven Gerrard 13.8 20 5 1 11 \n",
|
||||
"10 New Player 12.3 NaN NaN NaN NaN \n",
|
||||
"\n",
|
||||
" points_per_game points team position \n",
|
||||
"6 10.35 155.26 Manchester City Midfield \n",
|
||||
"7 10.47 209.49 Chelsea Midfield \n",
|
||||
"8 7.02 147.43 West Brom Forward \n",
|
||||
"9 7.50 150.01 Liverpool Midfield \n",
|
||||
"10 NaN NaN NaN NaN "
|
||||
|
@ -1871,7 +1773,7 @@
|
|||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"# Reindexing the DataFrame after sorting\n",
|
||||
"# Optional reindexing of the DataFrame after sorting\n",
|
||||
"\n",
|
||||
"df.index = range(1,len(df.index)+1)\n",
|
||||
"df.head()"
|
||||
|
@ -1989,6 +1891,455 @@
|
|||
}
|
||||
],
|
||||
"prompt_number": 14
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<br>\n",
|
||||
"<br>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "heading",
|
||||
"level": 1,
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Updating Columns"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"[[back to section overview](#Sections)]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"# Creating a dummy DataFrame with changes in the `salary` column\n",
|
||||
"\n",
|
||||
"df_2 = df.copy()\n",
|
||||
"df_2.loc[0:2, 'salary'] = [20.0, 15.0]\n",
|
||||
"df_2.head(3)"
|
||||
],
|
||||
"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>player</th>\n",
|
||||
" <th>salary</th>\n",
|
||||
" <th>games</th>\n",
|
||||
" <th>goals</th>\n",
|
||||
" <th>assists</th>\n",
|
||||
" <th>shots_on_target</th>\n",
|
||||
" <th>points_per_game</th>\n",
|
||||
" <th>points</th>\n",
|
||||
" <th>team</th>\n",
|
||||
" <th>position</th>\n",
|
||||
" </tr>\n",
|
||||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
" <tr>\n",
|
||||
" <th>1</th>\n",
|
||||
" <td> Sergio Ag\u00fcero</td>\n",
|
||||
" <td> 20</td>\n",
|
||||
" <td> 16</td>\n",
|
||||
" <td> 14</td>\n",
|
||||
" <td> 3</td>\n",
|
||||
" <td> 34</td>\n",
|
||||
" <td> 13.12</td>\n",
|
||||
" <td> 209.98</td>\n",
|
||||
" <td> Manchester City</td>\n",
|
||||
" <td> Forward</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>2</th>\n",
|
||||
" <td> Alexis S\u00e1nchez</td>\n",
|
||||
" <td> 15</td>\n",
|
||||
" <td> 0</td>\n",
|
||||
" <td> 12</td>\n",
|
||||
" <td> 7</td>\n",
|
||||
" <td> 29</td>\n",
|
||||
" <td> 11.19</td>\n",
|
||||
" <td> 223.86</td>\n",
|
||||
" <td> Arsenal</td>\n",
|
||||
" <td> Forward</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>3</th>\n",
|
||||
" <td> Saido Berahino</td>\n",
|
||||
" <td> 13.8</td>\n",
|
||||
" <td> 21</td>\n",
|
||||
" <td> 9</td>\n",
|
||||
" <td> 0</td>\n",
|
||||
" <td> 20</td>\n",
|
||||
" <td> 7.02</td>\n",
|
||||
" <td> 147.43</td>\n",
|
||||
" <td> West Brom</td>\n",
|
||||
" <td> Forward</td>\n",
|
||||
" </tr>\n",
|
||||
" </tbody>\n",
|
||||
"</table>\n",
|
||||
"</div>"
|
||||
],
|
||||
"metadata": {},
|
||||
"output_type": "pyout",
|
||||
"prompt_number": 15,
|
||||
"text": [
|
||||
" player salary games goals assists shots_on_target \\\n",
|
||||
"1 Sergio Ag\u00fcero 20 16 14 3 34 \n",
|
||||
"2 Alexis S\u00e1nchez 15 0 12 7 29 \n",
|
||||
"3 Saido Berahino 13.8 21 9 0 20 \n",
|
||||
"\n",
|
||||
" points_per_game points team position \n",
|
||||
"1 13.12 209.98 Manchester City Forward \n",
|
||||
"2 11.19 223.86 Arsenal Forward \n",
|
||||
"3 7.02 147.43 West Brom Forward "
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 15
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<br>\n",
|
||||
"<br>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"# Temporarily use the `player` columns as indices to \n",
|
||||
"# apply the update functions\n",
|
||||
"\n",
|
||||
"df.set_index('player', inplace=True)\n",
|
||||
"df_2.set_index('player', inplace=True)\n",
|
||||
"df.head(3)"
|
||||
],
|
||||
"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>salary</th>\n",
|
||||
" <th>games</th>\n",
|
||||
" <th>goals</th>\n",
|
||||
" <th>assists</th>\n",
|
||||
" <th>shots_on_target</th>\n",
|
||||
" <th>points_per_game</th>\n",
|
||||
" <th>points</th>\n",
|
||||
" <th>team</th>\n",
|
||||
" <th>position</th>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>player</th>\n",
|
||||
" <th></th>\n",
|
||||
" <th></th>\n",
|
||||
" <th></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>Sergio Ag\u00fcero</th>\n",
|
||||
" <td> 19.2</td>\n",
|
||||
" <td> 16</td>\n",
|
||||
" <td> 14</td>\n",
|
||||
" <td> 3</td>\n",
|
||||
" <td> 34</td>\n",
|
||||
" <td> 13.12</td>\n",
|
||||
" <td> 209.98</td>\n",
|
||||
" <td> Manchester City</td>\n",
|
||||
" <td> Forward</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>Alexis S\u00e1nchez</th>\n",
|
||||
" <td> 17.6</td>\n",
|
||||
" <td> 0</td>\n",
|
||||
" <td> 12</td>\n",
|
||||
" <td> 7</td>\n",
|
||||
" <td> 29</td>\n",
|
||||
" <td> 11.19</td>\n",
|
||||
" <td> 223.86</td>\n",
|
||||
" <td> Arsenal</td>\n",
|
||||
" <td> Forward</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>Saido Berahino</th>\n",
|
||||
" <td> 13.8</td>\n",
|
||||
" <td> 21</td>\n",
|
||||
" <td> 9</td>\n",
|
||||
" <td> 0</td>\n",
|
||||
" <td> 20</td>\n",
|
||||
" <td> 7.02</td>\n",
|
||||
" <td> 147.43</td>\n",
|
||||
" <td> West Brom</td>\n",
|
||||
" <td> Forward</td>\n",
|
||||
" </tr>\n",
|
||||
" </tbody>\n",
|
||||
"</table>\n",
|
||||
"</div>"
|
||||
],
|
||||
"metadata": {},
|
||||
"output_type": "pyout",
|
||||
"prompt_number": 16,
|
||||
"text": [
|
||||
" salary games goals assists shots_on_target \\\n",
|
||||
"player \n",
|
||||
"Sergio Ag\u00fcero 19.2 16 14 3 34 \n",
|
||||
"Alexis S\u00e1nchez 17.6 0 12 7 29 \n",
|
||||
"Saido Berahino 13.8 21 9 0 20 \n",
|
||||
"\n",
|
||||
" points_per_game points team position \n",
|
||||
"player \n",
|
||||
"Sergio Ag\u00fcero 13.12 209.98 Manchester City Forward \n",
|
||||
"Alexis S\u00e1nchez 11.19 223.86 Arsenal Forward \n",
|
||||
"Saido Berahino 7.02 147.43 West Brom Forward "
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 16
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<br>\n",
|
||||
"<br>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"# Update the `salary` column\n",
|
||||
"df.update(other=df_2['salary'], overwrite=True)\n",
|
||||
"df.head(3)"
|
||||
],
|
||||
"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>salary</th>\n",
|
||||
" <th>games</th>\n",
|
||||
" <th>goals</th>\n",
|
||||
" <th>assists</th>\n",
|
||||
" <th>shots_on_target</th>\n",
|
||||
" <th>points_per_game</th>\n",
|
||||
" <th>points</th>\n",
|
||||
" <th>team</th>\n",
|
||||
" <th>position</th>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>player</th>\n",
|
||||
" <th></th>\n",
|
||||
" <th></th>\n",
|
||||
" <th></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>Sergio Ag\u00fcero</th>\n",
|
||||
" <td> 20</td>\n",
|
||||
" <td> 16</td>\n",
|
||||
" <td> 14</td>\n",
|
||||
" <td> 3</td>\n",
|
||||
" <td> 34</td>\n",
|
||||
" <td> 13.12</td>\n",
|
||||
" <td> 209.98</td>\n",
|
||||
" <td> Manchester City</td>\n",
|
||||
" <td> Forward</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>Alexis S\u00e1nchez</th>\n",
|
||||
" <td> 15</td>\n",
|
||||
" <td> 0</td>\n",
|
||||
" <td> 12</td>\n",
|
||||
" <td> 7</td>\n",
|
||||
" <td> 29</td>\n",
|
||||
" <td> 11.19</td>\n",
|
||||
" <td> 223.86</td>\n",
|
||||
" <td> Arsenal</td>\n",
|
||||
" <td> Forward</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>Saido Berahino</th>\n",
|
||||
" <td> 13.8</td>\n",
|
||||
" <td> 21</td>\n",
|
||||
" <td> 9</td>\n",
|
||||
" <td> 0</td>\n",
|
||||
" <td> 20</td>\n",
|
||||
" <td> 7.02</td>\n",
|
||||
" <td> 147.43</td>\n",
|
||||
" <td> West Brom</td>\n",
|
||||
" <td> Forward</td>\n",
|
||||
" </tr>\n",
|
||||
" </tbody>\n",
|
||||
"</table>\n",
|
||||
"</div>"
|
||||
],
|
||||
"metadata": {},
|
||||
"output_type": "pyout",
|
||||
"prompt_number": 17,
|
||||
"text": [
|
||||
" salary games goals assists shots_on_target \\\n",
|
||||
"player \n",
|
||||
"Sergio Ag\u00fcero 20 16 14 3 34 \n",
|
||||
"Alexis S\u00e1nchez 15 0 12 7 29 \n",
|
||||
"Saido Berahino 13.8 21 9 0 20 \n",
|
||||
"\n",
|
||||
" points_per_game points team position \n",
|
||||
"player \n",
|
||||
"Sergio Ag\u00fcero 13.12 209.98 Manchester City Forward \n",
|
||||
"Alexis S\u00e1nchez 11.19 223.86 Arsenal Forward \n",
|
||||
"Saido Berahino 7.02 147.43 West Brom Forward "
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 17
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<br>\n",
|
||||
"<br>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"# Reset the indices\n",
|
||||
"df.reset_index(inplace=True)\n",
|
||||
"df.head(3)"
|
||||
],
|
||||
"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>player</th>\n",
|
||||
" <th>salary</th>\n",
|
||||
" <th>games</th>\n",
|
||||
" <th>goals</th>\n",
|
||||
" <th>assists</th>\n",
|
||||
" <th>shots_on_target</th>\n",
|
||||
" <th>points_per_game</th>\n",
|
||||
" <th>points</th>\n",
|
||||
" <th>team</th>\n",
|
||||
" <th>position</th>\n",
|
||||
" </tr>\n",
|
||||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
" <tr>\n",
|
||||
" <th>0</th>\n",
|
||||
" <td> Sergio Ag\u00fcero</td>\n",
|
||||
" <td> 20</td>\n",
|
||||
" <td> 16</td>\n",
|
||||
" <td> 14</td>\n",
|
||||
" <td> 3</td>\n",
|
||||
" <td> 34</td>\n",
|
||||
" <td> 13.12</td>\n",
|
||||
" <td> 209.98</td>\n",
|
||||
" <td> Manchester City</td>\n",
|
||||
" <td> Forward</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>1</th>\n",
|
||||
" <td> Alexis S\u00e1nchez</td>\n",
|
||||
" <td> 15</td>\n",
|
||||
" <td> 0</td>\n",
|
||||
" <td> 12</td>\n",
|
||||
" <td> 7</td>\n",
|
||||
" <td> 29</td>\n",
|
||||
" <td> 11.19</td>\n",
|
||||
" <td> 223.86</td>\n",
|
||||
" <td> Arsenal</td>\n",
|
||||
" <td> Forward</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>2</th>\n",
|
||||
" <td> Saido Berahino</td>\n",
|
||||
" <td> 13.8</td>\n",
|
||||
" <td> 21</td>\n",
|
||||
" <td> 9</td>\n",
|
||||
" <td> 0</td>\n",
|
||||
" <td> 20</td>\n",
|
||||
" <td> 7.02</td>\n",
|
||||
" <td> 147.43</td>\n",
|
||||
" <td> West Brom</td>\n",
|
||||
" <td> Forward</td>\n",
|
||||
" </tr>\n",
|
||||
" </tbody>\n",
|
||||
"</table>\n",
|
||||
"</div>"
|
||||
],
|
||||
"metadata": {},
|
||||
"output_type": "pyout",
|
||||
"prompt_number": 18,
|
||||
"text": [
|
||||
" player salary games goals assists shots_on_target \\\n",
|
||||
"0 Sergio Ag\u00fcero 20 16 14 3 34 \n",
|
||||
"1 Alexis S\u00e1nchez 15 0 12 7 29 \n",
|
||||
"2 Saido Berahino 13.8 21 9 0 20 \n",
|
||||
"\n",
|
||||
" points_per_game points team position \n",
|
||||
"0 13.12 209.98 Manchester City Forward \n",
|
||||
"1 11.19 223.86 Arsenal Forward \n",
|
||||
"2 7.02 147.43 West Brom Forward "
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 18
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"prompt_number": 18
|
||||
}
|
||||
],
|
||||
"metadata": {}
|
||||
|
|
Loading…
Reference in New Issue
Block a user