Created
September 27, 2020 15:47
-
-
Save Pankajnu/b0e7214b754dd9517997d9188d420b92 to your computer and use it in GitHub Desktop.
Intensive practice of python day1.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "import pandas as pd\nimport numpy as np", | |
"execution_count": 83, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df = pd.read_csv(\"http://rcs.bu.edu/examples/python/data_analysis/Salaries.csv\")", | |
"execution_count": 4, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df", | |
"execution_count": 5, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 5, | |
"data": { | |
"text/plain": " rank discipline phd service sex salary\n0 Prof B 56 49 Male 186960\n1 Prof A 12 6 Male 93000\n2 Prof A 23 20 Male 110515\n3 Prof A 40 31 Male 131205\n4 Prof B 20 18 Male 104800\n.. ... ... ... ... ... ...\n73 Prof B 18 10 Female 105450\n74 AssocProf B 19 6 Female 104542\n75 Prof B 17 17 Female 124312\n76 Prof A 28 14 Female 109954\n77 Prof A 23 15 Female 109646\n\n[78 rows x 6 columns]", | |
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>rank</th>\n <th>discipline</th>\n <th>phd</th>\n <th>service</th>\n <th>sex</th>\n <th>salary</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>Prof</td>\n <td>B</td>\n <td>56</td>\n <td>49</td>\n <td>Male</td>\n <td>186960</td>\n </tr>\n <tr>\n <th>1</th>\n <td>Prof</td>\n <td>A</td>\n <td>12</td>\n <td>6</td>\n <td>Male</td>\n <td>93000</td>\n </tr>\n <tr>\n <th>2</th>\n <td>Prof</td>\n <td>A</td>\n <td>23</td>\n <td>20</td>\n <td>Male</td>\n <td>110515</td>\n </tr>\n <tr>\n <th>3</th>\n <td>Prof</td>\n <td>A</td>\n <td>40</td>\n <td>31</td>\n <td>Male</td>\n <td>131205</td>\n </tr>\n <tr>\n <th>4</th>\n <td>Prof</td>\n <td>B</td>\n <td>20</td>\n <td>18</td>\n <td>Male</td>\n <td>104800</td>\n </tr>\n <tr>\n <th>...</th>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n </tr>\n <tr>\n <th>73</th>\n <td>Prof</td>\n <td>B</td>\n <td>18</td>\n <td>10</td>\n <td>Female</td>\n <td>105450</td>\n </tr>\n <tr>\n <th>74</th>\n <td>AssocProf</td>\n <td>B</td>\n <td>19</td>\n <td>6</td>\n <td>Female</td>\n <td>104542</td>\n </tr>\n <tr>\n <th>75</th>\n <td>Prof</td>\n <td>B</td>\n <td>17</td>\n <td>17</td>\n <td>Female</td>\n <td>124312</td>\n </tr>\n <tr>\n <th>76</th>\n <td>Prof</td>\n <td>A</td>\n <td>28</td>\n <td>14</td>\n <td>Female</td>\n <td>109954</td>\n </tr>\n <tr>\n <th>77</th>\n <td>Prof</td>\n <td>A</td>\n <td>23</td>\n <td>15</td>\n <td>Female</td>\n <td>109646</td>\n </tr>\n </tbody>\n</table>\n<p>78 rows × 6 columns</p>\n</div>" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df.head(7)", | |
"execution_count": 6, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 6, | |
"data": { | |
"text/plain": " rank discipline phd service sex salary\n0 Prof B 56 49 Male 186960\n1 Prof A 12 6 Male 93000\n2 Prof A 23 20 Male 110515\n3 Prof A 40 31 Male 131205\n4 Prof B 20 18 Male 104800\n5 Prof A 20 20 Male 122400\n6 AssocProf A 20 17 Male 81285", | |
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>rank</th>\n <th>discipline</th>\n <th>phd</th>\n <th>service</th>\n <th>sex</th>\n <th>salary</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>Prof</td>\n <td>B</td>\n <td>56</td>\n <td>49</td>\n <td>Male</td>\n <td>186960</td>\n </tr>\n <tr>\n <th>1</th>\n <td>Prof</td>\n <td>A</td>\n <td>12</td>\n <td>6</td>\n <td>Male</td>\n <td>93000</td>\n </tr>\n <tr>\n <th>2</th>\n <td>Prof</td>\n <td>A</td>\n <td>23</td>\n <td>20</td>\n <td>Male</td>\n <td>110515</td>\n </tr>\n <tr>\n <th>3</th>\n <td>Prof</td>\n <td>A</td>\n <td>40</td>\n <td>31</td>\n <td>Male</td>\n <td>131205</td>\n </tr>\n <tr>\n <th>4</th>\n <td>Prof</td>\n <td>B</td>\n <td>20</td>\n <td>18</td>\n <td>Male</td>\n <td>104800</td>\n </tr>\n <tr>\n <th>5</th>\n <td>Prof</td>\n <td>A</td>\n <td>20</td>\n <td>20</td>\n <td>Male</td>\n <td>122400</td>\n </tr>\n <tr>\n <th>6</th>\n <td>AssocProf</td>\n <td>A</td>\n <td>20</td>\n <td>17</td>\n <td>Male</td>\n <td>81285</td>\n </tr>\n </tbody>\n</table>\n</div>" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df.head(10)", | |
"execution_count": 7, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 7, | |
"data": { | |
"text/plain": " rank discipline phd service sex salary\n0 Prof B 56 49 Male 186960\n1 Prof A 12 6 Male 93000\n2 Prof A 23 20 Male 110515\n3 Prof A 40 31 Male 131205\n4 Prof B 20 18 Male 104800\n5 Prof A 20 20 Male 122400\n6 AssocProf A 20 17 Male 81285\n7 Prof A 18 18 Male 126300\n8 Prof A 29 19 Male 94350\n9 Prof A 51 51 Male 57800", | |
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>rank</th>\n <th>discipline</th>\n <th>phd</th>\n <th>service</th>\n <th>sex</th>\n <th>salary</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>Prof</td>\n <td>B</td>\n <td>56</td>\n <td>49</td>\n <td>Male</td>\n <td>186960</td>\n </tr>\n <tr>\n <th>1</th>\n <td>Prof</td>\n <td>A</td>\n <td>12</td>\n <td>6</td>\n <td>Male</td>\n <td>93000</td>\n </tr>\n <tr>\n <th>2</th>\n <td>Prof</td>\n <td>A</td>\n <td>23</td>\n <td>20</td>\n <td>Male</td>\n <td>110515</td>\n </tr>\n <tr>\n <th>3</th>\n <td>Prof</td>\n <td>A</td>\n <td>40</td>\n <td>31</td>\n <td>Male</td>\n <td>131205</td>\n </tr>\n <tr>\n <th>4</th>\n <td>Prof</td>\n <td>B</td>\n <td>20</td>\n <td>18</td>\n <td>Male</td>\n <td>104800</td>\n </tr>\n <tr>\n <th>5</th>\n <td>Prof</td>\n <td>A</td>\n <td>20</td>\n <td>20</td>\n <td>Male</td>\n <td>122400</td>\n </tr>\n <tr>\n <th>6</th>\n <td>AssocProf</td>\n <td>A</td>\n <td>20</td>\n <td>17</td>\n <td>Male</td>\n <td>81285</td>\n </tr>\n <tr>\n <th>7</th>\n <td>Prof</td>\n <td>A</td>\n <td>18</td>\n <td>18</td>\n <td>Male</td>\n <td>126300</td>\n </tr>\n <tr>\n <th>8</th>\n <td>Prof</td>\n <td>A</td>\n <td>29</td>\n <td>19</td>\n <td>Male</td>\n <td>94350</td>\n </tr>\n <tr>\n <th>9</th>\n <td>Prof</td>\n <td>A</td>\n <td>51</td>\n <td>51</td>\n <td>Male</td>\n <td>57800</td>\n </tr>\n </tbody>\n</table>\n</div>" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df.head(20)", | |
"execution_count": 8, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 8, | |
"data": { | |
"text/plain": " rank discipline phd service sex salary\n0 Prof B 56 49 Male 186960\n1 Prof A 12 6 Male 93000\n2 Prof A 23 20 Male 110515\n3 Prof A 40 31 Male 131205\n4 Prof B 20 18 Male 104800\n5 Prof A 20 20 Male 122400\n6 AssocProf A 20 17 Male 81285\n7 Prof A 18 18 Male 126300\n8 Prof A 29 19 Male 94350\n9 Prof A 51 51 Male 57800\n10 Prof B 39 33 Male 128250\n11 Prof B 23 23 Male 134778\n12 AsstProf B 1 0 Male 88000\n13 Prof B 35 33 Male 162200\n14 Prof B 25 19 Male 153750\n15 Prof B 17 3 Male 150480\n16 AsstProf B 8 3 Male 75044\n17 AsstProf B 4 0 Male 92000\n18 Prof A 19 7 Male 107300\n19 Prof A 29 27 Male 150500", | |
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>rank</th>\n <th>discipline</th>\n <th>phd</th>\n <th>service</th>\n <th>sex</th>\n <th>salary</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>Prof</td>\n <td>B</td>\n <td>56</td>\n <td>49</td>\n <td>Male</td>\n <td>186960</td>\n </tr>\n <tr>\n <th>1</th>\n <td>Prof</td>\n <td>A</td>\n <td>12</td>\n <td>6</td>\n <td>Male</td>\n <td>93000</td>\n </tr>\n <tr>\n <th>2</th>\n <td>Prof</td>\n <td>A</td>\n <td>23</td>\n <td>20</td>\n <td>Male</td>\n <td>110515</td>\n </tr>\n <tr>\n <th>3</th>\n <td>Prof</td>\n <td>A</td>\n <td>40</td>\n <td>31</td>\n <td>Male</td>\n <td>131205</td>\n </tr>\n <tr>\n <th>4</th>\n <td>Prof</td>\n <td>B</td>\n <td>20</td>\n <td>18</td>\n <td>Male</td>\n <td>104800</td>\n </tr>\n <tr>\n <th>5</th>\n <td>Prof</td>\n <td>A</td>\n <td>20</td>\n <td>20</td>\n <td>Male</td>\n <td>122400</td>\n </tr>\n <tr>\n <th>6</th>\n <td>AssocProf</td>\n <td>A</td>\n <td>20</td>\n <td>17</td>\n <td>Male</td>\n <td>81285</td>\n </tr>\n <tr>\n <th>7</th>\n <td>Prof</td>\n <td>A</td>\n <td>18</td>\n <td>18</td>\n <td>Male</td>\n <td>126300</td>\n </tr>\n <tr>\n <th>8</th>\n <td>Prof</td>\n <td>A</td>\n <td>29</td>\n <td>19</td>\n <td>Male</td>\n <td>94350</td>\n </tr>\n <tr>\n <th>9</th>\n <td>Prof</td>\n <td>A</td>\n <td>51</td>\n <td>51</td>\n <td>Male</td>\n <td>57800</td>\n </tr>\n <tr>\n <th>10</th>\n <td>Prof</td>\n <td>B</td>\n <td>39</td>\n <td>33</td>\n <td>Male</td>\n <td>128250</td>\n </tr>\n <tr>\n <th>11</th>\n <td>Prof</td>\n <td>B</td>\n <td>23</td>\n <td>23</td>\n <td>Male</td>\n <td>134778</td>\n </tr>\n <tr>\n <th>12</th>\n <td>AsstProf</td>\n <td>B</td>\n <td>1</td>\n <td>0</td>\n <td>Male</td>\n <td>88000</td>\n </tr>\n <tr>\n <th>13</th>\n <td>Prof</td>\n <td>B</td>\n <td>35</td>\n <td>33</td>\n <td>Male</td>\n <td>162200</td>\n </tr>\n <tr>\n <th>14</th>\n <td>Prof</td>\n <td>B</td>\n <td>25</td>\n <td>19</td>\n <td>Male</td>\n <td>153750</td>\n </tr>\n <tr>\n <th>15</th>\n <td>Prof</td>\n <td>B</td>\n <td>17</td>\n <td>3</td>\n <td>Male</td>\n <td>150480</td>\n </tr>\n <tr>\n <th>16</th>\n <td>AsstProf</td>\n <td>B</td>\n <td>8</td>\n <td>3</td>\n <td>Male</td>\n <td>75044</td>\n </tr>\n <tr>\n <th>17</th>\n <td>AsstProf</td>\n <td>B</td>\n <td>4</td>\n <td>0</td>\n <td>Male</td>\n <td>92000</td>\n </tr>\n <tr>\n <th>18</th>\n <td>Prof</td>\n <td>A</td>\n <td>19</td>\n <td>7</td>\n <td>Male</td>\n <td>107300</td>\n </tr>\n <tr>\n <th>19</th>\n <td>Prof</td>\n <td>A</td>\n <td>29</td>\n <td>27</td>\n <td>Male</td>\n <td>150500</td>\n </tr>\n </tbody>\n</table>\n</div>" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df.head(50)", | |
"execution_count": 9, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 9, | |
"data": { | |
"text/plain": " rank discipline phd service sex salary\n0 Prof B 56 49 Male 186960\n1 Prof A 12 6 Male 93000\n2 Prof A 23 20 Male 110515\n3 Prof A 40 31 Male 131205\n4 Prof B 20 18 Male 104800\n5 Prof A 20 20 Male 122400\n6 AssocProf A 20 17 Male 81285\n7 Prof A 18 18 Male 126300\n8 Prof A 29 19 Male 94350\n9 Prof A 51 51 Male 57800\n10 Prof B 39 33 Male 128250\n11 Prof B 23 23 Male 134778\n12 AsstProf B 1 0 Male 88000\n13 Prof B 35 33 Male 162200\n14 Prof B 25 19 Male 153750\n15 Prof B 17 3 Male 150480\n16 AsstProf B 8 3 Male 75044\n17 AsstProf B 4 0 Male 92000\n18 Prof A 19 7 Male 107300\n19 Prof A 29 27 Male 150500\n20 AsstProf B 4 4 Male 92000\n21 Prof A 33 30 Male 103106\n22 AsstProf A 4 2 Male 73000\n23 AsstProf A 2 0 Male 85000\n24 Prof A 30 23 Male 91100\n25 Prof B 35 31 Male 99418\n26 Prof A 38 19 Male 148750\n27 Prof A 45 43 Male 155865\n28 AsstProf B 7 2 Male 91300\n29 Prof B 21 20 Male 123683\n30 AssocProf B 9 7 Male 107008\n31 Prof B 22 21 Male 155750\n32 Prof A 27 19 Male 103275\n33 Prof B 18 18 Male 120000\n34 AssocProf B 12 8 Male 119800\n35 Prof B 28 23 Male 126933\n36 Prof B 45 45 Male 146856\n37 Prof A 20 8 Male 102000\n38 AsstProf B 4 3 Male 91000\n39 Prof B 18 18 Female 129000\n40 Prof A 39 36 Female 137000\n41 AssocProf A 13 8 Female 74830\n42 AsstProf B 4 2 Female 80225\n43 AsstProf B 5 0 Female 77000\n44 Prof B 23 19 Female 151768\n45 Prof B 25 25 Female 140096\n46 AsstProf B 11 3 Female 74692\n47 AssocProf B 11 11 Female 103613\n48 Prof B 17 17 Female 111512\n49 Prof B 17 18 Female 122960", | |
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>rank</th>\n <th>discipline</th>\n <th>phd</th>\n <th>service</th>\n <th>sex</th>\n <th>salary</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>Prof</td>\n <td>B</td>\n <td>56</td>\n <td>49</td>\n <td>Male</td>\n <td>186960</td>\n </tr>\n <tr>\n <th>1</th>\n <td>Prof</td>\n <td>A</td>\n <td>12</td>\n <td>6</td>\n <td>Male</td>\n <td>93000</td>\n </tr>\n <tr>\n <th>2</th>\n <td>Prof</td>\n <td>A</td>\n <td>23</td>\n <td>20</td>\n <td>Male</td>\n <td>110515</td>\n </tr>\n <tr>\n <th>3</th>\n <td>Prof</td>\n <td>A</td>\n <td>40</td>\n <td>31</td>\n <td>Male</td>\n <td>131205</td>\n </tr>\n <tr>\n <th>4</th>\n <td>Prof</td>\n <td>B</td>\n <td>20</td>\n <td>18</td>\n <td>Male</td>\n <td>104800</td>\n </tr>\n <tr>\n <th>5</th>\n <td>Prof</td>\n <td>A</td>\n <td>20</td>\n <td>20</td>\n <td>Male</td>\n <td>122400</td>\n </tr>\n <tr>\n <th>6</th>\n <td>AssocProf</td>\n <td>A</td>\n <td>20</td>\n <td>17</td>\n <td>Male</td>\n <td>81285</td>\n </tr>\n <tr>\n <th>7</th>\n <td>Prof</td>\n <td>A</td>\n <td>18</td>\n <td>18</td>\n <td>Male</td>\n <td>126300</td>\n </tr>\n <tr>\n <th>8</th>\n <td>Prof</td>\n <td>A</td>\n <td>29</td>\n <td>19</td>\n <td>Male</td>\n <td>94350</td>\n </tr>\n <tr>\n <th>9</th>\n <td>Prof</td>\n <td>A</td>\n <td>51</td>\n <td>51</td>\n <td>Male</td>\n <td>57800</td>\n </tr>\n <tr>\n <th>10</th>\n <td>Prof</td>\n <td>B</td>\n <td>39</td>\n <td>33</td>\n <td>Male</td>\n <td>128250</td>\n </tr>\n <tr>\n <th>11</th>\n <td>Prof</td>\n <td>B</td>\n <td>23</td>\n <td>23</td>\n <td>Male</td>\n <td>134778</td>\n </tr>\n <tr>\n <th>12</th>\n <td>AsstProf</td>\n <td>B</td>\n <td>1</td>\n <td>0</td>\n <td>Male</td>\n <td>88000</td>\n </tr>\n <tr>\n <th>13</th>\n <td>Prof</td>\n <td>B</td>\n <td>35</td>\n <td>33</td>\n <td>Male</td>\n <td>162200</td>\n </tr>\n <tr>\n <th>14</th>\n <td>Prof</td>\n <td>B</td>\n <td>25</td>\n <td>19</td>\n <td>Male</td>\n <td>153750</td>\n </tr>\n <tr>\n <th>15</th>\n <td>Prof</td>\n <td>B</td>\n <td>17</td>\n <td>3</td>\n <td>Male</td>\n <td>150480</td>\n </tr>\n <tr>\n <th>16</th>\n <td>AsstProf</td>\n <td>B</td>\n <td>8</td>\n <td>3</td>\n <td>Male</td>\n <td>75044</td>\n </tr>\n <tr>\n <th>17</th>\n <td>AsstProf</td>\n <td>B</td>\n <td>4</td>\n <td>0</td>\n <td>Male</td>\n <td>92000</td>\n </tr>\n <tr>\n <th>18</th>\n <td>Prof</td>\n <td>A</td>\n <td>19</td>\n <td>7</td>\n <td>Male</td>\n <td>107300</td>\n </tr>\n <tr>\n <th>19</th>\n <td>Prof</td>\n <td>A</td>\n <td>29</td>\n <td>27</td>\n <td>Male</td>\n <td>150500</td>\n </tr>\n <tr>\n <th>20</th>\n <td>AsstProf</td>\n <td>B</td>\n <td>4</td>\n <td>4</td>\n <td>Male</td>\n <td>92000</td>\n </tr>\n <tr>\n <th>21</th>\n <td>Prof</td>\n <td>A</td>\n <td>33</td>\n <td>30</td>\n <td>Male</td>\n <td>103106</td>\n </tr>\n <tr>\n <th>22</th>\n <td>AsstProf</td>\n <td>A</td>\n <td>4</td>\n <td>2</td>\n <td>Male</td>\n <td>73000</td>\n </tr>\n <tr>\n <th>23</th>\n <td>AsstProf</td>\n <td>A</td>\n <td>2</td>\n <td>0</td>\n <td>Male</td>\n <td>85000</td>\n </tr>\n <tr>\n <th>24</th>\n <td>Prof</td>\n <td>A</td>\n <td>30</td>\n <td>23</td>\n <td>Male</td>\n <td>91100</td>\n </tr>\n <tr>\n <th>25</th>\n <td>Prof</td>\n <td>B</td>\n <td>35</td>\n <td>31</td>\n <td>Male</td>\n <td>99418</td>\n </tr>\n <tr>\n <th>26</th>\n <td>Prof</td>\n <td>A</td>\n <td>38</td>\n <td>19</td>\n <td>Male</td>\n <td>148750</td>\n </tr>\n <tr>\n <th>27</th>\n <td>Prof</td>\n <td>A</td>\n <td>45</td>\n <td>43</td>\n <td>Male</td>\n <td>155865</td>\n </tr>\n <tr>\n <th>28</th>\n <td>AsstProf</td>\n <td>B</td>\n <td>7</td>\n <td>2</td>\n <td>Male</td>\n <td>91300</td>\n </tr>\n <tr>\n <th>29</th>\n <td>Prof</td>\n <td>B</td>\n <td>21</td>\n <td>20</td>\n <td>Male</td>\n <td>123683</td>\n </tr>\n <tr>\n <th>30</th>\n <td>AssocProf</td>\n <td>B</td>\n <td>9</td>\n <td>7</td>\n <td>Male</td>\n <td>107008</td>\n </tr>\n <tr>\n <th>31</th>\n <td>Prof</td>\n <td>B</td>\n <td>22</td>\n <td>21</td>\n <td>Male</td>\n <td>155750</td>\n </tr>\n <tr>\n <th>32</th>\n <td>Prof</td>\n <td>A</td>\n <td>27</td>\n <td>19</td>\n <td>Male</td>\n <td>103275</td>\n </tr>\n <tr>\n <th>33</th>\n <td>Prof</td>\n <td>B</td>\n <td>18</td>\n <td>18</td>\n <td>Male</td>\n <td>120000</td>\n </tr>\n <tr>\n <th>34</th>\n <td>AssocProf</td>\n <td>B</td>\n <td>12</td>\n <td>8</td>\n <td>Male</td>\n <td>119800</td>\n </tr>\n <tr>\n <th>35</th>\n <td>Prof</td>\n <td>B</td>\n <td>28</td>\n <td>23</td>\n <td>Male</td>\n <td>126933</td>\n </tr>\n <tr>\n <th>36</th>\n <td>Prof</td>\n <td>B</td>\n <td>45</td>\n <td>45</td>\n <td>Male</td>\n <td>146856</td>\n </tr>\n <tr>\n <th>37</th>\n <td>Prof</td>\n <td>A</td>\n <td>20</td>\n <td>8</td>\n <td>Male</td>\n <td>102000</td>\n </tr>\n <tr>\n <th>38</th>\n <td>AsstProf</td>\n <td>B</td>\n <td>4</td>\n <td>3</td>\n <td>Male</td>\n <td>91000</td>\n </tr>\n <tr>\n <th>39</th>\n <td>Prof</td>\n <td>B</td>\n <td>18</td>\n <td>18</td>\n <td>Female</td>\n <td>129000</td>\n </tr>\n <tr>\n <th>40</th>\n <td>Prof</td>\n <td>A</td>\n <td>39</td>\n <td>36</td>\n <td>Female</td>\n <td>137000</td>\n </tr>\n <tr>\n <th>41</th>\n <td>AssocProf</td>\n <td>A</td>\n <td>13</td>\n <td>8</td>\n <td>Female</td>\n <td>74830</td>\n </tr>\n <tr>\n <th>42</th>\n <td>AsstProf</td>\n <td>B</td>\n <td>4</td>\n <td>2</td>\n <td>Female</td>\n <td>80225</td>\n </tr>\n <tr>\n <th>43</th>\n <td>AsstProf</td>\n <td>B</td>\n <td>5</td>\n <td>0</td>\n <td>Female</td>\n <td>77000</td>\n </tr>\n <tr>\n <th>44</th>\n <td>Prof</td>\n <td>B</td>\n <td>23</td>\n <td>19</td>\n <td>Female</td>\n <td>151768</td>\n </tr>\n <tr>\n <th>45</th>\n <td>Prof</td>\n <td>B</td>\n <td>25</td>\n <td>25</td>\n <td>Female</td>\n <td>140096</td>\n </tr>\n <tr>\n <th>46</th>\n <td>AsstProf</td>\n <td>B</td>\n <td>11</td>\n <td>3</td>\n <td>Female</td>\n <td>74692</td>\n </tr>\n <tr>\n <th>47</th>\n <td>AssocProf</td>\n <td>B</td>\n <td>11</td>\n <td>11</td>\n <td>Female</td>\n <td>103613</td>\n </tr>\n <tr>\n <th>48</th>\n <td>Prof</td>\n <td>B</td>\n <td>17</td>\n <td>17</td>\n <td>Female</td>\n <td>111512</td>\n </tr>\n <tr>\n <th>49</th>\n <td>Prof</td>\n <td>B</td>\n <td>17</td>\n <td>18</td>\n <td>Female</td>\n <td>122960</td>\n </tr>\n </tbody>\n</table>\n</div>" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true, | |
"collapsed": true | |
}, | |
"cell_type": "code", | |
"source": "df.dtypes", | |
"execution_count": 10, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 10, | |
"data": { | |
"text/plain": "rank object\ndiscipline object\nphd int64\nservice int64\nsex object\nsalary int64\ndtype: object" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df.columns", | |
"execution_count": 11, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 11, | |
"data": { | |
"text/plain": "Index(['rank', 'discipline', 'phd', 'service', 'sex', 'salary'], dtype='object')" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df.axes", | |
"execution_count": 12, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 12, | |
"data": { | |
"text/plain": "[RangeIndex(start=0, stop=78, step=1),\n Index(['rank', 'discipline', 'phd', 'service', 'sex', 'salary'], dtype='object')]" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df.ndim", | |
"execution_count": 13, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 13, | |
"data": { | |
"text/plain": "2" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df.size", | |
"execution_count": 14, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 14, | |
"data": { | |
"text/plain": "468" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df.shape", | |
"execution_count": 15, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 15, | |
"data": { | |
"text/plain": "(78, 6)" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df.values\n", | |
"execution_count": 16, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 16, | |
"data": { | |
"text/plain": "array([['Prof', 'B', 56, 49, 'Male', 186960],\n ['Prof', 'A', 12, 6, 'Male', 93000],\n ['Prof', 'A', 23, 20, 'Male', 110515],\n ['Prof', 'A', 40, 31, 'Male', 131205],\n ['Prof', 'B', 20, 18, 'Male', 104800],\n ['Prof', 'A', 20, 20, 'Male', 122400],\n ['AssocProf', 'A', 20, 17, 'Male', 81285],\n ['Prof', 'A', 18, 18, 'Male', 126300],\n ['Prof', 'A', 29, 19, 'Male', 94350],\n ['Prof', 'A', 51, 51, 'Male', 57800],\n ['Prof', 'B', 39, 33, 'Male', 128250],\n ['Prof', 'B', 23, 23, 'Male', 134778],\n ['AsstProf', 'B', 1, 0, 'Male', 88000],\n ['Prof', 'B', 35, 33, 'Male', 162200],\n ['Prof', 'B', 25, 19, 'Male', 153750],\n ['Prof', 'B', 17, 3, 'Male', 150480],\n ['AsstProf', 'B', 8, 3, 'Male', 75044],\n ['AsstProf', 'B', 4, 0, 'Male', 92000],\n ['Prof', 'A', 19, 7, 'Male', 107300],\n ['Prof', 'A', 29, 27, 'Male', 150500],\n ['AsstProf', 'B', 4, 4, 'Male', 92000],\n ['Prof', 'A', 33, 30, 'Male', 103106],\n ['AsstProf', 'A', 4, 2, 'Male', 73000],\n ['AsstProf', 'A', 2, 0, 'Male', 85000],\n ['Prof', 'A', 30, 23, 'Male', 91100],\n ['Prof', 'B', 35, 31, 'Male', 99418],\n ['Prof', 'A', 38, 19, 'Male', 148750],\n ['Prof', 'A', 45, 43, 'Male', 155865],\n ['AsstProf', 'B', 7, 2, 'Male', 91300],\n ['Prof', 'B', 21, 20, 'Male', 123683],\n ['AssocProf', 'B', 9, 7, 'Male', 107008],\n ['Prof', 'B', 22, 21, 'Male', 155750],\n ['Prof', 'A', 27, 19, 'Male', 103275],\n ['Prof', 'B', 18, 18, 'Male', 120000],\n ['AssocProf', 'B', 12, 8, 'Male', 119800],\n ['Prof', 'B', 28, 23, 'Male', 126933],\n ['Prof', 'B', 45, 45, 'Male', 146856],\n ['Prof', 'A', 20, 8, 'Male', 102000],\n ['AsstProf', 'B', 4, 3, 'Male', 91000],\n ['Prof', 'B', 18, 18, 'Female', 129000],\n ['Prof', 'A', 39, 36, 'Female', 137000],\n ['AssocProf', 'A', 13, 8, 'Female', 74830],\n ['AsstProf', 'B', 4, 2, 'Female', 80225],\n ['AsstProf', 'B', 5, 0, 'Female', 77000],\n ['Prof', 'B', 23, 19, 'Female', 151768],\n ['Prof', 'B', 25, 25, 'Female', 140096],\n ['AsstProf', 'B', 11, 3, 'Female', 74692],\n ['AssocProf', 'B', 11, 11, 'Female', 103613],\n ['Prof', 'B', 17, 17, 'Female', 111512],\n ['Prof', 'B', 17, 18, 'Female', 122960],\n ['AsstProf', 'B', 10, 5, 'Female', 97032],\n ['Prof', 'B', 20, 14, 'Female', 127512],\n ['Prof', 'A', 12, 0, 'Female', 105000],\n ['AsstProf', 'A', 5, 3, 'Female', 73500],\n ['AssocProf', 'A', 25, 22, 'Female', 62884],\n ['AsstProf', 'A', 2, 0, 'Female', 72500],\n ['AssocProf', 'A', 10, 8, 'Female', 77500],\n ['AsstProf', 'A', 3, 1, 'Female', 72500],\n ['Prof', 'B', 36, 26, 'Female', 144651],\n ['AssocProf', 'B', 12, 10, 'Female', 103994],\n ['AsstProf', 'B', 3, 3, 'Female', 92000],\n ['AssocProf', 'B', 13, 10, 'Female', 103750],\n ['AssocProf', 'B', 14, 7, 'Female', 109650],\n ['Prof', 'A', 29, 27, 'Female', 91000],\n ['AssocProf', 'A', 26, 24, 'Female', 73300],\n ['Prof', 'A', 36, 19, 'Female', 117555],\n ['AsstProf', 'A', 7, 6, 'Female', 63100],\n ['Prof', 'A', 17, 11, 'Female', 90450],\n ['AsstProf', 'A', 4, 2, 'Female', 77500],\n ['Prof', 'A', 28, 7, 'Female', 116450],\n ['AsstProf', 'A', 8, 3, 'Female', 78500],\n ['AssocProf', 'B', 12, 9, 'Female', 71065],\n ['Prof', 'B', 24, 15, 'Female', 161101],\n ['Prof', 'B', 18, 10, 'Female', 105450],\n ['AssocProf', 'B', 19, 6, 'Female', 104542],\n ['Prof', 'B', 17, 17, 'Female', 124312],\n ['Prof', 'A', 28, 14, 'Female', 109954],\n ['Prof', 'A', 23, 15, 'Female', 109646]], dtype=object)" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df.dtypes", | |
"execution_count": 19, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 19, | |
"data": { | |
"text/plain": "rank object\ndiscipline object\nphd int64\nservice int64\nsex object\nsalary int64\ndtype: object" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df.size", | |
"execution_count": 20, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 20, | |
"data": { | |
"text/plain": "468" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df.columns", | |
"execution_count": 21, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 21, | |
"data": { | |
"text/plain": "Index(['rank', 'discipline', 'phd', 'service', 'sex', 'salary'], dtype='object')" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df.shape", | |
"execution_count": 22, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 22, | |
"data": { | |
"text/plain": "(78, 6)" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df.dtypes", | |
"execution_count": 23, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 23, | |
"data": { | |
"text/plain": "rank object\ndiscipline object\nphd int64\nservice int64\nsex object\nsalary int64\ndtype: object" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df", | |
"execution_count": 24, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 24, | |
"data": { | |
"text/plain": " rank discipline phd service sex salary\n0 Prof B 56 49 Male 186960\n1 Prof A 12 6 Male 93000\n2 Prof A 23 20 Male 110515\n3 Prof A 40 31 Male 131205\n4 Prof B 20 18 Male 104800\n.. ... ... ... ... ... ...\n73 Prof B 18 10 Female 105450\n74 AssocProf B 19 6 Female 104542\n75 Prof B 17 17 Female 124312\n76 Prof A 28 14 Female 109954\n77 Prof A 23 15 Female 109646\n\n[78 rows x 6 columns]", | |
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>rank</th>\n <th>discipline</th>\n <th>phd</th>\n <th>service</th>\n <th>sex</th>\n <th>salary</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>Prof</td>\n <td>B</td>\n <td>56</td>\n <td>49</td>\n <td>Male</td>\n <td>186960</td>\n </tr>\n <tr>\n <th>1</th>\n <td>Prof</td>\n <td>A</td>\n <td>12</td>\n <td>6</td>\n <td>Male</td>\n <td>93000</td>\n </tr>\n <tr>\n <th>2</th>\n <td>Prof</td>\n <td>A</td>\n <td>23</td>\n <td>20</td>\n <td>Male</td>\n <td>110515</td>\n </tr>\n <tr>\n <th>3</th>\n <td>Prof</td>\n <td>A</td>\n <td>40</td>\n <td>31</td>\n <td>Male</td>\n <td>131205</td>\n </tr>\n <tr>\n <th>4</th>\n <td>Prof</td>\n <td>B</td>\n <td>20</td>\n <td>18</td>\n <td>Male</td>\n <td>104800</td>\n </tr>\n <tr>\n <th>...</th>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n </tr>\n <tr>\n <th>73</th>\n <td>Prof</td>\n <td>B</td>\n <td>18</td>\n <td>10</td>\n <td>Female</td>\n <td>105450</td>\n </tr>\n <tr>\n <th>74</th>\n <td>AssocProf</td>\n <td>B</td>\n <td>19</td>\n <td>6</td>\n <td>Female</td>\n <td>104542</td>\n </tr>\n <tr>\n <th>75</th>\n <td>Prof</td>\n <td>B</td>\n <td>17</td>\n <td>17</td>\n <td>Female</td>\n <td>124312</td>\n </tr>\n <tr>\n <th>76</th>\n <td>Prof</td>\n <td>A</td>\n <td>28</td>\n <td>14</td>\n <td>Female</td>\n <td>109954</td>\n </tr>\n <tr>\n <th>77</th>\n <td>Prof</td>\n <td>A</td>\n <td>23</td>\n <td>15</td>\n <td>Female</td>\n <td>109646</td>\n </tr>\n </tbody>\n</table>\n<p>78 rows × 6 columns</p>\n</div>" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "print(df)", | |
"execution_count": 26, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": " rank discipline phd service sex salary\n0 Prof B 56 49 Male 186960\n1 Prof A 12 6 Male 93000\n2 Prof A 23 20 Male 110515\n3 Prof A 40 31 Male 131205\n4 Prof B 20 18 Male 104800\n.. ... ... ... ... ... ...\n73 Prof B 18 10 Female 105450\n74 AssocProf B 19 6 Female 104542\n75 Prof B 17 17 Female 124312\n76 Prof A 28 14 Female 109954\n77 Prof A 23 15 Female 109646\n\n[78 rows x 6 columns]\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "print(df(2,3))", | |
"execution_count": 29, | |
"outputs": [ | |
{ | |
"output_type": "error", | |
"ename": "TypeError", | |
"evalue": "'DataFrame' object is not callable", | |
"traceback": [ | |
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", | |
"\u001b[1;32m<ipython-input-29-8a3728dbc01a>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdf\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m3\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", | |
"\u001b[1;31mTypeError\u001b[0m: 'DataFrame' object is not callable" | |
] | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df.describe()", | |
"execution_count": 40, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 40, | |
"data": { | |
"text/plain": " phd service salary\ncount 78.000000 78.000000 78.000000\nmean 19.705128 15.051282 108023.782051\nstd 12.498425 12.139768 28293.661022\nmin 1.000000 0.000000 57800.000000\n25% 10.250000 5.250000 88612.500000\n50% 18.500000 14.500000 104671.000000\n75% 27.750000 20.750000 126774.750000\nmax 56.000000 51.000000 186960.000000", | |
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>phd</th>\n <th>service</th>\n <th>salary</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>count</th>\n <td>78.000000</td>\n <td>78.000000</td>\n <td>78.000000</td>\n </tr>\n <tr>\n <th>mean</th>\n <td>19.705128</td>\n <td>15.051282</td>\n <td>108023.782051</td>\n </tr>\n <tr>\n <th>std</th>\n <td>12.498425</td>\n <td>12.139768</td>\n <td>28293.661022</td>\n </tr>\n <tr>\n <th>min</th>\n <td>1.000000</td>\n <td>0.000000</td>\n <td>57800.000000</td>\n </tr>\n <tr>\n <th>25%</th>\n <td>10.250000</td>\n <td>5.250000</td>\n <td>88612.500000</td>\n </tr>\n <tr>\n <th>50%</th>\n <td>18.500000</td>\n <td>14.500000</td>\n <td>104671.000000</td>\n </tr>\n <tr>\n <th>75%</th>\n <td>27.750000</td>\n <td>20.750000</td>\n <td>126774.750000</td>\n </tr>\n <tr>\n <th>max</th>\n <td>56.000000</td>\n <td>51.000000</td>\n <td>186960.000000</td>\n </tr>\n </tbody>\n</table>\n</div>" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df.max()", | |
"execution_count": 41, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 41, | |
"data": { | |
"text/plain": "rank Prof\ndiscipline B\nphd 56\nservice 51\nsex Male\nsalary 186960\ndtype: object" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df['salary'].max()", | |
"execution_count": 46, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 46, | |
"data": { | |
"text/plain": "186960" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df.min()", | |
"execution_count": 47, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 47, | |
"data": { | |
"text/plain": "rank AssocProf\ndiscipline A\nphd 1\nservice 0\nsex Female\nsalary 57800\ndtype: object" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df['salary'].min()", | |
"execution_count": 48, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 48, | |
"data": { | |
"text/plain": "57800" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df.mean()", | |
"execution_count": 49, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 49, | |
"data": { | |
"text/plain": "phd 19.705128\nservice 15.051282\nsalary 108023.782051\ndtype: float64" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df['salary'].mean()", | |
"execution_count": 50, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 50, | |
"data": { | |
"text/plain": "108023.78205128205" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df.head(10).mean()", | |
"execution_count": 52, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 52, | |
"data": { | |
"text/plain": "phd 28.9\nservice 24.9\nsalary 110861.5\ndtype: float64" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df.head(10).mean", | |
"execution_count": 53, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 53, | |
"data": { | |
"text/plain": "<bound method DataFrame.mean of rank discipline phd service sex salary\n0 Prof B 56 49 Male 186960\n1 Prof A 12 6 Male 93000\n2 Prof A 23 20 Male 110515\n3 Prof A 40 31 Male 131205\n4 Prof B 20 18 Male 104800\n5 Prof A 20 20 Male 122400\n6 AssocProf A 20 17 Male 81285\n7 Prof A 18 18 Male 126300\n8 Prof A 29 19 Male 94350\n9 Prof A 51 51 Male 57800>" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df.head(10).mean()", | |
"execution_count": 54, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 54, | |
"data": { | |
"text/plain": "phd 28.9\nservice 24.9\nsalary 110861.5\ndtype: float64" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df.salary", | |
"execution_count": 55, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 55, | |
"data": { | |
"text/plain": "0 186960\n1 93000\n2 110515\n3 131205\n4 104800\n ... \n73 105450\n74 104542\n75 124312\n76 109954\n77 109646\nName: salary, Length: 78, dtype: int64" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df['salary']", | |
"execution_count": 56, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 56, | |
"data": { | |
"text/plain": "0 186960\n1 93000\n2 110515\n3 131205\n4 104800\n ... \n73 105450\n74 104542\n75 124312\n76 109954\n77 109646\nName: salary, Length: 78, dtype: int64" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df[['salary']]", | |
"execution_count": 59, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 59, | |
"data": { | |
"text/plain": " salary\n0 186960\n1 93000\n2 110515\n3 131205\n4 104800\n.. ...\n73 105450\n74 104542\n75 124312\n76 109954\n77 109646\n\n[78 rows x 1 columns]", | |
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>salary</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>186960</td>\n </tr>\n <tr>\n <th>1</th>\n <td>93000</td>\n </tr>\n <tr>\n <th>2</th>\n <td>110515</td>\n </tr>\n <tr>\n <th>3</th>\n <td>131205</td>\n </tr>\n <tr>\n <th>4</th>\n <td>104800</td>\n </tr>\n <tr>\n <th>...</th>\n <td>...</td>\n </tr>\n <tr>\n <th>73</th>\n <td>105450</td>\n </tr>\n <tr>\n <th>74</th>\n <td>104542</td>\n </tr>\n <tr>\n <th>75</th>\n <td>124312</td>\n </tr>\n <tr>\n <th>76</th>\n <td>109954</td>\n </tr>\n <tr>\n <th>77</th>\n <td>109646</td>\n </tr>\n </tbody>\n</table>\n<p>78 rows × 1 columns</p>\n</div>" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df.groupby (['rank']).mean()", | |
"execution_count": 60, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 60, | |
"data": { | |
"text/plain": " phd service salary\nrank \nAssocProf 15.076923 11.307692 91786.230769\nAsstProf 5.052632 2.210526 81362.789474\nProf 27.065217 21.413043 123624.804348", | |
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>phd</th>\n <th>service</th>\n <th>salary</th>\n </tr>\n <tr>\n <th>rank</th>\n <th></th>\n <th></th>\n <th></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>AssocProf</th>\n <td>15.076923</td>\n <td>11.307692</td>\n <td>91786.230769</td>\n </tr>\n <tr>\n <th>AsstProf</th>\n <td>5.052632</td>\n <td>2.210526</td>\n <td>81362.789474</td>\n </tr>\n <tr>\n <th>Prof</th>\n <td>27.065217</td>\n <td>21.413043</td>\n <td>123624.804348</td>\n </tr>\n </tbody>\n</table>\n</div>" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df.salary", | |
"execution_count": 61, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 61, | |
"data": { | |
"text/plain": "0 186960\n1 93000\n2 110515\n3 131205\n4 104800\n ... \n73 105450\n74 104542\n75 124312\n76 109954\n77 109646\nName: salary, Length: 78, dtype: int64" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df['rank'],['salary']", | |
"execution_count": 71, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 71, | |
"data": { | |
"text/plain": "(0 Prof\n 1 Prof\n 2 Prof\n 3 Prof\n 4 Prof\n ... \n 73 Prof\n 74 AssocProf\n 75 Prof\n 76 Prof\n 77 Prof\n Name: rank, Length: 78, dtype: object,\n ['salary'])" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df", | |
"execution_count": 72, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 72, | |
"data": { | |
"text/plain": " rank discipline phd service sex salary\n0 Prof B 56 49 Male 186960\n1 Prof A 12 6 Male 93000\n2 Prof A 23 20 Male 110515\n3 Prof A 40 31 Male 131205\n4 Prof B 20 18 Male 104800\n.. ... ... ... ... ... ...\n73 Prof B 18 10 Female 105450\n74 AssocProf B 19 6 Female 104542\n75 Prof B 17 17 Female 124312\n76 Prof A 28 14 Female 109954\n77 Prof A 23 15 Female 109646\n\n[78 rows x 6 columns]", | |
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>rank</th>\n <th>discipline</th>\n <th>phd</th>\n <th>service</th>\n <th>sex</th>\n <th>salary</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>Prof</td>\n <td>B</td>\n <td>56</td>\n <td>49</td>\n <td>Male</td>\n <td>186960</td>\n </tr>\n <tr>\n <th>1</th>\n <td>Prof</td>\n <td>A</td>\n <td>12</td>\n <td>6</td>\n <td>Male</td>\n <td>93000</td>\n </tr>\n <tr>\n <th>2</th>\n <td>Prof</td>\n <td>A</td>\n <td>23</td>\n <td>20</td>\n <td>Male</td>\n <td>110515</td>\n </tr>\n <tr>\n <th>3</th>\n <td>Prof</td>\n <td>A</td>\n <td>40</td>\n <td>31</td>\n <td>Male</td>\n <td>131205</td>\n </tr>\n <tr>\n <th>4</th>\n <td>Prof</td>\n <td>B</td>\n <td>20</td>\n <td>18</td>\n <td>Male</td>\n <td>104800</td>\n </tr>\n <tr>\n <th>...</th>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n </tr>\n <tr>\n <th>73</th>\n <td>Prof</td>\n <td>B</td>\n <td>18</td>\n <td>10</td>\n <td>Female</td>\n <td>105450</td>\n </tr>\n <tr>\n <th>74</th>\n <td>AssocProf</td>\n <td>B</td>\n <td>19</td>\n <td>6</td>\n <td>Female</td>\n <td>104542</td>\n </tr>\n <tr>\n <th>75</th>\n <td>Prof</td>\n <td>B</td>\n <td>17</td>\n <td>17</td>\n <td>Female</td>\n <td>124312</td>\n </tr>\n <tr>\n <th>76</th>\n <td>Prof</td>\n <td>A</td>\n <td>28</td>\n <td>14</td>\n <td>Female</td>\n <td>109954</td>\n </tr>\n <tr>\n <th>77</th>\n <td>Prof</td>\n <td>A</td>\n <td>23</td>\n <td>15</td>\n <td>Female</td>\n <td>109646</td>\n </tr>\n </tbody>\n</table>\n<p>78 rows × 6 columns</p>\n</div>" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df[['rank','salary']]", | |
"execution_count": 84, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 84, | |
"data": { | |
"text/plain": " rank salary\n0 Prof 186960\n1 Prof 93000\n2 Prof 110515\n3 Prof 131205\n4 Prof 104800\n.. ... ...\n73 Prof 105450\n74 AssocProf 104542\n75 Prof 124312\n76 Prof 109954\n77 Prof 109646\n\n[78 rows x 2 columns]", | |
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>rank</th>\n <th>salary</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>Prof</td>\n <td>186960</td>\n </tr>\n <tr>\n <th>1</th>\n <td>Prof</td>\n <td>93000</td>\n </tr>\n <tr>\n <th>2</th>\n <td>Prof</td>\n <td>110515</td>\n </tr>\n <tr>\n <th>3</th>\n <td>Prof</td>\n <td>131205</td>\n </tr>\n <tr>\n <th>4</th>\n <td>Prof</td>\n <td>104800</td>\n </tr>\n <tr>\n <th>...</th>\n <td>...</td>\n <td>...</td>\n </tr>\n <tr>\n <th>73</th>\n <td>Prof</td>\n <td>105450</td>\n </tr>\n <tr>\n <th>74</th>\n <td>AssocProf</td>\n <td>104542</td>\n </tr>\n <tr>\n <th>75</th>\n <td>Prof</td>\n <td>124312</td>\n </tr>\n <tr>\n <th>76</th>\n <td>Prof</td>\n <td>109954</td>\n </tr>\n <tr>\n <th>77</th>\n <td>Prof</td>\n <td>109646</td>\n </tr>\n </tbody>\n</table>\n<p>78 rows × 2 columns</p>\n</div>" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true, | |
"collapsed": true | |
}, | |
"cell_type": "code", | |
"source": "df[['rank','salary','service']]", | |
"execution_count": 86, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 86, | |
"data": { | |
"text/plain": " rank salary service\n0 Prof 186960 49\n1 Prof 93000 6\n2 Prof 110515 20\n3 Prof 131205 31\n4 Prof 104800 18\n.. ... ... ...\n73 Prof 105450 10\n74 AssocProf 104542 6\n75 Prof 124312 17\n76 Prof 109954 14\n77 Prof 109646 15\n\n[78 rows x 3 columns]", | |
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>rank</th>\n <th>salary</th>\n <th>service</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>Prof</td>\n <td>186960</td>\n <td>49</td>\n </tr>\n <tr>\n <th>1</th>\n <td>Prof</td>\n <td>93000</td>\n <td>6</td>\n </tr>\n <tr>\n <th>2</th>\n <td>Prof</td>\n <td>110515</td>\n <td>20</td>\n </tr>\n <tr>\n <th>3</th>\n <td>Prof</td>\n <td>131205</td>\n <td>31</td>\n </tr>\n <tr>\n <th>4</th>\n <td>Prof</td>\n <td>104800</td>\n <td>18</td>\n </tr>\n <tr>\n <th>...</th>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n </tr>\n <tr>\n <th>73</th>\n <td>Prof</td>\n <td>105450</td>\n <td>10</td>\n </tr>\n <tr>\n <th>74</th>\n <td>AssocProf</td>\n <td>104542</td>\n <td>6</td>\n </tr>\n <tr>\n <th>75</th>\n <td>Prof</td>\n <td>124312</td>\n <td>17</td>\n </tr>\n <tr>\n <th>76</th>\n <td>Prof</td>\n <td>109954</td>\n <td>14</td>\n </tr>\n <tr>\n <th>77</th>\n <td>Prof</td>\n <td>109646</td>\n <td>15</td>\n </tr>\n </tbody>\n</table>\n<p>78 rows × 3 columns</p>\n</div>" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df [2,[5:15]]", | |
"execution_count": 98, | |
"outputs": [ | |
{ | |
"output_type": "error", | |
"ename": "SyntaxError", | |
"evalue": "invalid syntax (<ipython-input-98-38e8e7041b35>, line 1)", | |
"traceback": [ | |
"\u001b[1;36m File \u001b[1;32m\"<ipython-input-98-38e8e7041b35>\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m df [2,[5:15]]\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" | |
] | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df.iloc[4,5]", | |
"execution_count": 104, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 104, | |
"data": { | |
"text/plain": "104800" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df.loc[[0,1,4],['rank','salary']]", | |
"execution_count": 116, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 116, | |
"data": { | |
"text/plain": " rank salary\n0 Prof 186960\n1 Prof 93000\n4 Prof 104800", | |
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>rank</th>\n <th>salary</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>Prof</td>\n <td>186960</td>\n </tr>\n <tr>\n <th>1</th>\n <td>Prof</td>\n <td>93000</td>\n </tr>\n <tr>\n <th>4</th>\n <td>Prof</td>\n <td>104800</td>\n </tr>\n </tbody>\n</table>\n</div>" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true, | |
"collapsed": true | |
}, | |
"cell_type": "code", | |
"source": "df.loc[[0,1,2,3,4,5,10,20,30],['rank','salary']]", | |
"execution_count": 118, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 118, | |
"data": { | |
"text/plain": " rank salary\n0 Prof 186960\n1 Prof 93000\n2 Prof 110515\n3 Prof 131205\n4 Prof 104800\n5 Prof 122400\n10 Prof 128250\n20 AsstProf 92000\n30 AssocProf 107008", | |
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>rank</th>\n <th>salary</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>Prof</td>\n <td>186960</td>\n </tr>\n <tr>\n <th>1</th>\n <td>Prof</td>\n <td>93000</td>\n </tr>\n <tr>\n <th>2</th>\n <td>Prof</td>\n <td>110515</td>\n </tr>\n <tr>\n <th>3</th>\n <td>Prof</td>\n <td>131205</td>\n </tr>\n <tr>\n <th>4</th>\n <td>Prof</td>\n <td>104800</td>\n </tr>\n <tr>\n <th>5</th>\n <td>Prof</td>\n <td>122400</td>\n </tr>\n <tr>\n <th>10</th>\n <td>Prof</td>\n <td>128250</td>\n </tr>\n <tr>\n <th>20</th>\n <td>AsstProf</td>\n <td>92000</td>\n </tr>\n <tr>\n <th>30</th>\n <td>AssocProf</td>\n <td>107008</td>\n </tr>\n </tbody>\n</table>\n</div>" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df.groupby(['rank']).mean()", | |
"execution_count": 122, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 122, | |
"data": { | |
"text/plain": " phd service salary\nrank \nAssocProf 15.076923 11.307692 91786.230769\nAsstProf 5.052632 2.210526 81362.789474\nProf 27.065217 21.413043 123624.804348", | |
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>phd</th>\n <th>service</th>\n <th>salary</th>\n </tr>\n <tr>\n <th>rank</th>\n <th></th>\n <th></th>\n <th></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>AssocProf</th>\n <td>15.076923</td>\n <td>11.307692</td>\n <td>91786.230769</td>\n </tr>\n <tr>\n <th>AsstProf</th>\n <td>5.052632</td>\n <td>2.210526</td>\n <td>81362.789474</td>\n </tr>\n <tr>\n <th>Prof</th>\n <td>27.065217</td>\n <td>21.413043</td>\n <td>123624.804348</td>\n </tr>\n </tbody>\n</table>\n</div>" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df.groupby('sex')[['salary','phd']].max()", | |
"execution_count": 125, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 125, | |
"data": { | |
"text/plain": " salary phd\nsex \nFemale 161101 39\nMale 186960 56", | |
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>salary</th>\n <th>phd</th>\n </tr>\n <tr>\n <th>sex</th>\n <th></th>\n <th></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>Female</th>\n <td>161101</td>\n <td>39</td>\n </tr>\n <tr>\n <th>Male</th>\n <td>186960</td>\n <td>56</td>\n </tr>\n </tbody>\n</table>\n</div>" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df.groupby('sex')[['salary','phd']].min()", | |
"execution_count": 127, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 127, | |
"data": { | |
"text/plain": " salary phd\nsex \nFemale 62884 2\nMale 57800 1", | |
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>salary</th>\n <th>phd</th>\n </tr>\n <tr>\n <th>sex</th>\n <th></th>\n <th></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>Female</th>\n <td>62884</td>\n <td>2</td>\n </tr>\n <tr>\n <th>Male</th>\n <td>57800</td>\n <td>1</td>\n </tr>\n </tbody>\n</table>\n</div>" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df_sub=df[df['salary']>120000]", | |
"execution_count": 128, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df_sub", | |
"execution_count": 131, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 131, | |
"data": { | |
"text/plain": " rank discipline phd service sex salary\n0 Prof B 56 49 Male 186960\n3 Prof A 40 31 Male 131205\n5 Prof A 20 20 Male 122400\n7 Prof A 18 18 Male 126300\n10 Prof B 39 33 Male 128250\n11 Prof B 23 23 Male 134778\n13 Prof B 35 33 Male 162200\n14 Prof B 25 19 Male 153750\n15 Prof B 17 3 Male 150480\n19 Prof A 29 27 Male 150500\n26 Prof A 38 19 Male 148750\n27 Prof A 45 43 Male 155865\n29 Prof B 21 20 Male 123683\n31 Prof B 22 21 Male 155750\n35 Prof B 28 23 Male 126933\n36 Prof B 45 45 Male 146856\n39 Prof B 18 18 Female 129000\n40 Prof A 39 36 Female 137000\n44 Prof B 23 19 Female 151768\n45 Prof B 25 25 Female 140096\n49 Prof B 17 18 Female 122960\n51 Prof B 20 14 Female 127512\n58 Prof B 36 26 Female 144651\n72 Prof B 24 15 Female 161101\n75 Prof B 17 17 Female 124312", | |
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>rank</th>\n <th>discipline</th>\n <th>phd</th>\n <th>service</th>\n <th>sex</th>\n <th>salary</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>Prof</td>\n <td>B</td>\n <td>56</td>\n <td>49</td>\n <td>Male</td>\n <td>186960</td>\n </tr>\n <tr>\n <th>3</th>\n <td>Prof</td>\n <td>A</td>\n <td>40</td>\n <td>31</td>\n <td>Male</td>\n <td>131205</td>\n </tr>\n <tr>\n <th>5</th>\n <td>Prof</td>\n <td>A</td>\n <td>20</td>\n <td>20</td>\n <td>Male</td>\n <td>122400</td>\n </tr>\n <tr>\n <th>7</th>\n <td>Prof</td>\n <td>A</td>\n <td>18</td>\n <td>18</td>\n <td>Male</td>\n <td>126300</td>\n </tr>\n <tr>\n <th>10</th>\n <td>Prof</td>\n <td>B</td>\n <td>39</td>\n <td>33</td>\n <td>Male</td>\n <td>128250</td>\n </tr>\n <tr>\n <th>11</th>\n <td>Prof</td>\n <td>B</td>\n <td>23</td>\n <td>23</td>\n <td>Male</td>\n <td>134778</td>\n </tr>\n <tr>\n <th>13</th>\n <td>Prof</td>\n <td>B</td>\n <td>35</td>\n <td>33</td>\n <td>Male</td>\n <td>162200</td>\n </tr>\n <tr>\n <th>14</th>\n <td>Prof</td>\n <td>B</td>\n <td>25</td>\n <td>19</td>\n <td>Male</td>\n <td>153750</td>\n </tr>\n <tr>\n <th>15</th>\n <td>Prof</td>\n <td>B</td>\n <td>17</td>\n <td>3</td>\n <td>Male</td>\n <td>150480</td>\n </tr>\n <tr>\n <th>19</th>\n <td>Prof</td>\n <td>A</td>\n <td>29</td>\n <td>27</td>\n <td>Male</td>\n <td>150500</td>\n </tr>\n <tr>\n <th>26</th>\n <td>Prof</td>\n <td>A</td>\n <td>38</td>\n <td>19</td>\n <td>Male</td>\n <td>148750</td>\n </tr>\n <tr>\n <th>27</th>\n <td>Prof</td>\n <td>A</td>\n <td>45</td>\n <td>43</td>\n <td>Male</td>\n <td>155865</td>\n </tr>\n <tr>\n <th>29</th>\n <td>Prof</td>\n <td>B</td>\n <td>21</td>\n <td>20</td>\n <td>Male</td>\n <td>123683</td>\n </tr>\n <tr>\n <th>31</th>\n <td>Prof</td>\n <td>B</td>\n <td>22</td>\n <td>21</td>\n <td>Male</td>\n <td>155750</td>\n </tr>\n <tr>\n <th>35</th>\n <td>Prof</td>\n <td>B</td>\n <td>28</td>\n <td>23</td>\n <td>Male</td>\n <td>126933</td>\n </tr>\n <tr>\n <th>36</th>\n <td>Prof</td>\n <td>B</td>\n <td>45</td>\n <td>45</td>\n <td>Male</td>\n <td>146856</td>\n </tr>\n <tr>\n <th>39</th>\n <td>Prof</td>\n <td>B</td>\n <td>18</td>\n <td>18</td>\n <td>Female</td>\n <td>129000</td>\n </tr>\n <tr>\n <th>40</th>\n <td>Prof</td>\n <td>A</td>\n <td>39</td>\n <td>36</td>\n <td>Female</td>\n <td>137000</td>\n </tr>\n <tr>\n <th>44</th>\n <td>Prof</td>\n <td>B</td>\n <td>23</td>\n <td>19</td>\n <td>Female</td>\n <td>151768</td>\n </tr>\n <tr>\n <th>45</th>\n <td>Prof</td>\n <td>B</td>\n <td>25</td>\n <td>25</td>\n <td>Female</td>\n <td>140096</td>\n </tr>\n <tr>\n <th>49</th>\n <td>Prof</td>\n <td>B</td>\n <td>17</td>\n <td>18</td>\n <td>Female</td>\n <td>122960</td>\n </tr>\n <tr>\n <th>51</th>\n <td>Prof</td>\n <td>B</td>\n <td>20</td>\n <td>14</td>\n <td>Female</td>\n <td>127512</td>\n </tr>\n <tr>\n <th>58</th>\n <td>Prof</td>\n <td>B</td>\n <td>36</td>\n <td>26</td>\n <td>Female</td>\n <td>144651</td>\n </tr>\n <tr>\n <th>72</th>\n <td>Prof</td>\n <td>B</td>\n <td>24</td>\n <td>15</td>\n <td>Female</td>\n <td>161101</td>\n </tr>\n <tr>\n <th>75</th>\n <td>Prof</td>\n <td>B</td>\n <td>17</td>\n <td>17</td>\n <td>Female</td>\n <td>124312</td>\n </tr>\n </tbody>\n</table>\n</div>" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df_f=df[df['sex']== 'female']", | |
"execution_count": 132, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df_f", | |
"execution_count": 133, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 133, | |
"data": { | |
"text/plain": "Empty DataFrame\nColumns: [rank, discipline, phd, service, sex, salary]\nIndex: []", | |
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>rank</th>\n <th>discipline</th>\n <th>phd</th>\n <th>service</th>\n <th>sex</th>\n <th>salary</th>\n </tr>\n </thead>\n <tbody>\n </tbody>\n</table>\n</div>" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df.iloc[:,-1]", | |
"execution_count": 136, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 136, | |
"data": { | |
"text/plain": "0 186960\n1 93000\n2 110515\n3 131205\n4 104800\n ... \n73 105450\n74 104542\n75 124312\n76 109954\n77 109646\nName: salary, Length: 78, dtype: int64" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df.iloc[2:8,0:4]", | |
"execution_count": 139, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 139, | |
"data": { | |
"text/plain": " rank discipline phd service\n2 Prof A 23 20\n3 Prof A 40 31\n4 Prof B 20 18\n5 Prof A 20 20\n6 AssocProf A 20 17\n7 Prof A 18 18", | |
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>rank</th>\n <th>discipline</th>\n <th>phd</th>\n <th>service</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>2</th>\n <td>Prof</td>\n <td>A</td>\n <td>23</td>\n <td>20</td>\n </tr>\n <tr>\n <th>3</th>\n <td>Prof</td>\n <td>A</td>\n <td>40</td>\n <td>31</td>\n </tr>\n <tr>\n <th>4</th>\n <td>Prof</td>\n <td>B</td>\n <td>20</td>\n <td>18</td>\n </tr>\n <tr>\n <th>5</th>\n <td>Prof</td>\n <td>A</td>\n <td>20</td>\n <td>20</td>\n </tr>\n <tr>\n <th>6</th>\n <td>AssocProf</td>\n <td>A</td>\n <td>20</td>\n <td>17</td>\n </tr>\n <tr>\n <th>7</th>\n <td>Prof</td>\n <td>A</td>\n <td>18</td>\n <td>18</td>\n </tr>\n </tbody>\n</table>\n</div>" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df.iloc[0:2,1:3]", | |
"execution_count": 144, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 144, | |
"data": { | |
"text/plain": " discipline phd\n0 B 56\n1 A 12", | |
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>discipline</th>\n <th>phd</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>B</td>\n <td>56</td>\n </tr>\n <tr>\n <th>1</th>\n <td>A</td>\n <td>12</td>\n </tr>\n </tbody>\n</table>\n</div>" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "df.iloc[[0,5],:]", | |
"execution_count": 146, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 146, | |
"data": { | |
"text/plain": " rank discipline phd service sex salary\n0 Prof B 56 49 Male 186960\n5 Prof A 20 20 Male 122400", | |
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>rank</th>\n <th>discipline</th>\n <th>phd</th>\n <th>service</th>\n <th>sex</th>\n <th>salary</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>Prof</td>\n <td>B</td>\n <td>56</td>\n <td>49</td>\n <td>Male</td>\n <td>186960</td>\n </tr>\n <tr>\n <th>5</th>\n <td>Prof</td>\n <td>A</td>\n <td>20</td>\n <td>20</td>\n <td>Male</td>\n <td>122400</td>\n </tr>\n </tbody>\n</table>\n</div>" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "", | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "", | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "", | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "", | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "", | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "", | |
"execution_count": null, | |
"outputs": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3", | |
"language": "python" | |
}, | |
"language_info": { | |
"name": "python", | |
"version": "3.8.3", | |
"mimetype": "text/x-python", | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"pygments_lexer": "ipython3", | |
"nbconvert_exporter": "python", | |
"file_extension": ".py" | |
}, | |
"gist": { | |
"id": "", | |
"data": { | |
"description": "Intensive practice of python day1.ipynb", | |
"public": true | |
} | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment