You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

6449 lines
204 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"___\n",
"\n",
"<a href='http://www.pieriandata.com'><img src='../Pierian_Data_Logo.png'/></a>\n",
"___\n",
"<center><em>Copyright by Pierian Data Inc.</em></center>\n",
"<center><em>For more information, visit us at <a href='http://www.pieriandata.com'>www.pieriandata.com</a></em></center>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# DataFrames\n",
"\n",
"Throughout the course, most of our data exploration will be done with DataFrames. DataFrames are an extremely powerful tool and a natural extension of the Pandas Series. By definition all a DataFrame is:\n",
"\n",
"**A Pandas DataFrame consists of multiple Pandas Series that share index values.**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Imports"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Creating a DataFrame from Python Objects"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# help(pd.DataFrame)"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [],
"source": [
"# Make sure the seed is in the same cell as the random call\n",
"# https://stackoverflow.com/questions/21494489/what-does-numpy-random-seed0-do\n",
"np.random.seed(101)\n",
"mydata = np.random.randint(0,101,(4,3))"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[95, 11, 81],\n",
" [70, 63, 87],\n",
" [75, 9, 77],\n",
" [40, 4, 63]])"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mydata"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
"myindex = ['CA','NY','AZ','TX']"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [],
"source": [
"mycolumns = ['Jan','Feb','Mar']"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [
{
"data": {
"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>0</th>\n",
" <th>1</th>\n",
" <th>2</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>95</td>\n",
" <td>11</td>\n",
" <td>81</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>70</td>\n",
" <td>63</td>\n",
" <td>87</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>75</td>\n",
" <td>9</td>\n",
" <td>77</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>40</td>\n",
" <td>4</td>\n",
" <td>63</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" 0 1 2\n",
"0 95 11 81\n",
"1 70 63 87\n",
"2 75 9 77\n",
"3 40 4 63"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = pd.DataFrame(data=mydata)\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [
{
"data": {
"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>0</th>\n",
" <th>1</th>\n",
" <th>2</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>CA</th>\n",
" <td>95</td>\n",
" <td>11</td>\n",
" <td>81</td>\n",
" </tr>\n",
" <tr>\n",
" <th>NY</th>\n",
" <td>70</td>\n",
" <td>63</td>\n",
" <td>87</td>\n",
" </tr>\n",
" <tr>\n",
" <th>AZ</th>\n",
" <td>75</td>\n",
" <td>9</td>\n",
" <td>77</td>\n",
" </tr>\n",
" <tr>\n",
" <th>TX</th>\n",
" <td>40</td>\n",
" <td>4</td>\n",
" <td>63</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" 0 1 2\n",
"CA 95 11 81\n",
"NY 70 63 87\n",
"AZ 75 9 77\n",
"TX 40 4 63"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = pd.DataFrame(data=mydata,index=myindex)\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [
{
"data": {
"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>Jan</th>\n",
" <th>Feb</th>\n",
" <th>Mar</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>CA</th>\n",
" <td>95</td>\n",
" <td>11</td>\n",
" <td>81</td>\n",
" </tr>\n",
" <tr>\n",
" <th>NY</th>\n",
" <td>70</td>\n",
" <td>63</td>\n",
" <td>87</td>\n",
" </tr>\n",
" <tr>\n",
" <th>AZ</th>\n",
" <td>75</td>\n",
" <td>9</td>\n",
" <td>77</td>\n",
" </tr>\n",
" <tr>\n",
" <th>TX</th>\n",
" <td>40</td>\n",
" <td>4</td>\n",
" <td>63</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Jan Feb Mar\n",
"CA 95 11 81\n",
"NY 70 63 87\n",
"AZ 75 9 77\n",
"TX 40 4 63"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = pd.DataFrame(data=mydata,index=myindex,columns=mycolumns)\n",
"df "
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'pandas.core.frame.DataFrame'>\n",
"Index: 4 entries, CA to TX\n",
"Data columns (total 3 columns):\n",
"Jan 4 non-null int32\n",
"Feb 4 non-null int32\n",
"Mar 4 non-null int32\n",
"dtypes: int32(3)\n",
"memory usage: 80.0+ bytes\n"
]
}
],
"source": [
"df.info()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"# Reading a .csv file for a DataFrame\n",
"\n",
"----\n",
"\n",
"## NOTE: We will go over all kinds of data inputs and outputs (.html, .csv, .xlxs , etc...) later on in the course! For now we just need to read in a simple .csv file.\n",
"\n",
"----"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## CSV\n",
"Comma Separated Values files are text files that use commas as field delimeters.<br>\n",
"Unless you're running the virtual environment included with the course, you may need to install <tt>xlrd</tt> and <tt>openpyxl</tt>.<br>\n",
"In your terminal/command prompt run:\n",
"\n",
" conda install xlrd\n",
" conda install openpyxl\n",
"\n",
"Then restart Jupyter Notebook.\n",
"(or use pip install if you aren't using the Anaconda Distribution)\n",
"\n",
"### Understanding File Paths\n",
"\n",
"You have two options when reading a file with pandas:\n",
"\n",
"1. If your .py file or .ipynb notebook is located in the **exact** same folder location as the .csv file you want to read, simply pass in the file name as a string, for example:\n",
" \n",
" df = pd.read_csv('some_file.csv')\n",
" \n",
"2. Pass in the entire file path if you are located in a different directory. The file path must be 100% correct in order for this to work. For example:\n",
"\n",
" df = pd.read_csv(\"C:\\\\Users\\\\myself\\\\files\\\\some_file.csv\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Print your current directory file path with pwd"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'C:\\\\Users\\\\Marcial\\\\Pierian-Data-Courses\\\\Machine-Learning-MasterClass\\\\03-Pandas'"
]
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pwd"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### List the files in your current directory with ls"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" Volume in drive C has no label.\n",
" Volume Serial Number is 3652-BD2F\n",
"\n",
" Directory of C:\\Users\\Marcial\\Pierian-Data-Courses\\Machine-Learning-MasterClass\\03-Pandas\n",
"\n",
"06/30/2020 05:21 PM <DIR> .\n",
"06/30/2020 05:21 PM <DIR> ..\n",
"01/27/2020 01:55 PM <DIR> .ipynb_checkpoints\n",
"06/30/2020 04:51 PM 565,390 00-Series.ipynb\n",
"06/30/2020 05:21 PM 207,278 01-DataFrames.ipynb\n",
"01/27/2020 06:24 PM 194,565 02-Conditional-Filtering.ipynb\n",
"06/30/2020 11:41 AM 82,092 03-Useful-Methods.ipynb\n",
"06/30/2020 11:41 AM 45,221 04-Missing-Data.ipynb\n",
"06/30/2020 11:42 AM 1,101 05-Groupby-Operations.ipynb\n",
"06/30/2020 11:42 AM 1,103 06-Combining-DataFrames.ipynb\n",
"06/30/2020 11:42 AM 1,095 07-Text-Methods.ipynb\n",
"06/30/2020 11:42 AM 1,095 08-Time-Methods.ipynb\n",
"06/30/2020 11:42 AM 1,101 09-Inputs-and-Outputs.ipynb\n",
"06/30/2020 11:42 AM 1,095 10-Simple-Plots.ipynb\n",
"06/30/2020 11:42 AM 951 11-Pandas-Project-Exercise.ipynb\n",
"06/30/2020 11:42 AM 1,118 12-Pandas-Project-Exercise-Solution.ipynb\n",
"02/07/2020 12:26 PM 177 movie_scores.csv\n",
"01/27/2020 02:28 PM 18,752 tips.csv\n",
" 15 File(s) 1,122,134 bytes\n",
" 3 Dir(s) 84,920,594,432 bytes free\n"
]
}
],
"source": [
"ls"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"df = pd.read_csv('tips.csv')"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"outputs": [
{
"data": {
"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>total_bill</th>\n",
" <th>tip</th>\n",
" <th>sex</th>\n",
" <th>smoker</th>\n",
" <th>day</th>\n",
" <th>time</th>\n",
" <th>size</th>\n",
" <th>price_per_person</th>\n",
" <th>Payer Name</th>\n",
" <th>CC Number</th>\n",
" <th>Payment ID</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>16.99</td>\n",
" <td>1.01</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>8.49</td>\n",
" <td>Christy Cunningham</td>\n",
" <td>3560325168603410</td>\n",
" <td>Sun2959</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>10.34</td>\n",
" <td>1.66</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>3.45</td>\n",
" <td>Douglas Tucker</td>\n",
" <td>4478071379779230</td>\n",
" <td>Sun4608</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>21.01</td>\n",
" <td>3.50</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>7.00</td>\n",
" <td>Travis Walters</td>\n",
" <td>6011812112971322</td>\n",
" <td>Sun4458</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>23.68</td>\n",
" <td>3.31</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>11.84</td>\n",
" <td>Nathaniel Harris</td>\n",
" <td>4676137647685994</td>\n",
" <td>Sun5260</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>24.59</td>\n",
" <td>3.61</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>4</td>\n",
" <td>6.15</td>\n",
" <td>Tonya Carter</td>\n",
" <td>4832732618637221</td>\n",
" <td>Sun2251</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>25.29</td>\n",
" <td>4.71</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>4</td>\n",
" <td>6.32</td>\n",
" <td>Erik Smith</td>\n",
" <td>213140353657882</td>\n",
" <td>Sun9679</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>8.77</td>\n",
" <td>2.00</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>4.38</td>\n",
" <td>Kristopher Johnson</td>\n",
" <td>2223727524230344</td>\n",
" <td>Sun5985</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>26.88</td>\n",
" <td>3.12</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>4</td>\n",
" <td>6.72</td>\n",
" <td>Robert Buck</td>\n",
" <td>3514785077705092</td>\n",
" <td>Sun8157</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>15.04</td>\n",
" <td>1.96</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>7.52</td>\n",
" <td>Joseph Mcdonald</td>\n",
" <td>3522866365840377</td>\n",
" <td>Sun6820</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>14.78</td>\n",
" <td>3.23</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>7.39</td>\n",
" <td>Jerome Abbott</td>\n",
" <td>3532124519049786</td>\n",
" <td>Sun3775</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>10.27</td>\n",
" <td>1.71</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>5.14</td>\n",
" <td>William Riley</td>\n",
" <td>566287581219</td>\n",
" <td>Sun2546</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>35.26</td>\n",
" <td>5.00</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>4</td>\n",
" <td>8.82</td>\n",
" <td>Diane Macias</td>\n",
" <td>4577817359320969</td>\n",
" <td>Sun6686</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>15.42</td>\n",
" <td>1.57</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>7.71</td>\n",
" <td>Chad Harrington</td>\n",
" <td>577040572932</td>\n",
" <td>Sun1300</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>18.43</td>\n",
" <td>3.00</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>4</td>\n",
" <td>4.61</td>\n",
" <td>Joshua Jones</td>\n",
" <td>6011163105616890</td>\n",
" <td>Sun2971</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>14.83</td>\n",
" <td>3.02</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>7.42</td>\n",
" <td>Vanessa Jones</td>\n",
" <td>30016702287574</td>\n",
" <td>Sun3848</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>21.58</td>\n",
" <td>3.92</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>10.79</td>\n",
" <td>Matthew Reilly</td>\n",
" <td>180073029785069</td>\n",
" <td>Sun1878</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>10.33</td>\n",
" <td>1.67</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>3.44</td>\n",
" <td>Elizabeth Foster</td>\n",
" <td>4240025044626033</td>\n",
" <td>Sun9715</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17</th>\n",
" <td>16.29</td>\n",
" <td>3.71</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>5.43</td>\n",
" <td>John Pittman</td>\n",
" <td>6521340257218708</td>\n",
" <td>Sun2998</td>\n",
" </tr>\n",
" <tr>\n",
" <th>18</th>\n",
" <td>16.97</td>\n",
" <td>3.50</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>5.66</td>\n",
" <td>Laura Martinez</td>\n",
" <td>30422275171379</td>\n",
" <td>Sun2789</td>\n",
" </tr>\n",
" <tr>\n",
" <th>19</th>\n",
" <td>20.65</td>\n",
" <td>3.35</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>6.88</td>\n",
" <td>Timothy Oneal</td>\n",
" <td>6568069240986485</td>\n",
" <td>Sat9213</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>17.92</td>\n",
" <td>4.08</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>8.96</td>\n",
" <td>Thomas Rice</td>\n",
" <td>4403296224639756</td>\n",
" <td>Sat1709</td>\n",
" </tr>\n",
" <tr>\n",
" <th>21</th>\n",
" <td>20.29</td>\n",
" <td>2.75</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>10.14</td>\n",
" <td>Natalie Gardner</td>\n",
" <td>5448125351489749</td>\n",
" <td>Sat9618</td>\n",
" </tr>\n",
" <tr>\n",
" <th>22</th>\n",
" <td>15.77</td>\n",
" <td>2.23</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>7.88</td>\n",
" <td>Ashley Shelton</td>\n",
" <td>3524119516293213</td>\n",
" <td>Sat9786</td>\n",
" </tr>\n",
" <tr>\n",
" <th>23</th>\n",
" <td>39.42</td>\n",
" <td>7.58</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>4</td>\n",
" <td>9.86</td>\n",
" <td>Lance Peterson</td>\n",
" <td>3542584061609808</td>\n",
" <td>Sat239</td>\n",
" </tr>\n",
" <tr>\n",
" <th>24</th>\n",
" <td>19.82</td>\n",
" <td>3.18</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>9.91</td>\n",
" <td>Christopher Ross</td>\n",
" <td>36739148167928</td>\n",
" <td>Sat6236</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25</th>\n",
" <td>17.81</td>\n",
" <td>2.34</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>4</td>\n",
" <td>4.45</td>\n",
" <td>Robert Perkins</td>\n",
" <td>30502930499388</td>\n",
" <td>Sat907</td>\n",
" </tr>\n",
" <tr>\n",
" <th>26</th>\n",
" <td>13.37</td>\n",
" <td>2.00</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>6.68</td>\n",
" <td>Kyle Avery</td>\n",
" <td>6531339539615499</td>\n",
" <td>Sat6651</td>\n",
" </tr>\n",
" <tr>\n",
" <th>27</th>\n",
" <td>12.69</td>\n",
" <td>2.00</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>6.34</td>\n",
" <td>Patrick Barber</td>\n",
" <td>30155551880343</td>\n",
" <td>Sat394</td>\n",
" </tr>\n",
" <tr>\n",
" <th>28</th>\n",
" <td>21.70</td>\n",
" <td>4.30</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>10.85</td>\n",
" <td>David Collier</td>\n",
" <td>5529694315416009</td>\n",
" <td>Sat3697</td>\n",
" </tr>\n",
" <tr>\n",
" <th>29</th>\n",
" <td>19.65</td>\n",
" <td>3.00</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>9.82</td>\n",
" <td>Melinda Murphy</td>\n",
" <td>5489272944576051</td>\n",
" <td>Sat2467</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",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>214</th>\n",
" <td>28.17</td>\n",
" <td>6.50</td>\n",
" <td>Female</td>\n",
" <td>Yes</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>9.39</td>\n",
" <td>Marissa Jackson</td>\n",
" <td>4922302538691962</td>\n",
" <td>Sat3374</td>\n",
" </tr>\n",
" <tr>\n",
" <th>215</th>\n",
" <td>12.90</td>\n",
" <td>1.10</td>\n",
" <td>Female</td>\n",
" <td>Yes</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>6.45</td>\n",
" <td>Jessica Owen</td>\n",
" <td>4726904879471</td>\n",
" <td>Sat6983</td>\n",
" </tr>\n",
" <tr>\n",
" <th>216</th>\n",
" <td>28.15</td>\n",
" <td>3.00</td>\n",
" <td>Male</td>\n",
" <td>Yes</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>5</td>\n",
" <td>5.63</td>\n",
" <td>Shawn Barnett PhD</td>\n",
" <td>4590982568244</td>\n",
" <td>Sat7320</td>\n",
" </tr>\n",
" <tr>\n",
" <th>217</th>\n",
" <td>11.59</td>\n",
" <td>1.50</td>\n",
" <td>Male</td>\n",
" <td>Yes</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>5.80</td>\n",
" <td>Gary Orr</td>\n",
" <td>30324521283406</td>\n",
" <td>Sat8489</td>\n",
" </tr>\n",
" <tr>\n",
" <th>218</th>\n",
" <td>7.74</td>\n",
" <td>1.44</td>\n",
" <td>Male</td>\n",
" <td>Yes</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>3.87</td>\n",
" <td>Nicholas Archer</td>\n",
" <td>340517153733524</td>\n",
" <td>Sat4772</td>\n",
" </tr>\n",
" <tr>\n",
" <th>219</th>\n",
" <td>30.14</td>\n",
" <td>3.09</td>\n",
" <td>Female</td>\n",
" <td>Yes</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>4</td>\n",
" <td>7.54</td>\n",
" <td>Shelby House</td>\n",
" <td>502097403252</td>\n",
" <td>Sat8863</td>\n",
" </tr>\n",
" <tr>\n",
" <th>220</th>\n",
" <td>12.16</td>\n",
" <td>2.20</td>\n",
" <td>Male</td>\n",
" <td>Yes</td>\n",
" <td>Fri</td>\n",
" <td>Lunch</td>\n",
" <td>2</td>\n",
" <td>6.08</td>\n",
" <td>Ricky Johnson</td>\n",
" <td>213109508670736</td>\n",
" <td>Fri4607</td>\n",
" </tr>\n",
" <tr>\n",
" <th>221</th>\n",
" <td>13.42</td>\n",
" <td>3.48</td>\n",
" <td>Female</td>\n",
" <td>Yes</td>\n",
" <td>Fri</td>\n",
" <td>Lunch</td>\n",
" <td>2</td>\n",
" <td>6.71</td>\n",
" <td>Leslie Kaufman</td>\n",
" <td>379437981958785</td>\n",
" <td>Fri7511</td>\n",
" </tr>\n",
" <tr>\n",
" <th>222</th>\n",
" <td>8.58</td>\n",
" <td>1.92</td>\n",
" <td>Male</td>\n",
" <td>Yes</td>\n",
" <td>Fri</td>\n",
" <td>Lunch</td>\n",
" <td>1</td>\n",
" <td>8.58</td>\n",
" <td>Jason Lawrence</td>\n",
" <td>3505302934650403</td>\n",
" <td>Fri6624</td>\n",
" </tr>\n",
" <tr>\n",
" <th>223</th>\n",
" <td>15.98</td>\n",
" <td>3.00</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Fri</td>\n",
" <td>Lunch</td>\n",
" <td>3</td>\n",
" <td>5.33</td>\n",
" <td>Mary Rivera</td>\n",
" <td>5343428579353069</td>\n",
" <td>Fri6014</td>\n",
" </tr>\n",
" <tr>\n",
" <th>224</th>\n",
" <td>13.42</td>\n",
" <td>1.58</td>\n",
" <td>Male</td>\n",
" <td>Yes</td>\n",
" <td>Fri</td>\n",
" <td>Lunch</td>\n",
" <td>2</td>\n",
" <td>6.71</td>\n",
" <td>Ronald Vaughn DVM</td>\n",
" <td>341503466406403</td>\n",
" <td>Fri5959</td>\n",
" </tr>\n",
" <tr>\n",
" <th>225</th>\n",
" <td>16.27</td>\n",
" <td>2.50</td>\n",
" <td>Female</td>\n",
" <td>Yes</td>\n",
" <td>Fri</td>\n",
" <td>Lunch</td>\n",
" <td>2</td>\n",
" <td>8.14</td>\n",
" <td>Whitney Arnold</td>\n",
" <td>3579111947217428</td>\n",
" <td>Fri6665</td>\n",
" </tr>\n",
" <tr>\n",
" <th>226</th>\n",
" <td>10.09</td>\n",
" <td>2.00</td>\n",
" <td>Female</td>\n",
" <td>Yes</td>\n",
" <td>Fri</td>\n",
" <td>Lunch</td>\n",
" <td>2</td>\n",
" <td>5.04</td>\n",
" <td>Ruth Weiss</td>\n",
" <td>5268689490381635</td>\n",
" <td>Fri6359</td>\n",
" </tr>\n",
" <tr>\n",
" <th>227</th>\n",
" <td>20.45</td>\n",
" <td>3.00</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>4</td>\n",
" <td>5.11</td>\n",
" <td>Robert Bradley</td>\n",
" <td>213141668145910</td>\n",
" <td>Sat4319</td>\n",
" </tr>\n",
" <tr>\n",
" <th>228</th>\n",
" <td>13.28</td>\n",
" <td>2.72</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>6.64</td>\n",
" <td>Glenn Jones</td>\n",
" <td>502061651712</td>\n",
" <td>Sat2937</td>\n",
" </tr>\n",
" <tr>\n",
" <th>229</th>\n",
" <td>22.12</td>\n",
" <td>2.88</td>\n",
" <td>Female</td>\n",
" <td>Yes</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>11.06</td>\n",
" <td>Jennifer Russell</td>\n",
" <td>4793003293608</td>\n",
" <td>Sat3943</td>\n",
" </tr>\n",
" <tr>\n",
" <th>230</th>\n",
" <td>24.01</td>\n",
" <td>2.00</td>\n",
" <td>Male</td>\n",
" <td>Yes</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>4</td>\n",
" <td>6.00</td>\n",
" <td>Michael Osborne</td>\n",
" <td>4258682154026</td>\n",
" <td>Sat7872</td>\n",
" </tr>\n",
" <tr>\n",
" <th>231</th>\n",
" <td>15.69</td>\n",
" <td>3.00</td>\n",
" <td>Male</td>\n",
" <td>Yes</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>5.23</td>\n",
" <td>Jason Parks</td>\n",
" <td>4812333796161</td>\n",
" <td>Sat6334</td>\n",
" </tr>\n",
" <tr>\n",
" <th>232</th>\n",
" <td>11.61</td>\n",
" <td>3.39</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>5.80</td>\n",
" <td>James Taylor</td>\n",
" <td>6011482917327995</td>\n",
" <td>Sat2124</td>\n",
" </tr>\n",
" <tr>\n",
" <th>233</th>\n",
" <td>10.77</td>\n",
" <td>1.47</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>5.38</td>\n",
" <td>Paul Novak</td>\n",
" <td>6011698897610858</td>\n",
" <td>Sat1467</td>\n",
" </tr>\n",
" <tr>\n",
" <th>234</th>\n",
" <td>15.53</td>\n",
" <td>3.00</td>\n",
" <td>Male</td>\n",
" <td>Yes</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>7.76</td>\n",
" <td>Tracy Douglas</td>\n",
" <td>4097938155941930</td>\n",
" <td>Sat7220</td>\n",
" </tr>\n",
" <tr>\n",
" <th>235</th>\n",
" <td>10.07</td>\n",
" <td>1.25</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>5.04</td>\n",
" <td>Sean Gonzalez</td>\n",
" <td>3534021246117605</td>\n",
" <td>Sat4615</td>\n",
" </tr>\n",
" <tr>\n",
" <th>236</th>\n",
" <td>12.60</td>\n",
" <td>1.00</td>\n",
" <td>Male</td>\n",
" <td>Yes</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>6.30</td>\n",
" <td>Matthew Myers</td>\n",
" <td>3543676378973965</td>\n",
" <td>Sat5032</td>\n",
" </tr>\n",
" <tr>\n",
" <th>237</th>\n",
" <td>32.83</td>\n",
" <td>1.17</td>\n",
" <td>Male</td>\n",
" <td>Yes</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>16.42</td>\n",
" <td>Thomas Brown</td>\n",
" <td>4284722681265508</td>\n",
" <td>Sat2929</td>\n",
" </tr>\n",
" <tr>\n",
" <th>238</th>\n",
" <td>35.83</td>\n",
" <td>4.67</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>11.94</td>\n",
" <td>Kimberly Crane</td>\n",
" <td>676184013727</td>\n",
" <td>Sat9777</td>\n",
" </tr>\n",
" <tr>\n",
" <th>239</th>\n",
" <td>29.03</td>\n",
" <td>5.92</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>9.68</td>\n",
" <td>Michael Avila</td>\n",
" <td>5296068606052842</td>\n",
" <td>Sat2657</td>\n",
" </tr>\n",
" <tr>\n",
" <th>240</th>\n",
" <td>27.18</td>\n",
" <td>2.00</td>\n",
" <td>Female</td>\n",
" <td>Yes</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>13.59</td>\n",
" <td>Monica Sanders</td>\n",
" <td>3506806155565404</td>\n",
" <td>Sat1766</td>\n",
" </tr>\n",
" <tr>\n",
" <th>241</th>\n",
" <td>22.67</td>\n",
" <td>2.00</td>\n",
" <td>Male</td>\n",
" <td>Yes</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>11.34</td>\n",
" <td>Keith Wong</td>\n",
" <td>6011891618747196</td>\n",
" <td>Sat3880</td>\n",
" </tr>\n",
" <tr>\n",
" <th>242</th>\n",
" <td>17.82</td>\n",
" <td>1.75</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>8.91</td>\n",
" <td>Dennis Dixon</td>\n",
" <td>4375220550950</td>\n",
" <td>Sat17</td>\n",
" </tr>\n",
" <tr>\n",
" <th>243</th>\n",
" <td>18.78</td>\n",
" <td>3.00</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Thur</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>9.39</td>\n",
" <td>Michelle Hardin</td>\n",
" <td>3511451626698139</td>\n",
" <td>Thur672</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>244 rows × 11 columns</p>\n",
"</div>"
],
"text/plain": [
" total_bill tip sex smoker day time size price_per_person \\\n",
"0 16.99 1.01 Female No Sun Dinner 2 8.49 \n",
"1 10.34 1.66 Male No Sun Dinner 3 3.45 \n",
"2 21.01 3.50 Male No Sun Dinner 3 7.00 \n",
"3 23.68 3.31 Male No Sun Dinner 2 11.84 \n",
"4 24.59 3.61 Female No Sun Dinner 4 6.15 \n",
"5 25.29 4.71 Male No Sun Dinner 4 6.32 \n",
"6 8.77 2.00 Male No Sun Dinner 2 4.38 \n",
"7 26.88 3.12 Male No Sun Dinner 4 6.72 \n",
"8 15.04 1.96 Male No Sun Dinner 2 7.52 \n",
"9 14.78 3.23 Male No Sun Dinner 2 7.39 \n",
"10 10.27 1.71 Male No Sun Dinner 2 5.14 \n",
"11 35.26 5.00 Female No Sun Dinner 4 8.82 \n",
"12 15.42 1.57 Male No Sun Dinner 2 7.71 \n",
"13 18.43 3.00 Male No Sun Dinner 4 4.61 \n",
"14 14.83 3.02 Female No Sun Dinner 2 7.42 \n",
"15 21.58 3.92 Male No Sun Dinner 2 10.79 \n",
"16 10.33 1.67 Female No Sun Dinner 3 3.44 \n",
"17 16.29 3.71 Male No Sun Dinner 3 5.43 \n",
"18 16.97 3.50 Female No Sun Dinner 3 5.66 \n",
"19 20.65 3.35 Male No Sat Dinner 3 6.88 \n",
"20 17.92 4.08 Male No Sat Dinner 2 8.96 \n",
"21 20.29 2.75 Female No Sat Dinner 2 10.14 \n",
"22 15.77 2.23 Female No Sat Dinner 2 7.88 \n",
"23 39.42 7.58 Male No Sat Dinner 4 9.86 \n",
"24 19.82 3.18 Male No Sat Dinner 2 9.91 \n",
"25 17.81 2.34 Male No Sat Dinner 4 4.45 \n",
"26 13.37 2.00 Male No Sat Dinner 2 6.68 \n",
"27 12.69 2.00 Male No Sat Dinner 2 6.34 \n",
"28 21.70 4.30 Male No Sat Dinner 2 10.85 \n",
"29 19.65 3.00 Female No Sat Dinner 2 9.82 \n",
".. ... ... ... ... ... ... ... ... \n",
"214 28.17 6.50 Female Yes Sat Dinner 3 9.39 \n",
"215 12.90 1.10 Female Yes Sat Dinner 2 6.45 \n",
"216 28.15 3.00 Male Yes Sat Dinner 5 5.63 \n",
"217 11.59 1.50 Male Yes Sat Dinner 2 5.80 \n",
"218 7.74 1.44 Male Yes Sat Dinner 2 3.87 \n",
"219 30.14 3.09 Female Yes Sat Dinner 4 7.54 \n",
"220 12.16 2.20 Male Yes Fri Lunch 2 6.08 \n",
"221 13.42 3.48 Female Yes Fri Lunch 2 6.71 \n",
"222 8.58 1.92 Male Yes Fri Lunch 1 8.58 \n",
"223 15.98 3.00 Female No Fri Lunch 3 5.33 \n",
"224 13.42 1.58 Male Yes Fri Lunch 2 6.71 \n",
"225 16.27 2.50 Female Yes Fri Lunch 2 8.14 \n",
"226 10.09 2.00 Female Yes Fri Lunch 2 5.04 \n",
"227 20.45 3.00 Male No Sat Dinner 4 5.11 \n",
"228 13.28 2.72 Male No Sat Dinner 2 6.64 \n",
"229 22.12 2.88 Female Yes Sat Dinner 2 11.06 \n",
"230 24.01 2.00 Male Yes Sat Dinner 4 6.00 \n",
"231 15.69 3.00 Male Yes Sat Dinner 3 5.23 \n",
"232 11.61 3.39 Male No Sat Dinner 2 5.80 \n",
"233 10.77 1.47 Male No Sat Dinner 2 5.38 \n",
"234 15.53 3.00 Male Yes Sat Dinner 2 7.76 \n",
"235 10.07 1.25 Male No Sat Dinner 2 5.04 \n",
"236 12.60 1.00 Male Yes Sat Dinner 2 6.30 \n",
"237 32.83 1.17 Male Yes Sat Dinner 2 16.42 \n",
"238 35.83 4.67 Female No Sat Dinner 3 11.94 \n",
"239 29.03 5.92 Male No Sat Dinner 3 9.68 \n",
"240 27.18 2.00 Female Yes Sat Dinner 2 13.59 \n",
"241 22.67 2.00 Male Yes Sat Dinner 2 11.34 \n",
"242 17.82 1.75 Male No Sat Dinner 2 8.91 \n",
"243 18.78 3.00 Female No Thur Dinner 2 9.39 \n",
"\n",
" Payer Name CC Number Payment ID \n",
"0 Christy Cunningham 3560325168603410 Sun2959 \n",
"1 Douglas Tucker 4478071379779230 Sun4608 \n",
"2 Travis Walters 6011812112971322 Sun4458 \n",
"3 Nathaniel Harris 4676137647685994 Sun5260 \n",
"4 Tonya Carter 4832732618637221 Sun2251 \n",
"5 Erik Smith 213140353657882 Sun9679 \n",
"6 Kristopher Johnson 2223727524230344 Sun5985 \n",
"7 Robert Buck 3514785077705092 Sun8157 \n",
"8 Joseph Mcdonald 3522866365840377 Sun6820 \n",
"9 Jerome Abbott 3532124519049786 Sun3775 \n",
"10 William Riley 566287581219 Sun2546 \n",
"11 Diane Macias 4577817359320969 Sun6686 \n",
"12 Chad Harrington 577040572932 Sun1300 \n",
"13 Joshua Jones 6011163105616890 Sun2971 \n",
"14 Vanessa Jones 30016702287574 Sun3848 \n",
"15 Matthew Reilly 180073029785069 Sun1878 \n",
"16 Elizabeth Foster 4240025044626033 Sun9715 \n",
"17 John Pittman 6521340257218708 Sun2998 \n",
"18 Laura Martinez 30422275171379 Sun2789 \n",
"19 Timothy Oneal 6568069240986485 Sat9213 \n",
"20 Thomas Rice 4403296224639756 Sat1709 \n",
"21 Natalie Gardner 5448125351489749 Sat9618 \n",
"22 Ashley Shelton 3524119516293213 Sat9786 \n",
"23 Lance Peterson 3542584061609808 Sat239 \n",
"24 Christopher Ross 36739148167928 Sat6236 \n",
"25 Robert Perkins 30502930499388 Sat907 \n",
"26 Kyle Avery 6531339539615499 Sat6651 \n",
"27 Patrick Barber 30155551880343 Sat394 \n",
"28 David Collier 5529694315416009 Sat3697 \n",
"29 Melinda Murphy 5489272944576051 Sat2467 \n",
".. ... ... ... \n",
"214 Marissa Jackson 4922302538691962 Sat3374 \n",
"215 Jessica Owen 4726904879471 Sat6983 \n",
"216 Shawn Barnett PhD 4590982568244 Sat7320 \n",
"217 Gary Orr 30324521283406 Sat8489 \n",
"218 Nicholas Archer 340517153733524 Sat4772 \n",
"219 Shelby House 502097403252 Sat8863 \n",
"220 Ricky Johnson 213109508670736 Fri4607 \n",
"221 Leslie Kaufman 379437981958785 Fri7511 \n",
"222 Jason Lawrence 3505302934650403 Fri6624 \n",
"223 Mary Rivera 5343428579353069 Fri6014 \n",
"224 Ronald Vaughn DVM 341503466406403 Fri5959 \n",
"225 Whitney Arnold 3579111947217428 Fri6665 \n",
"226 Ruth Weiss 5268689490381635 Fri6359 \n",
"227 Robert Bradley 213141668145910 Sat4319 \n",
"228 Glenn Jones 502061651712 Sat2937 \n",
"229 Jennifer Russell 4793003293608 Sat3943 \n",
"230 Michael Osborne 4258682154026 Sat7872 \n",
"231 Jason Parks 4812333796161 Sat6334 \n",
"232 James Taylor 6011482917327995 Sat2124 \n",
"233 Paul Novak 6011698897610858 Sat1467 \n",
"234 Tracy Douglas 4097938155941930 Sat7220 \n",
"235 Sean Gonzalez 3534021246117605 Sat4615 \n",
"236 Matthew Myers 3543676378973965 Sat5032 \n",
"237 Thomas Brown 4284722681265508 Sat2929 \n",
"238 Kimberly Crane 676184013727 Sat9777 \n",
"239 Michael Avila 5296068606052842 Sat2657 \n",
"240 Monica Sanders 3506806155565404 Sat1766 \n",
"241 Keith Wong 6011891618747196 Sat3880 \n",
"242 Dennis Dixon 4375220550950 Sat17 \n",
"243 Michelle Hardin 3511451626698139 Thur672 \n",
"\n",
"[244 rows x 11 columns]"
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"----\n",
"About this DataSet (in case you are interested)\n",
"\n",
"* Description\n",
" * One waiter recorded information about each tip he received over a period of a few months working in one restaurant. He collected several variables:\n",
"\n",
"* Format\n",
" * A data frame with 244 rows and 7 variables\n",
"\n",
"* Details\n",
" * tip in dollars,\n",
" * bill in dollars,\n",
" * sex of the bill payer,\n",
" * whether there were smokers in the party,\n",
" * day of the week,\n",
" * time of day,\n",
" * size of the party.\n",
"\n",
"In all he recorded 244 tips. The data was reported in a collection of case studies for business statistics (Bryant & Smith 1995).\n",
"\n",
"* References\n",
" * Bryant, P. G. and Smith, M (1995) Practical Data Analysis: Case Studies in Business Statistics. Homewood, IL: Richard D. Irwin Publishing:\n",
" \n",
"* Note: We created some additional columns with Fake data, including Name, CC Number, and Payment ID.\n",
"\n",
"----"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# DataFrames"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Obtaining Basic Information About DataFrame"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Index(['total_bill', 'tip', 'sex', 'smoker', 'day', 'time', 'size',\n",
" 'price_per_person', 'Payer Name', 'CC Number', 'Payment ID'],\n",
" dtype='object')"
]
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.columns"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"RangeIndex(start=0, stop=244, step=1)"
]
},
"execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.index"
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {},
"outputs": [
{
"data": {
"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>total_bill</th>\n",
" <th>tip</th>\n",
" <th>sex</th>\n",
" <th>smoker</th>\n",
" <th>day</th>\n",
" <th>time</th>\n",
" <th>size</th>\n",
" <th>price_per_person</th>\n",
" <th>Payer Name</th>\n",
" <th>CC Number</th>\n",
" <th>Payment ID</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>16.99</td>\n",
" <td>1.01</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>8.49</td>\n",
" <td>Christy Cunningham</td>\n",
" <td>3560325168603410</td>\n",
" <td>Sun2959</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>10.34</td>\n",
" <td>1.66</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>3.45</td>\n",
" <td>Douglas Tucker</td>\n",
" <td>4478071379779230</td>\n",
" <td>Sun4608</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>21.01</td>\n",
" <td>3.50</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>7.00</td>\n",
" <td>Travis Walters</td>\n",
" <td>6011812112971322</td>\n",
" <td>Sun4458</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" total_bill tip sex smoker day time size price_per_person \\\n",
"0 16.99 1.01 Female No Sun Dinner 2 8.49 \n",
"1 10.34 1.66 Male No Sun Dinner 3 3.45 \n",
"2 21.01 3.50 Male No Sun Dinner 3 7.00 \n",
"\n",
" Payer Name CC Number Payment ID \n",
"0 Christy Cunningham 3560325168603410 Sun2959 \n",
"1 Douglas Tucker 4478071379779230 Sun4608 \n",
"2 Travis Walters 6011812112971322 Sun4458 "
]
},
"execution_count": 44,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head(3)"
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {},
"outputs": [
{
"data": {
"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>total_bill</th>\n",
" <th>tip</th>\n",
" <th>sex</th>\n",
" <th>smoker</th>\n",
" <th>day</th>\n",
" <th>time</th>\n",
" <th>size</th>\n",
" <th>price_per_person</th>\n",
" <th>Payer Name</th>\n",
" <th>CC Number</th>\n",
" <th>Payment ID</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>241</th>\n",
" <td>22.67</td>\n",
" <td>2.00</td>\n",
" <td>Male</td>\n",
" <td>Yes</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>11.34</td>\n",
" <td>Keith Wong</td>\n",
" <td>6011891618747196</td>\n",
" <td>Sat3880</td>\n",
" </tr>\n",
" <tr>\n",
" <th>242</th>\n",
" <td>17.82</td>\n",
" <td>1.75</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>8.91</td>\n",
" <td>Dennis Dixon</td>\n",
" <td>4375220550950</td>\n",
" <td>Sat17</td>\n",
" </tr>\n",
" <tr>\n",
" <th>243</th>\n",
" <td>18.78</td>\n",
" <td>3.00</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Thur</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>9.39</td>\n",
" <td>Michelle Hardin</td>\n",
" <td>3511451626698139</td>\n",
" <td>Thur672</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" total_bill tip sex smoker day time size price_per_person \\\n",
"241 22.67 2.00 Male Yes Sat Dinner 2 11.34 \n",
"242 17.82 1.75 Male No Sat Dinner 2 8.91 \n",
"243 18.78 3.00 Female No Thur Dinner 2 9.39 \n",
"\n",
" Payer Name CC Number Payment ID \n",
"241 Keith Wong 6011891618747196 Sat3880 \n",
"242 Dennis Dixon 4375220550950 Sat17 \n",
"243 Michelle Hardin 3511451626698139 Thur672 "
]
},
"execution_count": 45,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.tail(3)"
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'pandas.core.frame.DataFrame'>\n",
"RangeIndex: 244 entries, 0 to 243\n",
"Data columns (total 11 columns):\n",
"total_bill 244 non-null float64\n",
"tip 244 non-null float64\n",
"sex 244 non-null object\n",
"smoker 244 non-null object\n",
"day 244 non-null object\n",
"time 244 non-null object\n",
"size 244 non-null int64\n",
"price_per_person 244 non-null float64\n",
"Payer Name 244 non-null object\n",
"CC Number 244 non-null int64\n",
"Payment ID 244 non-null object\n",
"dtypes: float64(3), int64(2), object(6)\n",
"memory usage: 21.0+ KB\n"
]
}
],
"source": [
"df.info()"
]
},
{
"cell_type": "code",
"execution_count": 47,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"244"
]
},
"execution_count": 47,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(df)"
]
},
{
"cell_type": "code",
"execution_count": 48,
"metadata": {},
"outputs": [
{
"data": {
"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>total_bill</th>\n",
" <th>tip</th>\n",
" <th>size</th>\n",
" <th>price_per_person</th>\n",
" <th>CC Number</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>count</th>\n",
" <td>244.000000</td>\n",
" <td>244.000000</td>\n",
" <td>244.000000</td>\n",
" <td>244.000000</td>\n",
" <td>2.440000e+02</td>\n",
" </tr>\n",
" <tr>\n",
" <th>mean</th>\n",
" <td>19.785943</td>\n",
" <td>2.998279</td>\n",
" <td>2.569672</td>\n",
" <td>7.888197</td>\n",
" <td>2.563496e+15</td>\n",
" </tr>\n",
" <tr>\n",
" <th>std</th>\n",
" <td>8.902412</td>\n",
" <td>1.383638</td>\n",
" <td>0.951100</td>\n",
" <td>2.914234</td>\n",
" <td>2.369340e+15</td>\n",
" </tr>\n",
" <tr>\n",
" <th>min</th>\n",
" <td>3.070000</td>\n",
" <td>1.000000</td>\n",
" <td>1.000000</td>\n",
" <td>2.880000</td>\n",
" <td>6.040679e+10</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25%</th>\n",
" <td>13.347500</td>\n",
" <td>2.000000</td>\n",
" <td>2.000000</td>\n",
" <td>5.800000</td>\n",
" <td>3.040731e+13</td>\n",
" </tr>\n",
" <tr>\n",
" <th>50%</th>\n",
" <td>17.795000</td>\n",
" <td>2.900000</td>\n",
" <td>2.000000</td>\n",
" <td>7.255000</td>\n",
" <td>3.525318e+15</td>\n",
" </tr>\n",
" <tr>\n",
" <th>75%</th>\n",
" <td>24.127500</td>\n",
" <td>3.562500</td>\n",
" <td>3.000000</td>\n",
" <td>9.390000</td>\n",
" <td>4.553675e+15</td>\n",
" </tr>\n",
" <tr>\n",
" <th>max</th>\n",
" <td>50.810000</td>\n",
" <td>10.000000</td>\n",
" <td>6.000000</td>\n",
" <td>20.270000</td>\n",
" <td>6.596454e+15</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" total_bill tip size price_per_person CC Number\n",
"count 244.000000 244.000000 244.000000 244.000000 2.440000e+02\n",
"mean 19.785943 2.998279 2.569672 7.888197 2.563496e+15\n",
"std 8.902412 1.383638 0.951100 2.914234 2.369340e+15\n",
"min 3.070000 1.000000 1.000000 2.880000 6.040679e+10\n",
"25% 13.347500 2.000000 2.000000 5.800000 3.040731e+13\n",
"50% 17.795000 2.900000 2.000000 7.255000 3.525318e+15\n",
"75% 24.127500 3.562500 3.000000 9.390000 4.553675e+15\n",
"max 50.810000 10.000000 6.000000 20.270000 6.596454e+15"
]
},
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.describe()"
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {},
"outputs": [
{
"data": {
"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>count</th>\n",
" <th>mean</th>\n",
" <th>std</th>\n",
" <th>min</th>\n",
" <th>25%</th>\n",
" <th>50%</th>\n",
" <th>75%</th>\n",
" <th>max</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>total_bill</th>\n",
" <td>244.0</td>\n",
" <td>1.978594e+01</td>\n",
" <td>8.902412e+00</td>\n",
" <td>3.070000e+00</td>\n",
" <td>1.334750e+01</td>\n",
" <td>1.779500e+01</td>\n",
" <td>2.412750e+01</td>\n",
" <td>5.081000e+01</td>\n",
" </tr>\n",
" <tr>\n",
" <th>tip</th>\n",
" <td>244.0</td>\n",
" <td>2.998279e+00</td>\n",
" <td>1.383638e+00</td>\n",
" <td>1.000000e+00</td>\n",
" <td>2.000000e+00</td>\n",
" <td>2.900000e+00</td>\n",
" <td>3.562500e+00</td>\n",
" <td>1.000000e+01</td>\n",
" </tr>\n",
" <tr>\n",
" <th>size</th>\n",
" <td>244.0</td>\n",
" <td>2.569672e+00</td>\n",
" <td>9.510998e-01</td>\n",
" <td>1.000000e+00</td>\n",
" <td>2.000000e+00</td>\n",
" <td>2.000000e+00</td>\n",
" <td>3.000000e+00</td>\n",
" <td>6.000000e+00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>price_per_person</th>\n",
" <td>244.0</td>\n",
" <td>7.888197e+00</td>\n",
" <td>2.914234e+00</td>\n",
" <td>2.880000e+00</td>\n",
" <td>5.800000e+00</td>\n",
" <td>7.255000e+00</td>\n",
" <td>9.390000e+00</td>\n",
" <td>2.027000e+01</td>\n",
" </tr>\n",
" <tr>\n",
" <th>CC Number</th>\n",
" <td>244.0</td>\n",
" <td>2.563496e+15</td>\n",
" <td>2.369340e+15</td>\n",
" <td>6.040679e+10</td>\n",
" <td>3.040731e+13</td>\n",
" <td>3.525318e+15</td>\n",
" <td>4.553675e+15</td>\n",
" <td>6.596454e+15</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" count mean std min \\\n",
"total_bill 244.0 1.978594e+01 8.902412e+00 3.070000e+00 \n",
"tip 244.0 2.998279e+00 1.383638e+00 1.000000e+00 \n",
"size 244.0 2.569672e+00 9.510998e-01 1.000000e+00 \n",
"price_per_person 244.0 7.888197e+00 2.914234e+00 2.880000e+00 \n",
"CC Number 244.0 2.563496e+15 2.369340e+15 6.040679e+10 \n",
"\n",
" 25% 50% 75% max \n",
"total_bill 1.334750e+01 1.779500e+01 2.412750e+01 5.081000e+01 \n",
"tip 2.000000e+00 2.900000e+00 3.562500e+00 1.000000e+01 \n",
"size 2.000000e+00 2.000000e+00 3.000000e+00 6.000000e+00 \n",
"price_per_person 5.800000e+00 7.255000e+00 9.390000e+00 2.027000e+01 \n",
"CC Number 3.040731e+13 3.525318e+15 4.553675e+15 6.596454e+15 "
]
},
"execution_count": 49,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.describe().transpose()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Selection and Indexing\n",
"\n",
"Let's learn how to retrieve information from a DataFrame."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### COLUMNS"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We will begin be learning how to extract information based on the columns"
]
},
{
"cell_type": "code",
"execution_count": 50,
"metadata": {},
"outputs": [
{
"data": {
"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>total_bill</th>\n",
" <th>tip</th>\n",
" <th>sex</th>\n",
" <th>smoker</th>\n",
" <th>day</th>\n",
" <th>time</th>\n",
" <th>size</th>\n",
" <th>price_per_person</th>\n",
" <th>Payer Name</th>\n",
" <th>CC Number</th>\n",
" <th>Payment ID</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>16.99</td>\n",
" <td>1.01</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>8.49</td>\n",
" <td>Christy Cunningham</td>\n",
" <td>3560325168603410</td>\n",
" <td>Sun2959</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>10.34</td>\n",
" <td>1.66</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>3.45</td>\n",
" <td>Douglas Tucker</td>\n",
" <td>4478071379779230</td>\n",
" <td>Sun4608</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>21.01</td>\n",
" <td>3.50</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>7.00</td>\n",
" <td>Travis Walters</td>\n",
" <td>6011812112971322</td>\n",
" <td>Sun4458</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>23.68</td>\n",
" <td>3.31</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>11.84</td>\n",
" <td>Nathaniel Harris</td>\n",
" <td>4676137647685994</td>\n",
" <td>Sun5260</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>24.59</td>\n",
" <td>3.61</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>4</td>\n",
" <td>6.15</td>\n",
" <td>Tonya Carter</td>\n",
" <td>4832732618637221</td>\n",
" <td>Sun2251</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" total_bill tip sex smoker day time size price_per_person \\\n",
"0 16.99 1.01 Female No Sun Dinner 2 8.49 \n",
"1 10.34 1.66 Male No Sun Dinner 3 3.45 \n",
"2 21.01 3.50 Male No Sun Dinner 3 7.00 \n",
"3 23.68 3.31 Male No Sun Dinner 2 11.84 \n",
"4 24.59 3.61 Female No Sun Dinner 4 6.15 \n",
"\n",
" Payer Name CC Number Payment ID \n",
"0 Christy Cunningham 3560325168603410 Sun2959 \n",
"1 Douglas Tucker 4478071379779230 Sun4608 \n",
"2 Travis Walters 6011812112971322 Sun4458 \n",
"3 Nathaniel Harris 4676137647685994 Sun5260 \n",
"4 Tonya Carter 4832732618637221 Sun2251 "
]
},
"execution_count": 50,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Grab a Single Column"
]
},
{
"cell_type": "code",
"execution_count": 51,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 16.99\n",
"1 10.34\n",
"2 21.01\n",
"3 23.68\n",
"4 24.59\n",
"5 25.29\n",
"6 8.77\n",
"7 26.88\n",
"8 15.04\n",
"9 14.78\n",
"10 10.27\n",
"11 35.26\n",
"12 15.42\n",
"13 18.43\n",
"14 14.83\n",
"15 21.58\n",
"16 10.33\n",
"17 16.29\n",
"18 16.97\n",
"19 20.65\n",
"20 17.92\n",
"21 20.29\n",
"22 15.77\n",
"23 39.42\n",
"24 19.82\n",
"25 17.81\n",
"26 13.37\n",
"27 12.69\n",
"28 21.70\n",
"29 19.65\n",
" ... \n",
"214 28.17\n",
"215 12.90\n",
"216 28.15\n",
"217 11.59\n",
"218 7.74\n",
"219 30.14\n",
"220 12.16\n",
"221 13.42\n",
"222 8.58\n",
"223 15.98\n",
"224 13.42\n",
"225 16.27\n",
"226 10.09\n",
"227 20.45\n",
"228 13.28\n",
"229 22.12\n",
"230 24.01\n",
"231 15.69\n",
"232 11.61\n",
"233 10.77\n",
"234 15.53\n",
"235 10.07\n",
"236 12.60\n",
"237 32.83\n",
"238 35.83\n",
"239 29.03\n",
"240 27.18\n",
"241 22.67\n",
"242 17.82\n",
"243 18.78\n",
"Name: total_bill, Length: 244, dtype: float64"
]
},
"execution_count": 51,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df['total_bill']"
]
},
{
"cell_type": "code",
"execution_count": 52,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"pandas.core.series.Series"
]
},
"execution_count": 52,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(df['total_bill'])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Grab Multiple Columns"
]
},
{
"cell_type": "code",
"execution_count": 53,
"metadata": {},
"outputs": [
{
"data": {
"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>total_bill</th>\n",
" <th>tip</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>16.99</td>\n",
" <td>1.01</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>10.34</td>\n",
" <td>1.66</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>21.01</td>\n",
" <td>3.50</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>23.68</td>\n",
" <td>3.31</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>24.59</td>\n",
" <td>3.61</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>25.29</td>\n",
" <td>4.71</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>8.77</td>\n",
" <td>2.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>26.88</td>\n",
" <td>3.12</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>15.04</td>\n",
" <td>1.96</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>14.78</td>\n",
" <td>3.23</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>10.27</td>\n",
" <td>1.71</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>35.26</td>\n",
" <td>5.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>15.42</td>\n",
" <td>1.57</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>18.43</td>\n",
" <td>3.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>14.83</td>\n",
" <td>3.02</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>21.58</td>\n",
" <td>3.92</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>10.33</td>\n",
" <td>1.67</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17</th>\n",
" <td>16.29</td>\n",
" <td>3.71</td>\n",
" </tr>\n",
" <tr>\n",
" <th>18</th>\n",
" <td>16.97</td>\n",
" <td>3.50</td>\n",
" </tr>\n",
" <tr>\n",
" <th>19</th>\n",
" <td>20.65</td>\n",
" <td>3.35</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>17.92</td>\n",
" <td>4.08</td>\n",
" </tr>\n",
" <tr>\n",
" <th>21</th>\n",
" <td>20.29</td>\n",
" <td>2.75</td>\n",
" </tr>\n",
" <tr>\n",
" <th>22</th>\n",
" <td>15.77</td>\n",
" <td>2.23</td>\n",
" </tr>\n",
" <tr>\n",
" <th>23</th>\n",
" <td>39.42</td>\n",
" <td>7.58</td>\n",
" </tr>\n",
" <tr>\n",
" <th>24</th>\n",
" <td>19.82</td>\n",
" <td>3.18</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25</th>\n",
" <td>17.81</td>\n",
" <td>2.34</td>\n",
" </tr>\n",
" <tr>\n",
" <th>26</th>\n",
" <td>13.37</td>\n",
" <td>2.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>27</th>\n",
" <td>12.69</td>\n",
" <td>2.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>28</th>\n",
" <td>21.70</td>\n",
" <td>4.30</td>\n",
" </tr>\n",
" <tr>\n",
" <th>29</th>\n",
" <td>19.65</td>\n",
" <td>3.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>214</th>\n",
" <td>28.17</td>\n",
" <td>6.50</td>\n",
" </tr>\n",
" <tr>\n",
" <th>215</th>\n",
" <td>12.90</td>\n",
" <td>1.10</td>\n",
" </tr>\n",
" <tr>\n",
" <th>216</th>\n",
" <td>28.15</td>\n",
" <td>3.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>217</th>\n",
" <td>11.59</td>\n",
" <td>1.50</td>\n",
" </tr>\n",
" <tr>\n",
" <th>218</th>\n",
" <td>7.74</td>\n",
" <td>1.44</td>\n",
" </tr>\n",
" <tr>\n",
" <th>219</th>\n",
" <td>30.14</td>\n",
" <td>3.09</td>\n",
" </tr>\n",
" <tr>\n",
" <th>220</th>\n",
" <td>12.16</td>\n",
" <td>2.20</td>\n",
" </tr>\n",
" <tr>\n",
" <th>221</th>\n",
" <td>13.42</td>\n",
" <td>3.48</td>\n",
" </tr>\n",
" <tr>\n",
" <th>222</th>\n",
" <td>8.58</td>\n",
" <td>1.92</td>\n",
" </tr>\n",
" <tr>\n",
" <th>223</th>\n",
" <td>15.98</td>\n",
" <td>3.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>224</th>\n",
" <td>13.42</td>\n",
" <td>1.58</td>\n",
" </tr>\n",
" <tr>\n",
" <th>225</th>\n",
" <td>16.27</td>\n",
" <td>2.50</td>\n",
" </tr>\n",
" <tr>\n",
" <th>226</th>\n",
" <td>10.09</td>\n",
" <td>2.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>227</th>\n",
" <td>20.45</td>\n",
" <td>3.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>228</th>\n",
" <td>13.28</td>\n",
" <td>2.72</td>\n",
" </tr>\n",
" <tr>\n",
" <th>229</th>\n",
" <td>22.12</td>\n",
" <td>2.88</td>\n",
" </tr>\n",
" <tr>\n",
" <th>230</th>\n",
" <td>24.01</td>\n",
" <td>2.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>231</th>\n",
" <td>15.69</td>\n",
" <td>3.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>232</th>\n",
" <td>11.61</td>\n",
" <td>3.39</td>\n",
" </tr>\n",
" <tr>\n",
" <th>233</th>\n",
" <td>10.77</td>\n",
" <td>1.47</td>\n",
" </tr>\n",
" <tr>\n",
" <th>234</th>\n",
" <td>15.53</td>\n",
" <td>3.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>235</th>\n",
" <td>10.07</td>\n",
" <td>1.25</td>\n",
" </tr>\n",
" <tr>\n",
" <th>236</th>\n",
" <td>12.60</td>\n",
" <td>1.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>237</th>\n",
" <td>32.83</td>\n",
" <td>1.17</td>\n",
" </tr>\n",
" <tr>\n",
" <th>238</th>\n",
" <td>35.83</td>\n",
" <td>4.67</td>\n",
" </tr>\n",
" <tr>\n",
" <th>239</th>\n",
" <td>29.03</td>\n",
" <td>5.92</td>\n",
" </tr>\n",
" <tr>\n",
" <th>240</th>\n",
" <td>27.18</td>\n",
" <td>2.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>241</th>\n",
" <td>22.67</td>\n",
" <td>2.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>242</th>\n",
" <td>17.82</td>\n",
" <td>1.75</td>\n",
" </tr>\n",
" <tr>\n",
" <th>243</th>\n",
" <td>18.78</td>\n",
" <td>3.00</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>244 rows × 2 columns</p>\n",
"</div>"
],
"text/plain": [
" total_bill tip\n",
"0 16.99 1.01\n",
"1 10.34 1.66\n",
"2 21.01 3.50\n",
"3 23.68 3.31\n",
"4 24.59 3.61\n",
"5 25.29 4.71\n",
"6 8.77 2.00\n",
"7 26.88 3.12\n",
"8 15.04 1.96\n",
"9 14.78 3.23\n",
"10 10.27 1.71\n",
"11 35.26 5.00\n",
"12 15.42 1.57\n",
"13 18.43 3.00\n",
"14 14.83 3.02\n",
"15 21.58 3.92\n",
"16 10.33 1.67\n",
"17 16.29 3.71\n",
"18 16.97 3.50\n",
"19 20.65 3.35\n",
"20 17.92 4.08\n",
"21 20.29 2.75\n",
"22 15.77 2.23\n",
"23 39.42 7.58\n",
"24 19.82 3.18\n",
"25 17.81 2.34\n",
"26 13.37 2.00\n",
"27 12.69 2.00\n",
"28 21.70 4.30\n",
"29 19.65 3.00\n",
".. ... ...\n",
"214 28.17 6.50\n",
"215 12.90 1.10\n",
"216 28.15 3.00\n",
"217 11.59 1.50\n",
"218 7.74 1.44\n",
"219 30.14 3.09\n",
"220 12.16 2.20\n",
"221 13.42 3.48\n",
"222 8.58 1.92\n",
"223 15.98 3.00\n",
"224 13.42 1.58\n",
"225 16.27 2.50\n",
"226 10.09 2.00\n",
"227 20.45 3.00\n",
"228 13.28 2.72\n",
"229 22.12 2.88\n",
"230 24.01 2.00\n",
"231 15.69 3.00\n",
"232 11.61 3.39\n",
"233 10.77 1.47\n",
"234 15.53 3.00\n",
"235 10.07 1.25\n",
"236 12.60 1.00\n",
"237 32.83 1.17\n",
"238 35.83 4.67\n",
"239 29.03 5.92\n",
"240 27.18 2.00\n",
"241 22.67 2.00\n",
"242 17.82 1.75\n",
"243 18.78 3.00\n",
"\n",
"[244 rows x 2 columns]"
]
},
"execution_count": 53,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Note how its a python list of column names! Thus the double brackets.\n",
"df[['total_bill','tip']]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Create New Columns"
]
},
{
"cell_type": "code",
"execution_count": 54,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"df['tip_percentage'] = 100* df['tip'] / df['total_bill']"
]
},
{
"cell_type": "code",
"execution_count": 55,
"metadata": {},
"outputs": [
{
"data": {
"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>total_bill</th>\n",
" <th>tip</th>\n",
" <th>sex</th>\n",
" <th>smoker</th>\n",
" <th>day</th>\n",
" <th>time</th>\n",
" <th>size</th>\n",
" <th>price_per_person</th>\n",
" <th>Payer Name</th>\n",
" <th>CC Number</th>\n",
" <th>Payment ID</th>\n",
" <th>tip_percentage</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>16.99</td>\n",
" <td>1.01</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>8.49</td>\n",
" <td>Christy Cunningham</td>\n",
" <td>3560325168603410</td>\n",
" <td>Sun2959</td>\n",
" <td>5.944673</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>10.34</td>\n",
" <td>1.66</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>3.45</td>\n",
" <td>Douglas Tucker</td>\n",
" <td>4478071379779230</td>\n",
" <td>Sun4608</td>\n",
" <td>16.054159</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>21.01</td>\n",
" <td>3.50</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>7.00</td>\n",
" <td>Travis Walters</td>\n",
" <td>6011812112971322</td>\n",
" <td>Sun4458</td>\n",
" <td>16.658734</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>23.68</td>\n",
" <td>3.31</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>11.84</td>\n",
" <td>Nathaniel Harris</td>\n",
" <td>4676137647685994</td>\n",
" <td>Sun5260</td>\n",
" <td>13.978041</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>24.59</td>\n",
" <td>3.61</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>4</td>\n",
" <td>6.15</td>\n",
" <td>Tonya Carter</td>\n",
" <td>4832732618637221</td>\n",
" <td>Sun2251</td>\n",
" <td>14.680765</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" total_bill tip sex smoker day time size price_per_person \\\n",
"0 16.99 1.01 Female No Sun Dinner 2 8.49 \n",
"1 10.34 1.66 Male No Sun Dinner 3 3.45 \n",
"2 21.01 3.50 Male No Sun Dinner 3 7.00 \n",
"3 23.68 3.31 Male No Sun Dinner 2 11.84 \n",
"4 24.59 3.61 Female No Sun Dinner 4 6.15 \n",
"\n",
" Payer Name CC Number Payment ID tip_percentage \n",
"0 Christy Cunningham 3560325168603410 Sun2959 5.944673 \n",
"1 Douglas Tucker 4478071379779230 Sun4608 16.054159 \n",
"2 Travis Walters 6011812112971322 Sun4458 16.658734 \n",
"3 Nathaniel Harris 4676137647685994 Sun5260 13.978041 \n",
"4 Tonya Carter 4832732618637221 Sun2251 14.680765 "
]
},
"execution_count": 55,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": 56,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"df['price_per_person'] = df['total_bill'] / df['size']"
]
},
{
"cell_type": "code",
"execution_count": 57,
"metadata": {},
"outputs": [
{
"data": {
"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>total_bill</th>\n",
" <th>tip</th>\n",
" <th>sex</th>\n",
" <th>smoker</th>\n",
" <th>day</th>\n",
" <th>time</th>\n",
" <th>size</th>\n",
" <th>price_per_person</th>\n",
" <th>Payer Name</th>\n",
" <th>CC Number</th>\n",
" <th>Payment ID</th>\n",
" <th>tip_percentage</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>16.99</td>\n",
" <td>1.01</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>8.495000</td>\n",
" <td>Christy Cunningham</td>\n",
" <td>3560325168603410</td>\n",
" <td>Sun2959</td>\n",
" <td>5.944673</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>10.34</td>\n",
" <td>1.66</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>3.446667</td>\n",
" <td>Douglas Tucker</td>\n",
" <td>4478071379779230</td>\n",
" <td>Sun4608</td>\n",
" <td>16.054159</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>21.01</td>\n",
" <td>3.50</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>7.003333</td>\n",
" <td>Travis Walters</td>\n",
" <td>6011812112971322</td>\n",
" <td>Sun4458</td>\n",
" <td>16.658734</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>23.68</td>\n",
" <td>3.31</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>11.840000</td>\n",
" <td>Nathaniel Harris</td>\n",
" <td>4676137647685994</td>\n",
" <td>Sun5260</td>\n",
" <td>13.978041</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>24.59</td>\n",
" <td>3.61</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>4</td>\n",
" <td>6.147500</td>\n",
" <td>Tonya Carter</td>\n",
" <td>4832732618637221</td>\n",
" <td>Sun2251</td>\n",
" <td>14.680765</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" total_bill tip sex smoker day time size price_per_person \\\n",
"0 16.99 1.01 Female No Sun Dinner 2 8.495000 \n",
"1 10.34 1.66 Male No Sun Dinner 3 3.446667 \n",
"2 21.01 3.50 Male No Sun Dinner 3 7.003333 \n",
"3 23.68 3.31 Male No Sun Dinner 2 11.840000 \n",
"4 24.59 3.61 Female No Sun Dinner 4 6.147500 \n",
"\n",
" Payer Name CC Number Payment ID tip_percentage \n",
"0 Christy Cunningham 3560325168603410 Sun2959 5.944673 \n",
"1 Douglas Tucker 4478071379779230 Sun4608 16.054159 \n",
"2 Travis Walters 6011812112971322 Sun4458 16.658734 \n",
"3 Nathaniel Harris 4676137647685994 Sun5260 13.978041 \n",
"4 Tonya Carter 4832732618637221 Sun2251 14.680765 "
]
},
"execution_count": 57,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": 58,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Help on function round_ in module numpy:\n",
"\n",
"round_(a, decimals=0, out=None)\n",
" Round an array to the given number of decimals.\n",
" \n",
" See Also\n",
" --------\n",
" around : equivalent function; see for details.\n",
"\n"
]
}
],
"source": [
"help(np.round)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Adjust Existing Columns"
]
},
{
"cell_type": "code",
"execution_count": 59,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Because pandas is based on numpy, we get awesome capabilities with numpy's universal functions!\n",
"df['price_per_person'] = np.round(df['price_per_person'],2)"
]
},
{
"cell_type": "code",
"execution_count": 60,
"metadata": {},
"outputs": [
{
"data": {
"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>total_bill</th>\n",
" <th>tip</th>\n",
" <th>sex</th>\n",
" <th>smoker</th>\n",
" <th>day</th>\n",
" <th>time</th>\n",
" <th>size</th>\n",
" <th>price_per_person</th>\n",
" <th>Payer Name</th>\n",
" <th>CC Number</th>\n",
" <th>Payment ID</th>\n",
" <th>tip_percentage</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>16.99</td>\n",
" <td>1.01</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>8.49</td>\n",
" <td>Christy Cunningham</td>\n",
" <td>3560325168603410</td>\n",
" <td>Sun2959</td>\n",
" <td>5.944673</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>10.34</td>\n",
" <td>1.66</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>3.45</td>\n",
" <td>Douglas Tucker</td>\n",
" <td>4478071379779230</td>\n",
" <td>Sun4608</td>\n",
" <td>16.054159</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>21.01</td>\n",
" <td>3.50</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>7.00</td>\n",
" <td>Travis Walters</td>\n",
" <td>6011812112971322</td>\n",
" <td>Sun4458</td>\n",
" <td>16.658734</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>23.68</td>\n",
" <td>3.31</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>11.84</td>\n",
" <td>Nathaniel Harris</td>\n",
" <td>4676137647685994</td>\n",
" <td>Sun5260</td>\n",
" <td>13.978041</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>24.59</td>\n",
" <td>3.61</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>4</td>\n",
" <td>6.15</td>\n",
" <td>Tonya Carter</td>\n",
" <td>4832732618637221</td>\n",
" <td>Sun2251</td>\n",
" <td>14.680765</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" total_bill tip sex smoker day time size price_per_person \\\n",
"0 16.99 1.01 Female No Sun Dinner 2 8.49 \n",
"1 10.34 1.66 Male No Sun Dinner 3 3.45 \n",
"2 21.01 3.50 Male No Sun Dinner 3 7.00 \n",
"3 23.68 3.31 Male No Sun Dinner 2 11.84 \n",
"4 24.59 3.61 Female No Sun Dinner 4 6.15 \n",
"\n",
" Payer Name CC Number Payment ID tip_percentage \n",
"0 Christy Cunningham 3560325168603410 Sun2959 5.944673 \n",
"1 Douglas Tucker 4478071379779230 Sun4608 16.054159 \n",
"2 Travis Walters 6011812112971322 Sun4458 16.658734 \n",
"3 Nathaniel Harris 4676137647685994 Sun5260 13.978041 \n",
"4 Tonya Carter 4832732618637221 Sun2251 14.680765 "
]
},
"execution_count": 60,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Remove Columns"
]
},
{
"cell_type": "code",
"execution_count": 61,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# df.drop('tip_percentage',axis=1)"
]
},
{
"cell_type": "code",
"execution_count": 62,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"df = df.drop(\"tip_percentage\",axis=1)"
]
},
{
"cell_type": "code",
"execution_count": 63,
"metadata": {},
"outputs": [
{
"data": {
"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>total_bill</th>\n",
" <th>tip</th>\n",
" <th>sex</th>\n",
" <th>smoker</th>\n",
" <th>day</th>\n",
" <th>time</th>\n",
" <th>size</th>\n",
" <th>price_per_person</th>\n",
" <th>Payer Name</th>\n",
" <th>CC Number</th>\n",
" <th>Payment ID</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>16.99</td>\n",
" <td>1.01</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>8.49</td>\n",
" <td>Christy Cunningham</td>\n",
" <td>3560325168603410</td>\n",
" <td>Sun2959</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>10.34</td>\n",
" <td>1.66</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>3.45</td>\n",
" <td>Douglas Tucker</td>\n",
" <td>4478071379779230</td>\n",
" <td>Sun4608</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>21.01</td>\n",
" <td>3.50</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>7.00</td>\n",
" <td>Travis Walters</td>\n",
" <td>6011812112971322</td>\n",
" <td>Sun4458</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>23.68</td>\n",
" <td>3.31</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>11.84</td>\n",
" <td>Nathaniel Harris</td>\n",
" <td>4676137647685994</td>\n",
" <td>Sun5260</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>24.59</td>\n",
" <td>3.61</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>4</td>\n",
" <td>6.15</td>\n",
" <td>Tonya Carter</td>\n",
" <td>4832732618637221</td>\n",
" <td>Sun2251</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" total_bill tip sex smoker day time size price_per_person \\\n",
"0 16.99 1.01 Female No Sun Dinner 2 8.49 \n",
"1 10.34 1.66 Male No Sun Dinner 3 3.45 \n",
"2 21.01 3.50 Male No Sun Dinner 3 7.00 \n",
"3 23.68 3.31 Male No Sun Dinner 2 11.84 \n",
"4 24.59 3.61 Female No Sun Dinner 4 6.15 \n",
"\n",
" Payer Name CC Number Payment ID \n",
"0 Christy Cunningham 3560325168603410 Sun2959 \n",
"1 Douglas Tucker 4478071379779230 Sun4608 \n",
"2 Travis Walters 6011812112971322 Sun4458 \n",
"3 Nathaniel Harris 4676137647685994 Sun5260 \n",
"4 Tonya Carter 4832732618637221 Sun2251 "
]
},
"execution_count": 63,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Index Basics\n",
"\n",
"Before going over the same retrieval tasks for rows, let's build some basic understanding of the pandas DataFrame Index."
]
},
{
"cell_type": "code",
"execution_count": 64,
"metadata": {},
"outputs": [
{
"data": {
"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>total_bill</th>\n",
" <th>tip</th>\n",
" <th>sex</th>\n",
" <th>smoker</th>\n",
" <th>day</th>\n",
" <th>time</th>\n",
" <th>size</th>\n",
" <th>price_per_person</th>\n",
" <th>Payer Name</th>\n",
" <th>CC Number</th>\n",
" <th>Payment ID</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>16.99</td>\n",
" <td>1.01</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>8.49</td>\n",
" <td>Christy Cunningham</td>\n",
" <td>3560325168603410</td>\n",
" <td>Sun2959</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>10.34</td>\n",
" <td>1.66</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>3.45</td>\n",
" <td>Douglas Tucker</td>\n",
" <td>4478071379779230</td>\n",
" <td>Sun4608</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>21.01</td>\n",
" <td>3.50</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>7.00</td>\n",
" <td>Travis Walters</td>\n",
" <td>6011812112971322</td>\n",
" <td>Sun4458</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>23.68</td>\n",
" <td>3.31</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>11.84</td>\n",
" <td>Nathaniel Harris</td>\n",
" <td>4676137647685994</td>\n",
" <td>Sun5260</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>24.59</td>\n",
" <td>3.61</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>4</td>\n",
" <td>6.15</td>\n",
" <td>Tonya Carter</td>\n",
" <td>4832732618637221</td>\n",
" <td>Sun2251</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" total_bill tip sex smoker day time size price_per_person \\\n",
"0 16.99 1.01 Female No Sun Dinner 2 8.49 \n",
"1 10.34 1.66 Male No Sun Dinner 3 3.45 \n",
"2 21.01 3.50 Male No Sun Dinner 3 7.00 \n",
"3 23.68 3.31 Male No Sun Dinner 2 11.84 \n",
"4 24.59 3.61 Female No Sun Dinner 4 6.15 \n",
"\n",
" Payer Name CC Number Payment ID \n",
"0 Christy Cunningham 3560325168603410 Sun2959 \n",
"1 Douglas Tucker 4478071379779230 Sun4608 \n",
"2 Travis Walters 6011812112971322 Sun4458 \n",
"3 Nathaniel Harris 4676137647685994 Sun5260 \n",
"4 Tonya Carter 4832732618637221 Sun2251 "
]
},
"execution_count": 64,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": 65,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"RangeIndex(start=0, stop=244, step=1)"
]
},
"execution_count": 65,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.index"
]
},
{
"cell_type": "code",
"execution_count": 66,
"metadata": {},
"outputs": [
{
"data": {
"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>total_bill</th>\n",
" <th>tip</th>\n",
" <th>sex</th>\n",
" <th>smoker</th>\n",
" <th>day</th>\n",
" <th>time</th>\n",
" <th>size</th>\n",
" <th>price_per_person</th>\n",
" <th>Payer Name</th>\n",
" <th>CC Number</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Payment ID</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Sun2959</th>\n",
" <td>16.99</td>\n",
" <td>1.01</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>8.49</td>\n",
" <td>Christy Cunningham</td>\n",
" <td>3560325168603410</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun4608</th>\n",
" <td>10.34</td>\n",
" <td>1.66</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>3.45</td>\n",
" <td>Douglas Tucker</td>\n",
" <td>4478071379779230</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun4458</th>\n",
" <td>21.01</td>\n",
" <td>3.50</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>7.00</td>\n",
" <td>Travis Walters</td>\n",
" <td>6011812112971322</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun5260</th>\n",
" <td>23.68</td>\n",
" <td>3.31</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>11.84</td>\n",
" <td>Nathaniel Harris</td>\n",
" <td>4676137647685994</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun2251</th>\n",
" <td>24.59</td>\n",
" <td>3.61</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>4</td>\n",
" <td>6.15</td>\n",
" <td>Tonya Carter</td>\n",
" <td>4832732618637221</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun9679</th>\n",
" <td>25.29</td>\n",
" <td>4.71</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>4</td>\n",
" <td>6.32</td>\n",
" <td>Erik Smith</td>\n",
" <td>213140353657882</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun5985</th>\n",
" <td>8.77</td>\n",
" <td>2.00</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>4.38</td>\n",
" <td>Kristopher Johnson</td>\n",
" <td>2223727524230344</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun8157</th>\n",
" <td>26.88</td>\n",
" <td>3.12</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>4</td>\n",
" <td>6.72</td>\n",
" <td>Robert Buck</td>\n",
" <td>3514785077705092</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun6820</th>\n",
" <td>15.04</td>\n",
" <td>1.96</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>7.52</td>\n",
" <td>Joseph Mcdonald</td>\n",
" <td>3522866365840377</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun3775</th>\n",
" <td>14.78</td>\n",
" <td>3.23</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>7.39</td>\n",
" <td>Jerome Abbott</td>\n",
" <td>3532124519049786</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun2546</th>\n",
" <td>10.27</td>\n",
" <td>1.71</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>5.14</td>\n",
" <td>William Riley</td>\n",
" <td>566287581219</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun6686</th>\n",
" <td>35.26</td>\n",
" <td>5.00</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>4</td>\n",
" <td>8.82</td>\n",
" <td>Diane Macias</td>\n",
" <td>4577817359320969</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun1300</th>\n",
" <td>15.42</td>\n",
" <td>1.57</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>7.71</td>\n",
" <td>Chad Harrington</td>\n",
" <td>577040572932</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun2971</th>\n",
" <td>18.43</td>\n",
" <td>3.00</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>4</td>\n",
" <td>4.61</td>\n",
" <td>Joshua Jones</td>\n",
" <td>6011163105616890</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun3848</th>\n",
" <td>14.83</td>\n",
" <td>3.02</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>7.42</td>\n",
" <td>Vanessa Jones</td>\n",
" <td>30016702287574</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun1878</th>\n",
" <td>21.58</td>\n",
" <td>3.92</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>10.79</td>\n",
" <td>Matthew Reilly</td>\n",
" <td>180073029785069</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun9715</th>\n",
" <td>10.33</td>\n",
" <td>1.67</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>3.44</td>\n",
" <td>Elizabeth Foster</td>\n",
" <td>4240025044626033</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun2998</th>\n",
" <td>16.29</td>\n",
" <td>3.71</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>5.43</td>\n",
" <td>John Pittman</td>\n",
" <td>6521340257218708</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun2789</th>\n",
" <td>16.97</td>\n",
" <td>3.50</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>5.66</td>\n",
" <td>Laura Martinez</td>\n",
" <td>30422275171379</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat9213</th>\n",
" <td>20.65</td>\n",
" <td>3.35</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>6.88</td>\n",
" <td>Timothy Oneal</td>\n",
" <td>6568069240986485</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat1709</th>\n",
" <td>17.92</td>\n",
" <td>4.08</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>8.96</td>\n",
" <td>Thomas Rice</td>\n",
" <td>4403296224639756</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat9618</th>\n",
" <td>20.29</td>\n",
" <td>2.75</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>10.14</td>\n",
" <td>Natalie Gardner</td>\n",
" <td>5448125351489749</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat9786</th>\n",
" <td>15.77</td>\n",
" <td>2.23</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>7.88</td>\n",
" <td>Ashley Shelton</td>\n",
" <td>3524119516293213</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat239</th>\n",
" <td>39.42</td>\n",
" <td>7.58</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>4</td>\n",
" <td>9.86</td>\n",
" <td>Lance Peterson</td>\n",
" <td>3542584061609808</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat6236</th>\n",
" <td>19.82</td>\n",
" <td>3.18</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>9.91</td>\n",
" <td>Christopher Ross</td>\n",
" <td>36739148167928</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat907</th>\n",
" <td>17.81</td>\n",
" <td>2.34</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>4</td>\n",
" <td>4.45</td>\n",
" <td>Robert Perkins</td>\n",
" <td>30502930499388</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat6651</th>\n",
" <td>13.37</td>\n",
" <td>2.00</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>6.68</td>\n",
" <td>Kyle Avery</td>\n",
" <td>6531339539615499</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat394</th>\n",
" <td>12.69</td>\n",
" <td>2.00</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>6.34</td>\n",
" <td>Patrick Barber</td>\n",
" <td>30155551880343</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat3697</th>\n",
" <td>21.70</td>\n",
" <td>4.30</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>10.85</td>\n",
" <td>David Collier</td>\n",
" <td>5529694315416009</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat2467</th>\n",
" <td>19.65</td>\n",
" <td>3.00</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>9.82</td>\n",
" <td>Melinda Murphy</td>\n",
" <td>5489272944576051</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",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat3374</th>\n",
" <td>28.17</td>\n",
" <td>6.50</td>\n",
" <td>Female</td>\n",
" <td>Yes</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>9.39</td>\n",
" <td>Marissa Jackson</td>\n",
" <td>4922302538691962</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat6983</th>\n",
" <td>12.90</td>\n",
" <td>1.10</td>\n",
" <td>Female</td>\n",
" <td>Yes</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>6.45</td>\n",
" <td>Jessica Owen</td>\n",
" <td>4726904879471</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat7320</th>\n",
" <td>28.15</td>\n",
" <td>3.00</td>\n",
" <td>Male</td>\n",
" <td>Yes</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>5</td>\n",
" <td>5.63</td>\n",
" <td>Shawn Barnett PhD</td>\n",
" <td>4590982568244</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat8489</th>\n",
" <td>11.59</td>\n",
" <td>1.50</td>\n",
" <td>Male</td>\n",
" <td>Yes</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>5.80</td>\n",
" <td>Gary Orr</td>\n",
" <td>30324521283406</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat4772</th>\n",
" <td>7.74</td>\n",
" <td>1.44</td>\n",
" <td>Male</td>\n",
" <td>Yes</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>3.87</td>\n",
" <td>Nicholas Archer</td>\n",
" <td>340517153733524</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat8863</th>\n",
" <td>30.14</td>\n",
" <td>3.09</td>\n",
" <td>Female</td>\n",
" <td>Yes</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>4</td>\n",
" <td>7.54</td>\n",
" <td>Shelby House</td>\n",
" <td>502097403252</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Fri4607</th>\n",
" <td>12.16</td>\n",
" <td>2.20</td>\n",
" <td>Male</td>\n",
" <td>Yes</td>\n",
" <td>Fri</td>\n",
" <td>Lunch</td>\n",
" <td>2</td>\n",
" <td>6.08</td>\n",
" <td>Ricky Johnson</td>\n",
" <td>213109508670736</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Fri7511</th>\n",
" <td>13.42</td>\n",
" <td>3.48</td>\n",
" <td>Female</td>\n",
" <td>Yes</td>\n",
" <td>Fri</td>\n",
" <td>Lunch</td>\n",
" <td>2</td>\n",
" <td>6.71</td>\n",
" <td>Leslie Kaufman</td>\n",
" <td>379437981958785</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Fri6624</th>\n",
" <td>8.58</td>\n",
" <td>1.92</td>\n",
" <td>Male</td>\n",
" <td>Yes</td>\n",
" <td>Fri</td>\n",
" <td>Lunch</td>\n",
" <td>1</td>\n",
" <td>8.58</td>\n",
" <td>Jason Lawrence</td>\n",
" <td>3505302934650403</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Fri6014</th>\n",
" <td>15.98</td>\n",
" <td>3.00</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Fri</td>\n",
" <td>Lunch</td>\n",
" <td>3</td>\n",
" <td>5.33</td>\n",
" <td>Mary Rivera</td>\n",
" <td>5343428579353069</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Fri5959</th>\n",
" <td>13.42</td>\n",
" <td>1.58</td>\n",
" <td>Male</td>\n",
" <td>Yes</td>\n",
" <td>Fri</td>\n",
" <td>Lunch</td>\n",
" <td>2</td>\n",
" <td>6.71</td>\n",
" <td>Ronald Vaughn DVM</td>\n",
" <td>341503466406403</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Fri6665</th>\n",
" <td>16.27</td>\n",
" <td>2.50</td>\n",
" <td>Female</td>\n",
" <td>Yes</td>\n",
" <td>Fri</td>\n",
" <td>Lunch</td>\n",
" <td>2</td>\n",
" <td>8.14</td>\n",
" <td>Whitney Arnold</td>\n",
" <td>3579111947217428</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Fri6359</th>\n",
" <td>10.09</td>\n",
" <td>2.00</td>\n",
" <td>Female</td>\n",
" <td>Yes</td>\n",
" <td>Fri</td>\n",
" <td>Lunch</td>\n",
" <td>2</td>\n",
" <td>5.04</td>\n",
" <td>Ruth Weiss</td>\n",
" <td>5268689490381635</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat4319</th>\n",
" <td>20.45</td>\n",
" <td>3.00</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>4</td>\n",
" <td>5.11</td>\n",
" <td>Robert Bradley</td>\n",
" <td>213141668145910</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat2937</th>\n",
" <td>13.28</td>\n",
" <td>2.72</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>6.64</td>\n",
" <td>Glenn Jones</td>\n",
" <td>502061651712</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat3943</th>\n",
" <td>22.12</td>\n",
" <td>2.88</td>\n",
" <td>Female</td>\n",
" <td>Yes</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>11.06</td>\n",
" <td>Jennifer Russell</td>\n",
" <td>4793003293608</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat7872</th>\n",
" <td>24.01</td>\n",
" <td>2.00</td>\n",
" <td>Male</td>\n",
" <td>Yes</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>4</td>\n",
" <td>6.00</td>\n",
" <td>Michael Osborne</td>\n",
" <td>4258682154026</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat6334</th>\n",
" <td>15.69</td>\n",
" <td>3.00</td>\n",
" <td>Male</td>\n",
" <td>Yes</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>5.23</td>\n",
" <td>Jason Parks</td>\n",
" <td>4812333796161</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat2124</th>\n",
" <td>11.61</td>\n",
" <td>3.39</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>5.80</td>\n",
" <td>James Taylor</td>\n",
" <td>6011482917327995</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat1467</th>\n",
" <td>10.77</td>\n",
" <td>1.47</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>5.38</td>\n",
" <td>Paul Novak</td>\n",
" <td>6011698897610858</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat7220</th>\n",
" <td>15.53</td>\n",
" <td>3.00</td>\n",
" <td>Male</td>\n",
" <td>Yes</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>7.76</td>\n",
" <td>Tracy Douglas</td>\n",
" <td>4097938155941930</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat4615</th>\n",
" <td>10.07</td>\n",
" <td>1.25</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>5.04</td>\n",
" <td>Sean Gonzalez</td>\n",
" <td>3534021246117605</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat5032</th>\n",
" <td>12.60</td>\n",
" <td>1.00</td>\n",
" <td>Male</td>\n",
" <td>Yes</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>6.30</td>\n",
" <td>Matthew Myers</td>\n",
" <td>3543676378973965</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat2929</th>\n",
" <td>32.83</td>\n",
" <td>1.17</td>\n",
" <td>Male</td>\n",
" <td>Yes</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>16.42</td>\n",
" <td>Thomas Brown</td>\n",
" <td>4284722681265508</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat9777</th>\n",
" <td>35.83</td>\n",
" <td>4.67</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>11.94</td>\n",
" <td>Kimberly Crane</td>\n",
" <td>676184013727</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat2657</th>\n",
" <td>29.03</td>\n",
" <td>5.92</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>9.68</td>\n",
" <td>Michael Avila</td>\n",
" <td>5296068606052842</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat1766</th>\n",
" <td>27.18</td>\n",
" <td>2.00</td>\n",
" <td>Female</td>\n",
" <td>Yes</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>13.59</td>\n",
" <td>Monica Sanders</td>\n",
" <td>3506806155565404</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat3880</th>\n",
" <td>22.67</td>\n",
" <td>2.00</td>\n",
" <td>Male</td>\n",
" <td>Yes</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>11.34</td>\n",
" <td>Keith Wong</td>\n",
" <td>6011891618747196</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat17</th>\n",
" <td>17.82</td>\n",
" <td>1.75</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>8.91</td>\n",
" <td>Dennis Dixon</td>\n",
" <td>4375220550950</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Thur672</th>\n",
" <td>18.78</td>\n",
" <td>3.00</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Thur</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>9.39</td>\n",
" <td>Michelle Hardin</td>\n",
" <td>3511451626698139</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>244 rows × 10 columns</p>\n",
"</div>"
],
"text/plain": [
" total_bill tip sex smoker day time size \\\n",
"Payment ID \n",
"Sun2959 16.99 1.01 Female No Sun Dinner 2 \n",
"Sun4608 10.34 1.66 Male No Sun Dinner 3 \n",
"Sun4458 21.01 3.50 Male No Sun Dinner 3 \n",
"Sun5260 23.68 3.31 Male No Sun Dinner 2 \n",
"Sun2251 24.59 3.61 Female No Sun Dinner 4 \n",
"Sun9679 25.29 4.71 Male No Sun Dinner 4 \n",
"Sun5985 8.77 2.00 Male No Sun Dinner 2 \n",
"Sun8157 26.88 3.12 Male No Sun Dinner 4 \n",
"Sun6820 15.04 1.96 Male No Sun Dinner 2 \n",
"Sun3775 14.78 3.23 Male No Sun Dinner 2 \n",
"Sun2546 10.27 1.71 Male No Sun Dinner 2 \n",
"Sun6686 35.26 5.00 Female No Sun Dinner 4 \n",
"Sun1300 15.42 1.57 Male No Sun Dinner 2 \n",
"Sun2971 18.43 3.00 Male No Sun Dinner 4 \n",
"Sun3848 14.83 3.02 Female No Sun Dinner 2 \n",
"Sun1878 21.58 3.92 Male No Sun Dinner 2 \n",
"Sun9715 10.33 1.67 Female No Sun Dinner 3 \n",
"Sun2998 16.29 3.71 Male No Sun Dinner 3 \n",
"Sun2789 16.97 3.50 Female No Sun Dinner 3 \n",
"Sat9213 20.65 3.35 Male No Sat Dinner 3 \n",
"Sat1709 17.92 4.08 Male No Sat Dinner 2 \n",
"Sat9618 20.29 2.75 Female No Sat Dinner 2 \n",
"Sat9786 15.77 2.23 Female No Sat Dinner 2 \n",
"Sat239 39.42 7.58 Male No Sat Dinner 4 \n",
"Sat6236 19.82 3.18 Male No Sat Dinner 2 \n",
"Sat907 17.81 2.34 Male No Sat Dinner 4 \n",
"Sat6651 13.37 2.00 Male No Sat Dinner 2 \n",
"Sat394 12.69 2.00 Male No Sat Dinner 2 \n",
"Sat3697 21.70 4.30 Male No Sat Dinner 2 \n",
"Sat2467 19.65 3.00 Female No Sat Dinner 2 \n",
"... ... ... ... ... ... ... ... \n",
"Sat3374 28.17 6.50 Female Yes Sat Dinner 3 \n",
"Sat6983 12.90 1.10 Female Yes Sat Dinner 2 \n",
"Sat7320 28.15 3.00 Male Yes Sat Dinner 5 \n",
"Sat8489 11.59 1.50 Male Yes Sat Dinner 2 \n",
"Sat4772 7.74 1.44 Male Yes Sat Dinner 2 \n",
"Sat8863 30.14 3.09 Female Yes Sat Dinner 4 \n",
"Fri4607 12.16 2.20 Male Yes Fri Lunch 2 \n",
"Fri7511 13.42 3.48 Female Yes Fri Lunch 2 \n",
"Fri6624 8.58 1.92 Male Yes Fri Lunch 1 \n",
"Fri6014 15.98 3.00 Female No Fri Lunch 3 \n",
"Fri5959 13.42 1.58 Male Yes Fri Lunch 2 \n",
"Fri6665 16.27 2.50 Female Yes Fri Lunch 2 \n",
"Fri6359 10.09 2.00 Female Yes Fri Lunch 2 \n",
"Sat4319 20.45 3.00 Male No Sat Dinner 4 \n",
"Sat2937 13.28 2.72 Male No Sat Dinner 2 \n",
"Sat3943 22.12 2.88 Female Yes Sat Dinner 2 \n",
"Sat7872 24.01 2.00 Male Yes Sat Dinner 4 \n",
"Sat6334 15.69 3.00 Male Yes Sat Dinner 3 \n",
"Sat2124 11.61 3.39 Male No Sat Dinner 2 \n",
"Sat1467 10.77 1.47 Male No Sat Dinner 2 \n",
"Sat7220 15.53 3.00 Male Yes Sat Dinner 2 \n",
"Sat4615 10.07 1.25 Male No Sat Dinner 2 \n",
"Sat5032 12.60 1.00 Male Yes Sat Dinner 2 \n",
"Sat2929 32.83 1.17 Male Yes Sat Dinner 2 \n",
"Sat9777 35.83 4.67 Female No Sat Dinner 3 \n",
"Sat2657 29.03 5.92 Male No Sat Dinner 3 \n",
"Sat1766 27.18 2.00 Female Yes Sat Dinner 2 \n",
"Sat3880 22.67 2.00 Male Yes Sat Dinner 2 \n",
"Sat17 17.82 1.75 Male No Sat Dinner 2 \n",
"Thur672 18.78 3.00 Female No Thur Dinner 2 \n",
"\n",
" price_per_person Payer Name CC Number \n",
"Payment ID \n",
"Sun2959 8.49 Christy Cunningham 3560325168603410 \n",
"Sun4608 3.45 Douglas Tucker 4478071379779230 \n",
"Sun4458 7.00 Travis Walters 6011812112971322 \n",
"Sun5260 11.84 Nathaniel Harris 4676137647685994 \n",
"Sun2251 6.15 Tonya Carter 4832732618637221 \n",
"Sun9679 6.32 Erik Smith 213140353657882 \n",
"Sun5985 4.38 Kristopher Johnson 2223727524230344 \n",
"Sun8157 6.72 Robert Buck 3514785077705092 \n",
"Sun6820 7.52 Joseph Mcdonald 3522866365840377 \n",
"Sun3775 7.39 Jerome Abbott 3532124519049786 \n",
"Sun2546 5.14 William Riley 566287581219 \n",
"Sun6686 8.82 Diane Macias 4577817359320969 \n",
"Sun1300 7.71 Chad Harrington 577040572932 \n",
"Sun2971 4.61 Joshua Jones 6011163105616890 \n",
"Sun3848 7.42 Vanessa Jones 30016702287574 \n",
"Sun1878 10.79 Matthew Reilly 180073029785069 \n",
"Sun9715 3.44 Elizabeth Foster 4240025044626033 \n",
"Sun2998 5.43 John Pittman 6521340257218708 \n",
"Sun2789 5.66 Laura Martinez 30422275171379 \n",
"Sat9213 6.88 Timothy Oneal 6568069240986485 \n",
"Sat1709 8.96 Thomas Rice 4403296224639756 \n",
"Sat9618 10.14 Natalie Gardner 5448125351489749 \n",
"Sat9786 7.88 Ashley Shelton 3524119516293213 \n",
"Sat239 9.86 Lance Peterson 3542584061609808 \n",
"Sat6236 9.91 Christopher Ross 36739148167928 \n",
"Sat907 4.45 Robert Perkins 30502930499388 \n",
"Sat6651 6.68 Kyle Avery 6531339539615499 \n",
"Sat394 6.34 Patrick Barber 30155551880343 \n",
"Sat3697 10.85 David Collier 5529694315416009 \n",
"Sat2467 9.82 Melinda Murphy 5489272944576051 \n",
"... ... ... ... \n",
"Sat3374 9.39 Marissa Jackson 4922302538691962 \n",
"Sat6983 6.45 Jessica Owen 4726904879471 \n",
"Sat7320 5.63 Shawn Barnett PhD 4590982568244 \n",
"Sat8489 5.80 Gary Orr 30324521283406 \n",
"Sat4772 3.87 Nicholas Archer 340517153733524 \n",
"Sat8863 7.54 Shelby House 502097403252 \n",
"Fri4607 6.08 Ricky Johnson 213109508670736 \n",
"Fri7511 6.71 Leslie Kaufman 379437981958785 \n",
"Fri6624 8.58 Jason Lawrence 3505302934650403 \n",
"Fri6014 5.33 Mary Rivera 5343428579353069 \n",
"Fri5959 6.71 Ronald Vaughn DVM 341503466406403 \n",
"Fri6665 8.14 Whitney Arnold 3579111947217428 \n",
"Fri6359 5.04 Ruth Weiss 5268689490381635 \n",
"Sat4319 5.11 Robert Bradley 213141668145910 \n",
"Sat2937 6.64 Glenn Jones 502061651712 \n",
"Sat3943 11.06 Jennifer Russell 4793003293608 \n",
"Sat7872 6.00 Michael Osborne 4258682154026 \n",
"Sat6334 5.23 Jason Parks 4812333796161 \n",
"Sat2124 5.80 James Taylor 6011482917327995 \n",
"Sat1467 5.38 Paul Novak 6011698897610858 \n",
"Sat7220 7.76 Tracy Douglas 4097938155941930 \n",
"Sat4615 5.04 Sean Gonzalez 3534021246117605 \n",
"Sat5032 6.30 Matthew Myers 3543676378973965 \n",
"Sat2929 16.42 Thomas Brown 4284722681265508 \n",
"Sat9777 11.94 Kimberly Crane 676184013727 \n",
"Sat2657 9.68 Michael Avila 5296068606052842 \n",
"Sat1766 13.59 Monica Sanders 3506806155565404 \n",
"Sat3880 11.34 Keith Wong 6011891618747196 \n",
"Sat17 8.91 Dennis Dixon 4375220550950 \n",
"Thur672 9.39 Michelle Hardin 3511451626698139 \n",
"\n",
"[244 rows x 10 columns]"
]
},
"execution_count": 66,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.set_index('Payment ID')"
]
},
{
"cell_type": "code",
"execution_count": 67,
"metadata": {},
"outputs": [
{
"data": {
"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>total_bill</th>\n",
" <th>tip</th>\n",
" <th>sex</th>\n",
" <th>smoker</th>\n",
" <th>day</th>\n",
" <th>time</th>\n",
" <th>size</th>\n",
" <th>price_per_person</th>\n",
" <th>Payer Name</th>\n",
" <th>CC Number</th>\n",
" <th>Payment ID</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>16.99</td>\n",
" <td>1.01</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>8.49</td>\n",
" <td>Christy Cunningham</td>\n",
" <td>3560325168603410</td>\n",
" <td>Sun2959</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>10.34</td>\n",
" <td>1.66</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>3.45</td>\n",
" <td>Douglas Tucker</td>\n",
" <td>4478071379779230</td>\n",
" <td>Sun4608</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>21.01</td>\n",
" <td>3.50</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>7.00</td>\n",
" <td>Travis Walters</td>\n",
" <td>6011812112971322</td>\n",
" <td>Sun4458</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>23.68</td>\n",
" <td>3.31</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>11.84</td>\n",
" <td>Nathaniel Harris</td>\n",
" <td>4676137647685994</td>\n",
" <td>Sun5260</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>24.59</td>\n",
" <td>3.61</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>4</td>\n",
" <td>6.15</td>\n",
" <td>Tonya Carter</td>\n",
" <td>4832732618637221</td>\n",
" <td>Sun2251</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" total_bill tip sex smoker day time size price_per_person \\\n",
"0 16.99 1.01 Female No Sun Dinner 2 8.49 \n",
"1 10.34 1.66 Male No Sun Dinner 3 3.45 \n",
"2 21.01 3.50 Male No Sun Dinner 3 7.00 \n",
"3 23.68 3.31 Male No Sun Dinner 2 11.84 \n",
"4 24.59 3.61 Female No Sun Dinner 4 6.15 \n",
"\n",
" Payer Name CC Number Payment ID \n",
"0 Christy Cunningham 3560325168603410 Sun2959 \n",
"1 Douglas Tucker 4478071379779230 Sun4608 \n",
"2 Travis Walters 6011812112971322 Sun4458 \n",
"3 Nathaniel Harris 4676137647685994 Sun5260 \n",
"4 Tonya Carter 4832732618637221 Sun2251 "
]
},
"execution_count": 67,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": 68,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"df = df.set_index('Payment ID')"
]
},
{
"cell_type": "code",
"execution_count": 69,
"metadata": {},
"outputs": [
{
"data": {
"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>total_bill</th>\n",
" <th>tip</th>\n",
" <th>sex</th>\n",
" <th>smoker</th>\n",
" <th>day</th>\n",
" <th>time</th>\n",
" <th>size</th>\n",
" <th>price_per_person</th>\n",
" <th>Payer Name</th>\n",
" <th>CC Number</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Payment ID</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Sun2959</th>\n",
" <td>16.99</td>\n",
" <td>1.01</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>8.49</td>\n",
" <td>Christy Cunningham</td>\n",
" <td>3560325168603410</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun4608</th>\n",
" <td>10.34</td>\n",
" <td>1.66</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>3.45</td>\n",
" <td>Douglas Tucker</td>\n",
" <td>4478071379779230</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun4458</th>\n",
" <td>21.01</td>\n",
" <td>3.50</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>7.00</td>\n",
" <td>Travis Walters</td>\n",
" <td>6011812112971322</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun5260</th>\n",
" <td>23.68</td>\n",
" <td>3.31</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>11.84</td>\n",
" <td>Nathaniel Harris</td>\n",
" <td>4676137647685994</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun2251</th>\n",
" <td>24.59</td>\n",
" <td>3.61</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>4</td>\n",
" <td>6.15</td>\n",
" <td>Tonya Carter</td>\n",
" <td>4832732618637221</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" total_bill tip sex smoker day time size \\\n",
"Payment ID \n",
"Sun2959 16.99 1.01 Female No Sun Dinner 2 \n",
"Sun4608 10.34 1.66 Male No Sun Dinner 3 \n",
"Sun4458 21.01 3.50 Male No Sun Dinner 3 \n",
"Sun5260 23.68 3.31 Male No Sun Dinner 2 \n",
"Sun2251 24.59 3.61 Female No Sun Dinner 4 \n",
"\n",
" price_per_person Payer Name CC Number \n",
"Payment ID \n",
"Sun2959 8.49 Christy Cunningham 3560325168603410 \n",
"Sun4608 3.45 Douglas Tucker 4478071379779230 \n",
"Sun4458 7.00 Travis Walters 6011812112971322 \n",
"Sun5260 11.84 Nathaniel Harris 4676137647685994 \n",
"Sun2251 6.15 Tonya Carter 4832732618637221 "
]
},
"execution_count": 69,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": 70,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"df = df.reset_index()"
]
},
{
"cell_type": "code",
"execution_count": 71,
"metadata": {},
"outputs": [
{
"data": {
"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>Payment ID</th>\n",
" <th>total_bill</th>\n",
" <th>tip</th>\n",
" <th>sex</th>\n",
" <th>smoker</th>\n",
" <th>day</th>\n",
" <th>time</th>\n",
" <th>size</th>\n",
" <th>price_per_person</th>\n",
" <th>Payer Name</th>\n",
" <th>CC Number</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Sun2959</td>\n",
" <td>16.99</td>\n",
" <td>1.01</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>8.49</td>\n",
" <td>Christy Cunningham</td>\n",
" <td>3560325168603410</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Sun4608</td>\n",
" <td>10.34</td>\n",
" <td>1.66</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>3.45</td>\n",
" <td>Douglas Tucker</td>\n",
" <td>4478071379779230</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Sun4458</td>\n",
" <td>21.01</td>\n",
" <td>3.50</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>7.00</td>\n",
" <td>Travis Walters</td>\n",
" <td>6011812112971322</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Sun5260</td>\n",
" <td>23.68</td>\n",
" <td>3.31</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>11.84</td>\n",
" <td>Nathaniel Harris</td>\n",
" <td>4676137647685994</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Sun2251</td>\n",
" <td>24.59</td>\n",
" <td>3.61</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>4</td>\n",
" <td>6.15</td>\n",
" <td>Tonya Carter</td>\n",
" <td>4832732618637221</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Payment ID total_bill tip sex smoker day time size \\\n",
"0 Sun2959 16.99 1.01 Female No Sun Dinner 2 \n",
"1 Sun4608 10.34 1.66 Male No Sun Dinner 3 \n",
"2 Sun4458 21.01 3.50 Male No Sun Dinner 3 \n",
"3 Sun5260 23.68 3.31 Male No Sun Dinner 2 \n",
"4 Sun2251 24.59 3.61 Female No Sun Dinner 4 \n",
"\n",
" price_per_person Payer Name CC Number \n",
"0 8.49 Christy Cunningham 3560325168603410 \n",
"1 3.45 Douglas Tucker 4478071379779230 \n",
"2 7.00 Travis Walters 6011812112971322 \n",
"3 11.84 Nathaniel Harris 4676137647685994 \n",
"4 6.15 Tonya Carter 4832732618637221 "
]
},
"execution_count": 71,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### ROWS\n",
"\n",
"Let's now explore these same concepts but with Rows."
]
},
{
"cell_type": "code",
"execution_count": 72,
"metadata": {},
"outputs": [
{
"data": {
"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>Payment ID</th>\n",
" <th>total_bill</th>\n",
" <th>tip</th>\n",
" <th>sex</th>\n",
" <th>smoker</th>\n",
" <th>day</th>\n",
" <th>time</th>\n",
" <th>size</th>\n",
" <th>price_per_person</th>\n",
" <th>Payer Name</th>\n",
" <th>CC Number</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Sun2959</td>\n",
" <td>16.99</td>\n",
" <td>1.01</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>8.49</td>\n",
" <td>Christy Cunningham</td>\n",
" <td>3560325168603410</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Sun4608</td>\n",
" <td>10.34</td>\n",
" <td>1.66</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>3.45</td>\n",
" <td>Douglas Tucker</td>\n",
" <td>4478071379779230</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Sun4458</td>\n",
" <td>21.01</td>\n",
" <td>3.50</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>7.00</td>\n",
" <td>Travis Walters</td>\n",
" <td>6011812112971322</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Sun5260</td>\n",
" <td>23.68</td>\n",
" <td>3.31</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>11.84</td>\n",
" <td>Nathaniel Harris</td>\n",
" <td>4676137647685994</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Sun2251</td>\n",
" <td>24.59</td>\n",
" <td>3.61</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>4</td>\n",
" <td>6.15</td>\n",
" <td>Tonya Carter</td>\n",
" <td>4832732618637221</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Payment ID total_bill tip sex smoker day time size \\\n",
"0 Sun2959 16.99 1.01 Female No Sun Dinner 2 \n",
"1 Sun4608 10.34 1.66 Male No Sun Dinner 3 \n",
"2 Sun4458 21.01 3.50 Male No Sun Dinner 3 \n",
"3 Sun5260 23.68 3.31 Male No Sun Dinner 2 \n",
"4 Sun2251 24.59 3.61 Female No Sun Dinner 4 \n",
"\n",
" price_per_person Payer Name CC Number \n",
"0 8.49 Christy Cunningham 3560325168603410 \n",
"1 3.45 Douglas Tucker 4478071379779230 \n",
"2 7.00 Travis Walters 6011812112971322 \n",
"3 11.84 Nathaniel Harris 4676137647685994 \n",
"4 6.15 Tonya Carter 4832732618637221 "
]
},
"execution_count": 72,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": 73,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"df = df.set_index('Payment ID')"
]
},
{
"cell_type": "code",
"execution_count": 74,
"metadata": {},
"outputs": [
{
"data": {
"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>total_bill</th>\n",
" <th>tip</th>\n",
" <th>sex</th>\n",
" <th>smoker</th>\n",
" <th>day</th>\n",
" <th>time</th>\n",
" <th>size</th>\n",
" <th>price_per_person</th>\n",
" <th>Payer Name</th>\n",
" <th>CC Number</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Payment ID</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Sun2959</th>\n",
" <td>16.99</td>\n",
" <td>1.01</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>8.49</td>\n",
" <td>Christy Cunningham</td>\n",
" <td>3560325168603410</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun4608</th>\n",
" <td>10.34</td>\n",
" <td>1.66</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>3.45</td>\n",
" <td>Douglas Tucker</td>\n",
" <td>4478071379779230</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun4458</th>\n",
" <td>21.01</td>\n",
" <td>3.50</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>7.00</td>\n",
" <td>Travis Walters</td>\n",
" <td>6011812112971322</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun5260</th>\n",
" <td>23.68</td>\n",
" <td>3.31</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>11.84</td>\n",
" <td>Nathaniel Harris</td>\n",
" <td>4676137647685994</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun2251</th>\n",
" <td>24.59</td>\n",
" <td>3.61</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>4</td>\n",
" <td>6.15</td>\n",
" <td>Tonya Carter</td>\n",
" <td>4832732618637221</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" total_bill tip sex smoker day time size \\\n",
"Payment ID \n",
"Sun2959 16.99 1.01 Female No Sun Dinner 2 \n",
"Sun4608 10.34 1.66 Male No Sun Dinner 3 \n",
"Sun4458 21.01 3.50 Male No Sun Dinner 3 \n",
"Sun5260 23.68 3.31 Male No Sun Dinner 2 \n",
"Sun2251 24.59 3.61 Female No Sun Dinner 4 \n",
"\n",
" price_per_person Payer Name CC Number \n",
"Payment ID \n",
"Sun2959 8.49 Christy Cunningham 3560325168603410 \n",
"Sun4608 3.45 Douglas Tucker 4478071379779230 \n",
"Sun4458 7.00 Travis Walters 6011812112971322 \n",
"Sun5260 11.84 Nathaniel Harris 4676137647685994 \n",
"Sun2251 6.15 Tonya Carter 4832732618637221 "
]
},
"execution_count": 74,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Grab a Single Row"
]
},
{
"cell_type": "code",
"execution_count": 75,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"total_bill 16.99\n",
"tip 1.01\n",
"sex Female\n",
"smoker No\n",
"day Sun\n",
"time Dinner\n",
"size 2\n",
"price_per_person 8.49\n",
"Payer Name Christy Cunningham\n",
"CC Number 3560325168603410\n",
"Name: Sun2959, dtype: object"
]
},
"execution_count": 75,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Integer Based\n",
"df.iloc[0]"
]
},
{
"cell_type": "code",
"execution_count": 76,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"total_bill 16.99\n",
"tip 1.01\n",
"sex Female\n",
"smoker No\n",
"day Sun\n",
"time Dinner\n",
"size 2\n",
"price_per_person 8.49\n",
"Payer Name Christy Cunningham\n",
"CC Number 3560325168603410\n",
"Name: Sun2959, dtype: object"
]
},
"execution_count": 76,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Name Based\n",
"df.loc['Sun2959']"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Grab Multiple Rows"
]
},
{
"cell_type": "code",
"execution_count": 77,
"metadata": {},
"outputs": [
{
"data": {
"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>total_bill</th>\n",
" <th>tip</th>\n",
" <th>sex</th>\n",
" <th>smoker</th>\n",
" <th>day</th>\n",
" <th>time</th>\n",
" <th>size</th>\n",
" <th>price_per_person</th>\n",
" <th>Payer Name</th>\n",
" <th>CC Number</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Payment ID</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Sun2959</th>\n",
" <td>16.99</td>\n",
" <td>1.01</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>8.49</td>\n",
" <td>Christy Cunningham</td>\n",
" <td>3560325168603410</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun4608</th>\n",
" <td>10.34</td>\n",
" <td>1.66</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>3.45</td>\n",
" <td>Douglas Tucker</td>\n",
" <td>4478071379779230</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun4458</th>\n",
" <td>21.01</td>\n",
" <td>3.50</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>7.00</td>\n",
" <td>Travis Walters</td>\n",
" <td>6011812112971322</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun5260</th>\n",
" <td>23.68</td>\n",
" <td>3.31</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>11.84</td>\n",
" <td>Nathaniel Harris</td>\n",
" <td>4676137647685994</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" total_bill tip sex smoker day time size \\\n",
"Payment ID \n",
"Sun2959 16.99 1.01 Female No Sun Dinner 2 \n",
"Sun4608 10.34 1.66 Male No Sun Dinner 3 \n",
"Sun4458 21.01 3.50 Male No Sun Dinner 3 \n",
"Sun5260 23.68 3.31 Male No Sun Dinner 2 \n",
"\n",
" price_per_person Payer Name CC Number \n",
"Payment ID \n",
"Sun2959 8.49 Christy Cunningham 3560325168603410 \n",
"Sun4608 3.45 Douglas Tucker 4478071379779230 \n",
"Sun4458 7.00 Travis Walters 6011812112971322 \n",
"Sun5260 11.84 Nathaniel Harris 4676137647685994 "
]
},
"execution_count": 77,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.iloc[0:4]"
]
},
{
"cell_type": "code",
"execution_count": 78,
"metadata": {},
"outputs": [
{
"data": {
"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>total_bill</th>\n",
" <th>tip</th>\n",
" <th>sex</th>\n",
" <th>smoker</th>\n",
" <th>day</th>\n",
" <th>time</th>\n",
" <th>size</th>\n",
" <th>price_per_person</th>\n",
" <th>Payer Name</th>\n",
" <th>CC Number</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Payment ID</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Sun2959</th>\n",
" <td>16.99</td>\n",
" <td>1.01</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>8.49</td>\n",
" <td>Christy Cunningham</td>\n",
" <td>3560325168603410</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun5260</th>\n",
" <td>23.68</td>\n",
" <td>3.31</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>11.84</td>\n",
" <td>Nathaniel Harris</td>\n",
" <td>4676137647685994</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" total_bill tip sex smoker day time size \\\n",
"Payment ID \n",
"Sun2959 16.99 1.01 Female No Sun Dinner 2 \n",
"Sun5260 23.68 3.31 Male No Sun Dinner 2 \n",
"\n",
" price_per_person Payer Name CC Number \n",
"Payment ID \n",
"Sun2959 8.49 Christy Cunningham 3560325168603410 \n",
"Sun5260 11.84 Nathaniel Harris 4676137647685994 "
]
},
"execution_count": 78,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.loc[['Sun2959','Sun5260']]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Remove Row\n",
"\n",
"Typically are datasets will be large enough that we won't remove rows like this since we won't know thier row location for some specific condition, instead, we drop rows based on conditions such as missing data or column values. The next lecture will cover this in a lot more detail."
]
},
{
"cell_type": "code",
"execution_count": 79,
"metadata": {},
"outputs": [
{
"data": {
"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>total_bill</th>\n",
" <th>tip</th>\n",
" <th>sex</th>\n",
" <th>smoker</th>\n",
" <th>day</th>\n",
" <th>time</th>\n",
" <th>size</th>\n",
" <th>price_per_person</th>\n",
" <th>Payer Name</th>\n",
" <th>CC Number</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Payment ID</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Sun2959</th>\n",
" <td>16.99</td>\n",
" <td>1.01</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>8.49</td>\n",
" <td>Christy Cunningham</td>\n",
" <td>3560325168603410</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun4608</th>\n",
" <td>10.34</td>\n",
" <td>1.66</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>3.45</td>\n",
" <td>Douglas Tucker</td>\n",
" <td>4478071379779230</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun4458</th>\n",
" <td>21.01</td>\n",
" <td>3.50</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>7.00</td>\n",
" <td>Travis Walters</td>\n",
" <td>6011812112971322</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun5260</th>\n",
" <td>23.68</td>\n",
" <td>3.31</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>11.84</td>\n",
" <td>Nathaniel Harris</td>\n",
" <td>4676137647685994</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun2251</th>\n",
" <td>24.59</td>\n",
" <td>3.61</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>4</td>\n",
" <td>6.15</td>\n",
" <td>Tonya Carter</td>\n",
" <td>4832732618637221</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" total_bill tip sex smoker day time size \\\n",
"Payment ID \n",
"Sun2959 16.99 1.01 Female No Sun Dinner 2 \n",
"Sun4608 10.34 1.66 Male No Sun Dinner 3 \n",
"Sun4458 21.01 3.50 Male No Sun Dinner 3 \n",
"Sun5260 23.68 3.31 Male No Sun Dinner 2 \n",
"Sun2251 24.59 3.61 Female No Sun Dinner 4 \n",
"\n",
" price_per_person Payer Name CC Number \n",
"Payment ID \n",
"Sun2959 8.49 Christy Cunningham 3560325168603410 \n",
"Sun4608 3.45 Douglas Tucker 4478071379779230 \n",
"Sun4458 7.00 Travis Walters 6011812112971322 \n",
"Sun5260 11.84 Nathaniel Harris 4676137647685994 \n",
"Sun2251 6.15 Tonya Carter 4832732618637221 "
]
},
"execution_count": 79,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": 80,
"metadata": {},
"outputs": [
{
"data": {
"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>total_bill</th>\n",
" <th>tip</th>\n",
" <th>sex</th>\n",
" <th>smoker</th>\n",
" <th>day</th>\n",
" <th>time</th>\n",
" <th>size</th>\n",
" <th>price_per_person</th>\n",
" <th>Payer Name</th>\n",
" <th>CC Number</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Payment ID</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Sun4608</th>\n",
" <td>10.34</td>\n",
" <td>1.66</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>3.45</td>\n",
" <td>Douglas Tucker</td>\n",
" <td>4478071379779230</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun4458</th>\n",
" <td>21.01</td>\n",
" <td>3.50</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>7.00</td>\n",
" <td>Travis Walters</td>\n",
" <td>6011812112971322</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun5260</th>\n",
" <td>23.68</td>\n",
" <td>3.31</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>11.84</td>\n",
" <td>Nathaniel Harris</td>\n",
" <td>4676137647685994</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun2251</th>\n",
" <td>24.59</td>\n",
" <td>3.61</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>4</td>\n",
" <td>6.15</td>\n",
" <td>Tonya Carter</td>\n",
" <td>4832732618637221</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun9679</th>\n",
" <td>25.29</td>\n",
" <td>4.71</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>4</td>\n",
" <td>6.32</td>\n",
" <td>Erik Smith</td>\n",
" <td>213140353657882</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" total_bill tip sex smoker day time size \\\n",
"Payment ID \n",
"Sun4608 10.34 1.66 Male No Sun Dinner 3 \n",
"Sun4458 21.01 3.50 Male No Sun Dinner 3 \n",
"Sun5260 23.68 3.31 Male No Sun Dinner 2 \n",
"Sun2251 24.59 3.61 Female No Sun Dinner 4 \n",
"Sun9679 25.29 4.71 Male No Sun Dinner 4 \n",
"\n",
" price_per_person Payer Name CC Number \n",
"Payment ID \n",
"Sun4608 3.45 Douglas Tucker 4478071379779230 \n",
"Sun4458 7.00 Travis Walters 6011812112971322 \n",
"Sun5260 11.84 Nathaniel Harris 4676137647685994 \n",
"Sun2251 6.15 Tonya Carter 4832732618637221 \n",
"Sun9679 6.32 Erik Smith 213140353657882 "
]
},
"execution_count": 80,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.drop('Sun2959',axis=0).head()"
]
},
{
"cell_type": "code",
"execution_count": 81,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Error if you have a named index!\n",
"# df.drop(0,axis=0).head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Insert a New Row\n",
"\n",
"Pretty rare to add a single row like this. Usually you use pd.concat() to add many rows at once. You could use the .append() method with a list of pd.Series() objects, but you won't see us do this with realistic real-world data."
]
},
{
"cell_type": "code",
"execution_count": 82,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"one_row = df.iloc[0]"
]
},
{
"cell_type": "code",
"execution_count": 83,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"total_bill 16.99\n",
"tip 1.01\n",
"sex Female\n",
"smoker No\n",
"day Sun\n",
"time Dinner\n",
"size 2\n",
"price_per_person 8.49\n",
"Payer Name Christy Cunningham\n",
"CC Number 3560325168603410\n",
"Name: Sun2959, dtype: object"
]
},
"execution_count": 83,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"one_row"
]
},
{
"cell_type": "code",
"execution_count": 84,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"pandas.core.series.Series"
]
},
"execution_count": 84,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(one_row)"
]
},
{
"cell_type": "code",
"execution_count": 85,
"metadata": {},
"outputs": [
{
"data": {
"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>total_bill</th>\n",
" <th>tip</th>\n",
" <th>sex</th>\n",
" <th>smoker</th>\n",
" <th>day</th>\n",
" <th>time</th>\n",
" <th>size</th>\n",
" <th>price_per_person</th>\n",
" <th>Payer Name</th>\n",
" <th>CC Number</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Payment ID</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Sat2657</th>\n",
" <td>29.03</td>\n",
" <td>5.92</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>3</td>\n",
" <td>9.68</td>\n",
" <td>Michael Avila</td>\n",
" <td>5296068606052842</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat1766</th>\n",
" <td>27.18</td>\n",
" <td>2.00</td>\n",
" <td>Female</td>\n",
" <td>Yes</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>13.59</td>\n",
" <td>Monica Sanders</td>\n",
" <td>3506806155565404</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat3880</th>\n",
" <td>22.67</td>\n",
" <td>2.00</td>\n",
" <td>Male</td>\n",
" <td>Yes</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>11.34</td>\n",
" <td>Keith Wong</td>\n",
" <td>6011891618747196</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat17</th>\n",
" <td>17.82</td>\n",
" <td>1.75</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>8.91</td>\n",
" <td>Dennis Dixon</td>\n",
" <td>4375220550950</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Thur672</th>\n",
" <td>18.78</td>\n",
" <td>3.00</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Thur</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>9.39</td>\n",
" <td>Michelle Hardin</td>\n",
" <td>3511451626698139</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" total_bill tip sex smoker day time size \\\n",
"Payment ID \n",
"Sat2657 29.03 5.92 Male No Sat Dinner 3 \n",
"Sat1766 27.18 2.00 Female Yes Sat Dinner 2 \n",
"Sat3880 22.67 2.00 Male Yes Sat Dinner 2 \n",
"Sat17 17.82 1.75 Male No Sat Dinner 2 \n",
"Thur672 18.78 3.00 Female No Thur Dinner 2 \n",
"\n",
" price_per_person Payer Name CC Number \n",
"Payment ID \n",
"Sat2657 9.68 Michael Avila 5296068606052842 \n",
"Sat1766 13.59 Monica Sanders 3506806155565404 \n",
"Sat3880 11.34 Keith Wong 6011891618747196 \n",
"Sat17 8.91 Dennis Dixon 4375220550950 \n",
"Thur672 9.39 Michelle Hardin 3511451626698139 "
]
},
"execution_count": 85,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.tail()"
]
},
{
"cell_type": "code",
"execution_count": 87,
"metadata": {},
"outputs": [
{
"data": {
"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>total_bill</th>\n",
" <th>tip</th>\n",
" <th>sex</th>\n",
" <th>smoker</th>\n",
" <th>day</th>\n",
" <th>time</th>\n",
" <th>size</th>\n",
" <th>price_per_person</th>\n",
" <th>Payer Name</th>\n",
" <th>CC Number</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Payment ID</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Sat1766</th>\n",
" <td>27.18</td>\n",
" <td>2.00</td>\n",
" <td>Female</td>\n",
" <td>Yes</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>13.59</td>\n",
" <td>Monica Sanders</td>\n",
" <td>3506806155565404</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat3880</th>\n",
" <td>22.67</td>\n",
" <td>2.00</td>\n",
" <td>Male</td>\n",
" <td>Yes</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>11.34</td>\n",
" <td>Keith Wong</td>\n",
" <td>6011891618747196</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sat17</th>\n",
" <td>17.82</td>\n",
" <td>1.75</td>\n",
" <td>Male</td>\n",
" <td>No</td>\n",
" <td>Sat</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>8.91</td>\n",
" <td>Dennis Dixon</td>\n",
" <td>4375220550950</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Thur672</th>\n",
" <td>18.78</td>\n",
" <td>3.00</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Thur</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>9.39</td>\n",
" <td>Michelle Hardin</td>\n",
" <td>3511451626698139</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sun2959</th>\n",
" <td>16.99</td>\n",
" <td>1.01</td>\n",
" <td>Female</td>\n",
" <td>No</td>\n",
" <td>Sun</td>\n",
" <td>Dinner</td>\n",
" <td>2</td>\n",
" <td>8.49</td>\n",
" <td>Christy Cunningham</td>\n",
" <td>3560325168603410</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" total_bill tip sex smoker day time size \\\n",
"Payment ID \n",
"Sat1766 27.18 2.00 Female Yes Sat Dinner 2 \n",
"Sat3880 22.67 2.00 Male Yes Sat Dinner 2 \n",
"Sat17 17.82 1.75 Male No Sat Dinner 2 \n",
"Thur672 18.78 3.00 Female No Thur Dinner 2 \n",
"Sun2959 16.99 1.01 Female No Sun Dinner 2 \n",
"\n",
" price_per_person Payer Name CC Number \n",
"Payment ID \n",
"Sat1766 13.59 Monica Sanders 3506806155565404 \n",
"Sat3880 11.34 Keith Wong 6011891618747196 \n",
"Sat17 8.91 Dennis Dixon 4375220550950 \n",
"Thur672 9.39 Michelle Hardin 3511451626698139 \n",
"Sun2959 8.49 Christy Cunningham 3560325168603410 "
]
},
"execution_count": 87,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.append(one_row).tail()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"--------"
]
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.6"
}
},
"nbformat": 4,
"nbformat_minor": 1
}