Chaining Conditions - Using Bitwise Operators

This commit is contained in:
rasbt 2015-01-24 22:25:57 -05:00
parent 1e6c7444ef
commit 632aef1bc4

View File

@ -1,7 +1,7 @@
{ {
"metadata": { "metadata": {
"name": "", "name": "",
"signature": "sha256:ae8818183bc1fe6a58845005b18b12c4458686fa307a82a46857775364df6506" "signature": "sha256:cf7223086a74b13d1ae2228a4c8545c401765a90cdb3eca418f18138a4afdaab"
}, },
"nbformat": 3, "nbformat": 3,
"nbformat_minor": 0, "nbformat_minor": 0,
@ -95,7 +95,8 @@
" - [Filling NaN Rows](#Filling-NaN-Rows)\n", " - [Filling NaN Rows](#Filling-NaN-Rows)\n",
"- [Appending Rows to a DataFrame](#Appending-Rows-to-a-DataFrame)\n", "- [Appending Rows to a DataFrame](#Appending-Rows-to-a-DataFrame)\n",
"- [Sorting and Reindexing DataFrames](#Sorting-and-Reindexing-DataFrames)\n", "- [Sorting and Reindexing DataFrames](#Sorting-and-Reindexing-DataFrames)\n",
"- [Updating Columns](#Updating-Columns)" "- [Updating Columns](#Updating-Columns)\n",
"- [Chaining Conditions - Using Bitwise Operators](#Chaining-Conditions---Using-Bitwise-Operators)"
] ]
}, },
{ {
@ -806,8 +807,8 @@
"\n", "\n",
"def process_player_col(text):\n", "def process_player_col(text):\n",
" name, rest = text.split('\\n')\n", " name, rest = text.split('\\n')\n",
" position, team = rest.split(' \u2014 ')\n", " position, team = [x.strip() for x in rest.split(' \u2014 ')]\n",
" return pd.Series([name, position, team])\n", " return pd.Series([name, team, position])\n",
"\n", "\n",
"df[['player', 'team', 'position']] = df.player.apply(process_player_col)\n", "df[['player', 'team', 'position']] = df.player.apply(process_player_col)\n",
"\n", "\n",
@ -854,8 +855,8 @@
" <td> 10</td>\n", " <td> 10</td>\n",
" <td> 10.47</td>\n", " <td> 10.47</td>\n",
" <td> 209.49</td>\n", " <td> 209.49</td>\n",
" <td> Chelsea</td>\n",
" <td> Midfield</td>\n", " <td> Midfield</td>\n",
" <td> Chelsea</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>8</th>\n", " <th>8</th>\n",
@ -867,8 +868,8 @@
" <td> 20</td>\n", " <td> 20</td>\n",
" <td> 7.02</td>\n", " <td> 7.02</td>\n",
" <td> 147.43</td>\n", " <td> 147.43</td>\n",
" <td> West Brom</td>\n",
" <td> Forward</td>\n", " <td> Forward</td>\n",
" <td> West Brom</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>9</th>\n", " <th>9</th>\n",
@ -880,8 +881,8 @@
" <td> 11</td>\n", " <td> 11</td>\n",
" <td> 7.50</td>\n", " <td> 7.50</td>\n",
" <td> 150.01</td>\n", " <td> 150.01</td>\n",
" <td> Liverpool</td>\n",
" <td> Midfield</td>\n", " <td> Midfield</td>\n",
" <td> Liverpool</td>\n",
" </tr>\n", " </tr>\n",
" </tbody>\n", " </tbody>\n",
"</table>\n", "</table>\n",
@ -889,7 +890,7 @@
], ],
"metadata": {}, "metadata": {},
"output_type": "pyout", "output_type": "pyout",
"prompt_number": 7, "prompt_number": 8,
"text": [ "text": [
" player salary games goals assists shots_on_target \\\n", " player salary games goals assists shots_on_target \\\n",
"7 Cesc F\u00e0bregas 14.0 20 2 14 10 \n", "7 Cesc F\u00e0bregas 14.0 20 2 14 10 \n",
@ -897,13 +898,13 @@
"9 Steven Gerrard 13.8 20 5 1 11 \n", "9 Steven Gerrard 13.8 20 5 1 11 \n",
"\n", "\n",
" points_per_game points position team \n", " points_per_game points position team \n",
"7 10.47 209.49 Chelsea Midfield \n", "7 10.47 209.49 Midfield Chelsea \n",
"8 7.02 147.43 West Brom Forward \n", "8 7.02 147.43 Forward West Brom \n",
"9 7.50 150.01 Liverpool Midfield " "9 7.50 150.01 Midfield Liverpool "
] ]
} }
], ],
"prompt_number": 7 "prompt_number": 8
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
@ -985,8 +986,8 @@
" <td> 13</td>\n", " <td> 13</td>\n",
" <td> 10.17</td>\n", " <td> 10.17</td>\n",
" <td> 132.23</td>\n", " <td> 132.23</td>\n",
" <td> Manchester United</td>\n",
" <td> Midfield</td>\n", " <td> Midfield</td>\n",
" <td> Manchester United</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>5</th>\n", " <th>5</th>\n",
@ -998,8 +999,8 @@
" <td> 20</td>\n", " <td> 20</td>\n",
" <td> 9.97</td>\n", " <td> 9.97</td>\n",
" <td> NaN</td>\n", " <td> NaN</td>\n",
" <td> Arsenal</td>\n",
" <td> Midfield</td>\n", " <td> Midfield</td>\n",
" <td> Arsenal</td>\n",
" </tr>\n", " </tr>\n",
" </tbody>\n", " </tbody>\n",
"</table>\n", "</table>\n",
@ -1007,19 +1008,19 @@
], ],
"metadata": {}, "metadata": {},
"output_type": "pyout", "output_type": "pyout",
"prompt_number": 8, "prompt_number": 9,
"text": [ "text": [
" player salary games goals assists shots_on_target \\\n", " player salary games goals assists shots_on_target \\\n",
"4 \u00c1ngel Di Mar\u00eda 15.0 13 3 NaN 13 \n", "4 \u00c1ngel Di Mar\u00eda 15.0 13 3 NaN 13 \n",
"5 Santiago Cazorla 14.8 20 4 NaN 20 \n", "5 Santiago Cazorla 14.8 20 4 NaN 20 \n",
"\n", "\n",
" points_per_game points position team \n", " points_per_game points position team \n",
"4 10.17 132.23 Manchester United Midfield \n", "4 10.17 132.23 Midfield Manchester United \n",
"5 9.97 NaN Arsenal Midfield " "5 9.97 NaN Midfield Arsenal "
] ]
} }
], ],
"prompt_number": 8 "prompt_number": 9
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
@ -1076,8 +1077,8 @@
" <td> 34</td>\n", " <td> 34</td>\n",
" <td> 13.12</td>\n", " <td> 13.12</td>\n",
" <td> 209.98</td>\n", " <td> 209.98</td>\n",
" <td> Manchester City</td>\n",
" <td> Forward</td>\n", " <td> Forward</td>\n",
" <td> Manchester City</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>1</th>\n", " <th>1</th>\n",
@ -1089,8 +1090,8 @@
" <td> 17</td>\n", " <td> 17</td>\n",
" <td> 13.05</td>\n", " <td> 13.05</td>\n",
" <td> 274.04</td>\n", " <td> 274.04</td>\n",
" <td> Chelsea</td>\n",
" <td> Midfield</td>\n", " <td> Midfield</td>\n",
" <td> Chelsea</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>2</th>\n", " <th>2</th>\n",
@ -1102,8 +1103,8 @@
" <td> 29</td>\n", " <td> 29</td>\n",
" <td> 11.19</td>\n", " <td> 11.19</td>\n",
" <td> 223.86</td>\n", " <td> 223.86</td>\n",
" <td> Arsenal</td>\n",
" <td> Forward</td>\n", " <td> Forward</td>\n",
" <td> Arsenal</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>3</th>\n", " <th>3</th>\n",
@ -1115,8 +1116,8 @@
" <td> 19</td>\n", " <td> 19</td>\n",
" <td> 10.99</td>\n", " <td> 10.99</td>\n",
" <td> 197.91</td>\n", " <td> 197.91</td>\n",
" <td> Manchester City</td>\n",
" <td> Midfield</td>\n", " <td> Midfield</td>\n",
" <td> Manchester City</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>6</th>\n", " <th>6</th>\n",
@ -1128,8 +1129,8 @@
" <td> 11</td>\n", " <td> 11</td>\n",
" <td> 10.35</td>\n", " <td> 10.35</td>\n",
" <td> 155.26</td>\n", " <td> 155.26</td>\n",
" <td> Manchester City</td>\n",
" <td> Midfield</td>\n", " <td> Midfield</td>\n",
" <td> Manchester City</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>7</th>\n", " <th>7</th>\n",
@ -1141,8 +1142,8 @@
" <td> 10</td>\n", " <td> 10</td>\n",
" <td> 10.47</td>\n", " <td> 10.47</td>\n",
" <td> 209.49</td>\n", " <td> 209.49</td>\n",
" <td> Chelsea</td>\n",
" <td> Midfield</td>\n", " <td> Midfield</td>\n",
" <td> Chelsea</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>8</th>\n", " <th>8</th>\n",
@ -1154,8 +1155,8 @@
" <td> 20</td>\n", " <td> 20</td>\n",
" <td> 7.02</td>\n", " <td> 7.02</td>\n",
" <td> 147.43</td>\n", " <td> 147.43</td>\n",
" <td> West Brom</td>\n",
" <td> Forward</td>\n", " <td> Forward</td>\n",
" <td> West Brom</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>9</th>\n", " <th>9</th>\n",
@ -1167,8 +1168,8 @@
" <td> 11</td>\n", " <td> 11</td>\n",
" <td> 7.50</td>\n", " <td> 7.50</td>\n",
" <td> 150.01</td>\n", " <td> 150.01</td>\n",
" <td> Liverpool</td>\n",
" <td> Midfield</td>\n", " <td> Midfield</td>\n",
" <td> Liverpool</td>\n",
" </tr>\n", " </tr>\n",
" </tbody>\n", " </tbody>\n",
"</table>\n", "</table>\n",
@ -1176,7 +1177,7 @@
], ],
"metadata": {}, "metadata": {},
"output_type": "pyout", "output_type": "pyout",
"prompt_number": 9, "prompt_number": 10,
"text": [ "text": [
" player salary games goals assists shots_on_target \\\n", " player salary games goals assists shots_on_target \\\n",
"0 Sergio Ag\u00fcero 19.2 16 14 3 34 \n", "0 Sergio Ag\u00fcero 19.2 16 14 3 34 \n",
@ -1189,18 +1190,18 @@
"9 Steven Gerrard 13.8 20 5 1 11 \n", "9 Steven Gerrard 13.8 20 5 1 11 \n",
"\n", "\n",
" points_per_game points position team \n", " points_per_game points position team \n",
"0 13.12 209.98 Manchester City Forward \n", "0 13.12 209.98 Forward Manchester City \n",
"1 13.05 274.04 Chelsea Midfield \n", "1 13.05 274.04 Midfield Chelsea \n",
"2 11.19 223.86 Arsenal Forward \n", "2 11.19 223.86 Forward Arsenal \n",
"3 10.99 197.91 Manchester City Midfield \n", "3 10.99 197.91 Midfield Manchester City \n",
"6 10.35 155.26 Manchester City Midfield \n", "6 10.35 155.26 Midfield Manchester City \n",
"7 10.47 209.49 Chelsea Midfield \n", "7 10.47 209.49 Midfield Chelsea \n",
"8 7.02 147.43 West Brom Forward \n", "8 7.02 147.43 Forward West Brom \n",
"9 7.50 150.01 Liverpool Midfield " "9 7.50 150.01 Midfield Liverpool "
] ]
} }
], ],
"prompt_number": 9 "prompt_number": 10
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
@ -1260,8 +1261,8 @@
" <td> 34</td>\n", " <td> 34</td>\n",
" <td> 13.12</td>\n", " <td> 13.12</td>\n",
" <td> 209.98</td>\n", " <td> 209.98</td>\n",
" <td> Manchester City</td>\n",
" <td> Forward</td>\n", " <td> Forward</td>\n",
" <td> Manchester City</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>1</th>\n", " <th>1</th>\n",
@ -1273,8 +1274,8 @@
" <td> 17</td>\n", " <td> 17</td>\n",
" <td> 13.05</td>\n", " <td> 13.05</td>\n",
" <td> 274.04</td>\n", " <td> 274.04</td>\n",
" <td> Chelsea</td>\n",
" <td> Midfield</td>\n", " <td> Midfield</td>\n",
" <td> Chelsea</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>2</th>\n", " <th>2</th>\n",
@ -1286,8 +1287,8 @@
" <td> 29</td>\n", " <td> 29</td>\n",
" <td> 11.19</td>\n", " <td> 11.19</td>\n",
" <td> 223.86</td>\n", " <td> 223.86</td>\n",
" <td> Arsenal</td>\n",
" <td> Forward</td>\n", " <td> Forward</td>\n",
" <td> Arsenal</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>3</th>\n", " <th>3</th>\n",
@ -1299,8 +1300,8 @@
" <td> 19</td>\n", " <td> 19</td>\n",
" <td> 10.99</td>\n", " <td> 10.99</td>\n",
" <td> 197.91</td>\n", " <td> 197.91</td>\n",
" <td> Manchester City</td>\n",
" <td> Midfield</td>\n", " <td> Midfield</td>\n",
" <td> Manchester City</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>4</th>\n", " <th>4</th>\n",
@ -1312,8 +1313,8 @@
" <td> 13</td>\n", " <td> 13</td>\n",
" <td> 10.17</td>\n", " <td> 10.17</td>\n",
" <td> 132.23</td>\n", " <td> 132.23</td>\n",
" <td> Manchester United</td>\n",
" <td> Midfield</td>\n", " <td> Midfield</td>\n",
" <td> Manchester United</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>5</th>\n", " <th>5</th>\n",
@ -1325,8 +1326,8 @@
" <td> 20</td>\n", " <td> 20</td>\n",
" <td> 9.97</td>\n", " <td> 9.97</td>\n",
" <td> 0.00</td>\n", " <td> 0.00</td>\n",
" <td> Arsenal</td>\n",
" <td> Midfield</td>\n", " <td> Midfield</td>\n",
" <td> Arsenal</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>6</th>\n", " <th>6</th>\n",
@ -1338,8 +1339,8 @@
" <td> 11</td>\n", " <td> 11</td>\n",
" <td> 10.35</td>\n", " <td> 10.35</td>\n",
" <td> 155.26</td>\n", " <td> 155.26</td>\n",
" <td> Manchester City</td>\n",
" <td> Midfield</td>\n", " <td> Midfield</td>\n",
" <td> Manchester City</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>7</th>\n", " <th>7</th>\n",
@ -1351,8 +1352,8 @@
" <td> 10</td>\n", " <td> 10</td>\n",
" <td> 10.47</td>\n", " <td> 10.47</td>\n",
" <td> 209.49</td>\n", " <td> 209.49</td>\n",
" <td> Chelsea</td>\n",
" <td> Midfield</td>\n", " <td> Midfield</td>\n",
" <td> Chelsea</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>8</th>\n", " <th>8</th>\n",
@ -1364,8 +1365,8 @@
" <td> 20</td>\n", " <td> 20</td>\n",
" <td> 7.02</td>\n", " <td> 7.02</td>\n",
" <td> 147.43</td>\n", " <td> 147.43</td>\n",
" <td> West Brom</td>\n",
" <td> Forward</td>\n", " <td> Forward</td>\n",
" <td> West Brom</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>9</th>\n", " <th>9</th>\n",
@ -1377,8 +1378,8 @@
" <td> 11</td>\n", " <td> 11</td>\n",
" <td> 7.50</td>\n", " <td> 7.50</td>\n",
" <td> 150.01</td>\n", " <td> 150.01</td>\n",
" <td> Liverpool</td>\n",
" <td> Midfield</td>\n", " <td> Midfield</td>\n",
" <td> Liverpool</td>\n",
" </tr>\n", " </tr>\n",
" </tbody>\n", " </tbody>\n",
"</table>\n", "</table>\n",
@ -1386,7 +1387,7 @@
], ],
"metadata": {}, "metadata": {},
"output_type": "pyout", "output_type": "pyout",
"prompt_number": 10, "prompt_number": 11,
"text": [ "text": [
" player salary games goals assists shots_on_target \\\n", " player salary games goals assists shots_on_target \\\n",
"0 Sergio Ag\u00fcero 19.2 16 14 3 34 \n", "0 Sergio Ag\u00fcero 19.2 16 14 3 34 \n",
@ -1401,20 +1402,20 @@
"9 Steven Gerrard 13.8 20 5 1 11 \n", "9 Steven Gerrard 13.8 20 5 1 11 \n",
"\n", "\n",
" points_per_game points position team \n", " points_per_game points position team \n",
"0 13.12 209.98 Manchester City Forward \n", "0 13.12 209.98 Forward Manchester City \n",
"1 13.05 274.04 Chelsea Midfield \n", "1 13.05 274.04 Midfield Chelsea \n",
"2 11.19 223.86 Arsenal Forward \n", "2 11.19 223.86 Forward Arsenal \n",
"3 10.99 197.91 Manchester City Midfield \n", "3 10.99 197.91 Midfield Manchester City \n",
"4 10.17 132.23 Manchester United Midfield \n", "4 10.17 132.23 Midfield Manchester United \n",
"5 9.97 0.00 Arsenal Midfield \n", "5 9.97 0.00 Midfield Arsenal \n",
"6 10.35 155.26 Manchester City Midfield \n", "6 10.35 155.26 Midfield Manchester City \n",
"7 10.47 209.49 Chelsea Midfield \n", "7 10.47 209.49 Midfield Chelsea \n",
"8 7.02 147.43 West Brom Forward \n", "8 7.02 147.43 Forward West Brom \n",
"9 7.50 150.01 Liverpool Midfield " "9 7.50 150.01 Midfield Liverpool "
] ]
} }
], ],
"prompt_number": 10 "prompt_number": 11
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
@ -1487,8 +1488,8 @@
" <td> 20</td>\n", " <td> 20</td>\n",
" <td> 7.02</td>\n", " <td> 7.02</td>\n",
" <td> 147.43</td>\n", " <td> 147.43</td>\n",
" <td> West Brom</td>\n",
" <td> Forward</td>\n", " <td> Forward</td>\n",
" <td> West Brom</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>9 </th>\n", " <th>9 </th>\n",
@ -1500,8 +1501,8 @@
" <td> 11</td>\n", " <td> 11</td>\n",
" <td> 7.50</td>\n", " <td> 7.50</td>\n",
" <td> 150.01</td>\n", " <td> 150.01</td>\n",
" <td> Liverpool</td>\n",
" <td> Midfield</td>\n", " <td> Midfield</td>\n",
" <td> Liverpool</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>10</th>\n", " <th>10</th>\n",
@ -1522,7 +1523,7 @@
], ],
"metadata": {}, "metadata": {},
"output_type": "pyout", "output_type": "pyout",
"prompt_number": 11, "prompt_number": 12,
"text": [ "text": [
" 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",
@ -1530,13 +1531,13 @@
"10 NaN NaN NaN NaN NaN NaN \n", "10 NaN NaN 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 West Brom Forward \n", "8 7.02 147.43 Forward West Brom \n",
"9 7.50 150.01 Liverpool Midfield \n", "9 7.50 150.01 Midfield Liverpool \n",
"10 NaN NaN NaN NaN " "10 NaN NaN NaN NaN "
] ]
} }
], ],
"prompt_number": 11 "prompt_number": 12
}, },
{ {
"cell_type": "code", "cell_type": "code",
@ -1581,8 +1582,8 @@
" <td> 20</td>\n", " <td> 20</td>\n",
" <td> 7.02</td>\n", " <td> 7.02</td>\n",
" <td> 147.43</td>\n", " <td> 147.43</td>\n",
" <td> West Brom</td>\n",
" <td> Forward</td>\n", " <td> Forward</td>\n",
" <td> West Brom</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>9 </th>\n", " <th>9 </th>\n",
@ -1594,8 +1595,8 @@
" <td> 11</td>\n", " <td> 11</td>\n",
" <td> 7.50</td>\n", " <td> 7.50</td>\n",
" <td> 150.01</td>\n", " <td> 150.01</td>\n",
" <td> Liverpool</td>\n",
" <td> Midfield</td>\n", " <td> Midfield</td>\n",
" <td> Liverpool</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>10</th>\n", " <th>10</th>\n",
@ -1616,7 +1617,7 @@
], ],
"metadata": {}, "metadata": {},
"output_type": "pyout", "output_type": "pyout",
"prompt_number": 12, "prompt_number": 13,
"text": [ "text": [
" 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",
@ -1624,13 +1625,13 @@
"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 West Brom Forward \n", "8 7.02 147.43 Forward West Brom \n",
"9 7.50 150.01 Liverpool Midfield \n", "9 7.50 150.01 Midfield Liverpool \n",
"10 NaN NaN NaN NaN " "10 NaN NaN NaN NaN "
] ]
} }
], ],
"prompt_number": 12 "prompt_number": 13
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
@ -1697,8 +1698,8 @@
" <td> 34</td>\n", " <td> 34</td>\n",
" <td> 13.12</td>\n", " <td> 13.12</td>\n",
" <td> 209.98</td>\n", " <td> 209.98</td>\n",
" <td> Manchester City</td>\n",
" <td> Forward</td>\n", " <td> Forward</td>\n",
" <td> Manchester City</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>2</th>\n", " <th>2</th>\n",
@ -1710,8 +1711,8 @@
" <td> 29</td>\n", " <td> 29</td>\n",
" <td> 11.19</td>\n", " <td> 11.19</td>\n",
" <td> 223.86</td>\n", " <td> 223.86</td>\n",
" <td> Arsenal</td>\n",
" <td> Forward</td>\n", " <td> Forward</td>\n",
" <td> Arsenal</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>8</th>\n", " <th>8</th>\n",
@ -1723,8 +1724,8 @@
" <td> 20</td>\n", " <td> 20</td>\n",
" <td> 7.02</td>\n", " <td> 7.02</td>\n",
" <td> 147.43</td>\n", " <td> 147.43</td>\n",
" <td> West Brom</td>\n",
" <td> Forward</td>\n", " <td> Forward</td>\n",
" <td> West Brom</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>1</th>\n", " <th>1</th>\n",
@ -1736,8 +1737,8 @@
" <td> 17</td>\n", " <td> 17</td>\n",
" <td> 13.05</td>\n", " <td> 13.05</td>\n",
" <td> 274.04</td>\n", " <td> 274.04</td>\n",
" <td> Chelsea</td>\n",
" <td> Midfield</td>\n", " <td> Midfield</td>\n",
" <td> Chelsea</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>3</th>\n", " <th>3</th>\n",
@ -1749,8 +1750,8 @@
" <td> 19</td>\n", " <td> 19</td>\n",
" <td> 10.99</td>\n", " <td> 10.99</td>\n",
" <td> 197.91</td>\n", " <td> 197.91</td>\n",
" <td> Manchester City</td>\n",
" <td> Midfield</td>\n", " <td> Midfield</td>\n",
" <td> Manchester City</td>\n",
" </tr>\n", " </tr>\n",
" </tbody>\n", " </tbody>\n",
"</table>\n", "</table>\n",
@ -1758,7 +1759,7 @@
], ],
"metadata": {}, "metadata": {},
"output_type": "pyout", "output_type": "pyout",
"prompt_number": 13, "prompt_number": 14,
"text": [ "text": [
" player salary games goals assists shots_on_target \\\n", " player salary games goals assists shots_on_target \\\n",
"0 Sergio Ag\u00fcero 19.2 16 14 3 34 \n", "0 Sergio Ag\u00fcero 19.2 16 14 3 34 \n",
@ -1768,15 +1769,15 @@
"3 Yaya Tour\u00e9 16.6 18 7 1 19 \n", "3 Yaya Tour\u00e9 16.6 18 7 1 19 \n",
"\n", "\n",
" points_per_game points position team \n", " points_per_game points position team \n",
"0 13.12 209.98 Manchester City Forward \n", "0 13.12 209.98 Forward Manchester City \n",
"2 11.19 223.86 Arsenal Forward \n", "2 11.19 223.86 Forward Arsenal \n",
"8 7.02 147.43 West Brom Forward \n", "8 7.02 147.43 Forward West Brom \n",
"1 13.05 274.04 Chelsea Midfield \n", "1 13.05 274.04 Midfield Chelsea \n",
"3 10.99 197.91 Manchester City Midfield " "3 10.99 197.91 Midfield Manchester City "
] ]
} }
], ],
"prompt_number": 13 "prompt_number": 14
}, },
{ {
"cell_type": "code", "cell_type": "code",
@ -1820,8 +1821,8 @@
" <td> 34</td>\n", " <td> 34</td>\n",
" <td> 13.12</td>\n", " <td> 13.12</td>\n",
" <td> 209.98</td>\n", " <td> 209.98</td>\n",
" <td> Manchester City</td>\n",
" <td> Forward</td>\n", " <td> Forward</td>\n",
" <td> Manchester City</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>2</th>\n", " <th>2</th>\n",
@ -1833,8 +1834,8 @@
" <td> 29</td>\n", " <td> 29</td>\n",
" <td> 11.19</td>\n", " <td> 11.19</td>\n",
" <td> 223.86</td>\n", " <td> 223.86</td>\n",
" <td> Arsenal</td>\n",
" <td> Forward</td>\n", " <td> Forward</td>\n",
" <td> Arsenal</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>3</th>\n", " <th>3</th>\n",
@ -1846,8 +1847,8 @@
" <td> 20</td>\n", " <td> 20</td>\n",
" <td> 7.02</td>\n", " <td> 7.02</td>\n",
" <td> 147.43</td>\n", " <td> 147.43</td>\n",
" <td> West Brom</td>\n",
" <td> Forward</td>\n", " <td> Forward</td>\n",
" <td> West Brom</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>4</th>\n", " <th>4</th>\n",
@ -1859,8 +1860,8 @@
" <td> 17</td>\n", " <td> 17</td>\n",
" <td> 13.05</td>\n", " <td> 13.05</td>\n",
" <td> 274.04</td>\n", " <td> 274.04</td>\n",
" <td> Chelsea</td>\n",
" <td> Midfield</td>\n", " <td> Midfield</td>\n",
" <td> Chelsea</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>5</th>\n", " <th>5</th>\n",
@ -1872,8 +1873,8 @@
" <td> 19</td>\n", " <td> 19</td>\n",
" <td> 10.99</td>\n", " <td> 10.99</td>\n",
" <td> 197.91</td>\n", " <td> 197.91</td>\n",
" <td> Manchester City</td>\n",
" <td> Midfield</td>\n", " <td> Midfield</td>\n",
" <td> Manchester City</td>\n",
" </tr>\n", " </tr>\n",
" </tbody>\n", " </tbody>\n",
"</table>\n", "</table>\n",
@ -1881,7 +1882,7 @@
], ],
"metadata": {}, "metadata": {},
"output_type": "pyout", "output_type": "pyout",
"prompt_number": 14, "prompt_number": 15,
"text": [ "text": [
" player salary games goals assists shots_on_target \\\n", " player salary games goals assists shots_on_target \\\n",
"1 Sergio Ag\u00fcero 19.2 16 14 3 34 \n", "1 Sergio Ag\u00fcero 19.2 16 14 3 34 \n",
@ -1891,15 +1892,15 @@
"5 Yaya Tour\u00e9 16.6 18 7 1 19 \n", "5 Yaya Tour\u00e9 16.6 18 7 1 19 \n",
"\n", "\n",
" points_per_game points position team \n", " points_per_game points position team \n",
"1 13.12 209.98 Manchester City Forward \n", "1 13.12 209.98 Forward Manchester City \n",
"2 11.19 223.86 Arsenal Forward \n", "2 11.19 223.86 Forward Arsenal \n",
"3 7.02 147.43 West Brom Forward \n", "3 7.02 147.43 Forward West Brom \n",
"4 13.05 274.04 Chelsea Midfield \n", "4 13.05 274.04 Midfield Chelsea \n",
"5 10.99 197.91 Manchester City Midfield " "5 10.99 197.91 Midfield Manchester City "
] ]
} }
], ],
"prompt_number": 14 "prompt_number": 15
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
@ -1967,8 +1968,8 @@
" <td> 34</td>\n", " <td> 34</td>\n",
" <td> 13.12</td>\n", " <td> 13.12</td>\n",
" <td> 209.98</td>\n", " <td> 209.98</td>\n",
" <td> Manchester City</td>\n",
" <td> Forward</td>\n", " <td> Forward</td>\n",
" <td> Manchester City</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>2</th>\n", " <th>2</th>\n",
@ -1980,8 +1981,8 @@
" <td> 29</td>\n", " <td> 29</td>\n",
" <td> 11.19</td>\n", " <td> 11.19</td>\n",
" <td> 223.86</td>\n", " <td> 223.86</td>\n",
" <td> Arsenal</td>\n",
" <td> Forward</td>\n", " <td> Forward</td>\n",
" <td> Arsenal</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>3</th>\n", " <th>3</th>\n",
@ -1993,8 +1994,8 @@
" <td> 20</td>\n", " <td> 20</td>\n",
" <td> 7.02</td>\n", " <td> 7.02</td>\n",
" <td> 147.43</td>\n", " <td> 147.43</td>\n",
" <td> West Brom</td>\n",
" <td> Forward</td>\n", " <td> Forward</td>\n",
" <td> West Brom</td>\n",
" </tr>\n", " </tr>\n",
" </tbody>\n", " </tbody>\n",
"</table>\n", "</table>\n",
@ -2002,7 +2003,7 @@
], ],
"metadata": {}, "metadata": {},
"output_type": "pyout", "output_type": "pyout",
"prompt_number": 15, "prompt_number": 16,
"text": [ "text": [
" player salary games goals assists shots_on_target \\\n", " player salary games goals assists shots_on_target \\\n",
"1 Sergio Ag\u00fcero 20 16 14 3 34 \n", "1 Sergio Ag\u00fcero 20 16 14 3 34 \n",
@ -2010,13 +2011,13 @@
"3 Saido Berahino 13.8 21 9 0 20 \n", "3 Saido Berahino 13.8 21 9 0 20 \n",
"\n", "\n",
" points_per_game points position team \n", " points_per_game points position team \n",
"1 13.12 209.98 Manchester City Forward \n", "1 13.12 209.98 Forward Manchester City \n",
"2 11.19 223.86 Arsenal Forward \n", "2 11.19 223.86 Forward Arsenal \n",
"3 7.02 147.43 West Brom Forward " "3 7.02 147.43 Forward West Brom "
] ]
} }
], ],
"prompt_number": 15 "prompt_number": 16
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
@ -2080,8 +2081,8 @@
" <td> 34</td>\n", " <td> 34</td>\n",
" <td> 13.12</td>\n", " <td> 13.12</td>\n",
" <td> 209.98</td>\n", " <td> 209.98</td>\n",
" <td> Manchester City</td>\n",
" <td> Forward</td>\n", " <td> Forward</td>\n",
" <td> Manchester City</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>Alexis S\u00e1nchez</th>\n", " <th>Alexis S\u00e1nchez</th>\n",
@ -2092,8 +2093,8 @@
" <td> 29</td>\n", " <td> 29</td>\n",
" <td> 11.19</td>\n", " <td> 11.19</td>\n",
" <td> 223.86</td>\n", " <td> 223.86</td>\n",
" <td> Arsenal</td>\n",
" <td> Forward</td>\n", " <td> Forward</td>\n",
" <td> Arsenal</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>Saido Berahino</th>\n", " <th>Saido Berahino</th>\n",
@ -2104,8 +2105,8 @@
" <td> 20</td>\n", " <td> 20</td>\n",
" <td> 7.02</td>\n", " <td> 7.02</td>\n",
" <td> 147.43</td>\n", " <td> 147.43</td>\n",
" <td> West Brom</td>\n",
" <td> Forward</td>\n", " <td> Forward</td>\n",
" <td> West Brom</td>\n",
" </tr>\n", " </tr>\n",
" </tbody>\n", " </tbody>\n",
"</table>\n", "</table>\n",
@ -2113,7 +2114,7 @@
], ],
"metadata": {}, "metadata": {},
"output_type": "pyout", "output_type": "pyout",
"prompt_number": 16, "prompt_number": 17,
"text": [ "text": [
" salary games goals assists shots_on_target \\\n", " salary games goals assists shots_on_target \\\n",
"player \n", "player \n",
@ -2123,13 +2124,13 @@
"\n", "\n",
" points_per_game points position team \n", " points_per_game points position team \n",
"player \n", "player \n",
"Sergio Ag\u00fcero 13.12 209.98 Manchester City Forward \n", "Sergio Ag\u00fcero 13.12 209.98 Forward Manchester City \n",
"Alexis S\u00e1nchez 11.19 223.86 Arsenal Forward \n", "Alexis S\u00e1nchez 11.19 223.86 Forward Arsenal \n",
"Saido Berahino 7.02 147.43 West Brom Forward " "Saido Berahino 7.02 147.43 Forward West Brom "
] ]
} }
], ],
"prompt_number": 16 "prompt_number": 17
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
@ -2190,8 +2191,8 @@
" <td> 34</td>\n", " <td> 34</td>\n",
" <td> 13.12</td>\n", " <td> 13.12</td>\n",
" <td> 209.98</td>\n", " <td> 209.98</td>\n",
" <td> Manchester City</td>\n",
" <td> Forward</td>\n", " <td> Forward</td>\n",
" <td> Manchester City</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>Alexis S\u00e1nchez</th>\n", " <th>Alexis S\u00e1nchez</th>\n",
@ -2202,8 +2203,8 @@
" <td> 29</td>\n", " <td> 29</td>\n",
" <td> 11.19</td>\n", " <td> 11.19</td>\n",
" <td> 223.86</td>\n", " <td> 223.86</td>\n",
" <td> Arsenal</td>\n",
" <td> Forward</td>\n", " <td> Forward</td>\n",
" <td> Arsenal</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>Saido Berahino</th>\n", " <th>Saido Berahino</th>\n",
@ -2214,8 +2215,8 @@
" <td> 20</td>\n", " <td> 20</td>\n",
" <td> 7.02</td>\n", " <td> 7.02</td>\n",
" <td> 147.43</td>\n", " <td> 147.43</td>\n",
" <td> West Brom</td>\n",
" <td> Forward</td>\n", " <td> Forward</td>\n",
" <td> West Brom</td>\n",
" </tr>\n", " </tr>\n",
" </tbody>\n", " </tbody>\n",
"</table>\n", "</table>\n",
@ -2223,7 +2224,7 @@
], ],
"metadata": {}, "metadata": {},
"output_type": "pyout", "output_type": "pyout",
"prompt_number": 17, "prompt_number": 18,
"text": [ "text": [
" salary games goals assists shots_on_target \\\n", " salary games goals assists shots_on_target \\\n",
"player \n", "player \n",
@ -2233,13 +2234,13 @@
"\n", "\n",
" points_per_game points position team \n", " points_per_game points position team \n",
"player \n", "player \n",
"Sergio Ag\u00fcero 13.12 209.98 Manchester City Forward \n", "Sergio Ag\u00fcero 13.12 209.98 Forward Manchester City \n",
"Alexis S\u00e1nchez 11.19 223.86 Arsenal Forward \n", "Alexis S\u00e1nchez 11.19 223.86 Forward Arsenal \n",
"Saido Berahino 7.02 147.43 West Brom Forward " "Saido Berahino 7.02 147.43 Forward West Brom "
] ]
} }
], ],
"prompt_number": 17 "prompt_number": 18
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
@ -2290,8 +2291,8 @@
" <td> 34</td>\n", " <td> 34</td>\n",
" <td> 13.12</td>\n", " <td> 13.12</td>\n",
" <td> 209.98</td>\n", " <td> 209.98</td>\n",
" <td> Manchester City</td>\n",
" <td> Forward</td>\n", " <td> Forward</td>\n",
" <td> Manchester City</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>1</th>\n", " <th>1</th>\n",
@ -2303,8 +2304,8 @@
" <td> 29</td>\n", " <td> 29</td>\n",
" <td> 11.19</td>\n", " <td> 11.19</td>\n",
" <td> 223.86</td>\n", " <td> 223.86</td>\n",
" <td> Arsenal</td>\n",
" <td> Forward</td>\n", " <td> Forward</td>\n",
" <td> Arsenal</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>2</th>\n", " <th>2</th>\n",
@ -2316,8 +2317,8 @@
" <td> 20</td>\n", " <td> 20</td>\n",
" <td> 7.02</td>\n", " <td> 7.02</td>\n",
" <td> 147.43</td>\n", " <td> 147.43</td>\n",
" <td> West Brom</td>\n",
" <td> Forward</td>\n", " <td> Forward</td>\n",
" <td> West Brom</td>\n",
" </tr>\n", " </tr>\n",
" </tbody>\n", " </tbody>\n",
"</table>\n", "</table>\n",
@ -2325,7 +2326,7 @@
], ],
"metadata": {}, "metadata": {},
"output_type": "pyout", "output_type": "pyout",
"prompt_number": 18, "prompt_number": 19,
"text": [ "text": [
" player salary games goals assists shots_on_target \\\n", " player salary games goals assists shots_on_target \\\n",
"0 Sergio Ag\u00fcero 20 16 14 3 34 \n", "0 Sergio Ag\u00fcero 20 16 14 3 34 \n",
@ -2333,13 +2334,205 @@
"2 Saido Berahino 13.8 21 9 0 20 \n", "2 Saido Berahino 13.8 21 9 0 20 \n",
"\n", "\n",
" points_per_game points position team \n", " points_per_game points position team \n",
"0 13.12 209.98 Manchester City Forward \n", "0 13.12 209.98 Forward Manchester City \n",
"1 11.19 223.86 Arsenal Forward \n", "1 11.19 223.86 Forward Arsenal \n",
"2 7.02 147.43 West Brom Forward " "2 7.02 147.43 Forward West Brom "
] ]
} }
], ],
"prompt_number": 18 "prompt_number": 19
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<br>\n",
"<br>"
]
},
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"Chaining Conditions - Using Bitwise Operators"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[[back to section overview](#Sections)]"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# Selecting only those players that either playing for Arsenal or Chelsea\n",
"\n",
"df[ (df['team'] == 'Arsenal') | (df['team'] == 'Chelsea') ]"
],
"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>position</th>\n",
" <th>team</th>\n",
" </tr>\n",
" </thead>\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",
"</table>\n",
"</div>"
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 20,
"text": [
" player salary games goals assists shots_on_target \\\n",
"1 Alexis S\u00e1nchez 15 0 12 7 29 \n",
"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 "
]
}
],
"prompt_number": 20
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# Selecting forwards from Arsenal only\n",
"\n",
"df[ (df['team'] == 'Arsenal') & (df['position'] == 'Forward') ]"
],
"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>position</th>\n",
" <th>team</th>\n",
" </tr>\n",
" </thead>\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",
"</table>\n",
"</div>"
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 22,
"text": [
" player salary games goals assists shots_on_target \\\n",
"1 Alexis S\u00e1nchez 15 0 12 7 29 \n",
"\n",
" points_per_game points position team \n",
"1 11.19 223.86 Forward Arsenal "
]
}
],
"prompt_number": 22
} }
], ],
"metadata": {} "metadata": {}