Applying Functions to Multiple Columns

This commit is contained in:
rasbt 2015-01-28 22:25:09 -05:00
parent 7cfec1ddc0
commit db6679eb9c

View File

@ -1,7 +1,7 @@
{ {
"metadata": { "metadata": {
"name": "", "name": "",
"signature": "sha256:c69dee8958d58e899a12b80810cc37f7abd7a90f9b76135251a76499ed8aeb2a" "signature": "sha256:3155cd3fa2449393a467f91f3cdbb32eeac212db664843ef30f96b635dbfc06d"
}, },
"nbformat": 3, "nbformat": 3,
"nbformat_minor": 0, "nbformat_minor": 0,
@ -1722,7 +1722,7 @@
"input": [ "input": [
"# Filling cells with data\n", "# Filling cells with data\n",
"\n", "\n",
"df.loc[df.index[-1], 'player'] = 'New Player'\n", "df.loc[df.index[-1], 'player'] = 'new player'\n",
"df.loc[df.index[-1], 'salary'] = 12.3\n", "df.loc[df.index[-1], 'salary'] = 12.3\n",
"df.tail(3)" "df.tail(3)"
], ],
@ -1777,7 +1777,7 @@
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>10</th>\n", " <th>10</th>\n",
" <td> New Player</td>\n", " <td> new player</td>\n",
" <td> 12.3</td>\n", " <td> 12.3</td>\n",
" <td>NaN</td>\n", " <td>NaN</td>\n",
" <td>NaN</td>\n", " <td>NaN</td>\n",
@ -1799,7 +1799,7 @@
" player salary games goals assists shots_on_target \\\n", " player salary games goals assists shots_on_target \\\n",
"8 saido berahino 13.8 21 9 0 20 \n", "8 saido berahino 13.8 21 9 0 20 \n",
"9 steven gerrard 13.8 20 5 1 11 \n", "9 steven gerrard 13.8 20 5 1 11 \n",
"10 New Player 12.3 NaN NaN NaN NaN \n", "10 new player 12.3 NaN NaN NaN NaN \n",
"\n", "\n",
" points_per_game points position team \n", " points_per_game points position team \n",
"8 7.02 147.43 forward west brom \n", "8 7.02 147.43 forward west brom \n",
@ -2548,7 +2548,7 @@
"input": [ "input": [
"# Selecting only those players that either playing for Arsenal or Chelsea\n", "# Selecting only those players that either playing for Arsenal or Chelsea\n",
"\n", "\n",
"df[ (df['team'] == 'Arsenal') | (df['team'] == 'Chelsea') ]" "df[ (df['team'] == 'arsenal') | (df['team'] == 'chelsea') ]"
], ],
"language": "python", "language": "python",
"metadata": {}, "metadata": {},
@ -2573,6 +2573,58 @@
" </tr>\n", " </tr>\n",
" </thead>\n", " </thead>\n",
" <tbody>\n", " <tbody>\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> forward</td>\n",
" <td> arsenal</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td> eden hazard</td>\n",
" <td> 18.9</td>\n",
" <td> 21</td>\n",
" <td> 8</td>\n",
" <td> 4</td>\n",
" <td> 17</td>\n",
" <td> 13.05</td>\n",
" <td> 274.04</td>\n",
" <td> midfield</td>\n",
" <td> chelsea</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td> santiago cazorla</td>\n",
" <td> 14.8</td>\n",
" <td> 20</td>\n",
" <td> 4</td>\n",
" <td> 0</td>\n",
" <td> 20</td>\n",
" <td> 9.97</td>\n",
" <td> 0.00</td>\n",
" <td> midfield</td>\n",
" <td> arsenal</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</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> midfield</td>\n",
" <td> chelsea</td>\n",
" </tr>\n",
" </tbody>\n", " </tbody>\n",
"</table>\n", "</table>\n",
"</div>" "</div>"
@ -2581,9 +2633,17 @@
"output_type": "pyout", "output_type": "pyout",
"prompt_number": 21, "prompt_number": 21,
"text": [ "text": [
"Empty DataFrame\n", " player salary games goals assists shots_on_target \\\n",
"Columns: [player, salary, games, goals, assists, shots_on_target, points_per_game, points, position, team]\n", "1 alexis s\u00e1nchez 15 0 12 7 29 \n",
"Index: []" "3 eden hazard 18.9 21 8 4 17 \n",
"7 santiago cazorla 14.8 20 4 0 20 \n",
"9 cesc f\u00e0bregas 14.0 20 2 14 10 \n",
"\n",
" points_per_game points position team \n",
"1 11.19 223.86 forward arsenal \n",
"3 13.05 274.04 midfield chelsea \n",
"7 9.97 0.00 midfield arsenal \n",
"9 10.47 209.49 midfield chelsea "
] ]
} }
], ],
@ -2595,7 +2655,7 @@
"input": [ "input": [
"# Selecting forwards from Arsenal only\n", "# Selecting forwards from Arsenal only\n",
"\n", "\n",
"df[ (df['team'] == 'Arsenal') & (df['position'] == 'Forward') ]" "df[ (df['team'] == 'arsenal') & (df['position'] == 'forward') ]"
], ],
"language": "python", "language": "python",
"metadata": {}, "metadata": {},
@ -2620,6 +2680,19 @@
" </tr>\n", " </tr>\n",
" </thead>\n", " </thead>\n",
" <tbody>\n", " <tbody>\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> forward</td>\n",
" <td> arsenal</td>\n",
" </tr>\n",
" </tbody>\n", " </tbody>\n",
"</table>\n", "</table>\n",
"</div>" "</div>"
@ -2628,9 +2701,11 @@
"output_type": "pyout", "output_type": "pyout",
"prompt_number": 22, "prompt_number": 22,
"text": [ "text": [
"Empty DataFrame\n", " player salary games goals assists shots_on_target \\\n",
"Columns: [player, salary, games, goals, assists, shots_on_target, points_per_game, points, position, team]\n", "1 alexis s\u00e1nchez 15 0 12 7 29 \n",
"Index: []" "\n",
" points_per_game points position team \n",
"1 11.19 223.86 forward arsenal "
] ]
} }
], ],