{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "___\n", "\n", "\n", "___\n", "
Copyright by Pierian Data Inc.
\n", "
For more information, visit us at www.pieriandata.com
" ] }, { "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
012
0951181
1706387
275977
340463
\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
012
CA951181
NY706387
AZ75977
TX40463
\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
JanFebMar
CA951181
NY706387
AZ75977
TX40463
\n", "
" ], "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": [ "\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.
\n", "Unless you're running the virtual environment included with the course, you may need to install xlrd and openpyxl.
\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 .\n", "06/30/2020 05:21 PM ..\n", "01/27/2020 01:55 PM .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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
total_billtipsexsmokerdaytimesizeprice_per_personPayer NameCC NumberPayment ID
016.991.01FemaleNoSunDinner28.49Christy Cunningham3560325168603410Sun2959
110.341.66MaleNoSunDinner33.45Douglas Tucker4478071379779230Sun4608
221.013.50MaleNoSunDinner37.00Travis Walters6011812112971322Sun4458
323.683.31MaleNoSunDinner211.84Nathaniel Harris4676137647685994Sun5260
424.593.61FemaleNoSunDinner46.15Tonya Carter4832732618637221Sun2251
525.294.71MaleNoSunDinner46.32Erik Smith213140353657882Sun9679
68.772.00MaleNoSunDinner24.38Kristopher Johnson2223727524230344Sun5985
726.883.12MaleNoSunDinner46.72Robert Buck3514785077705092Sun8157
815.041.96MaleNoSunDinner27.52Joseph Mcdonald3522866365840377Sun6820
914.783.23MaleNoSunDinner27.39Jerome Abbott3532124519049786Sun3775
1010.271.71MaleNoSunDinner25.14William Riley566287581219Sun2546
1135.265.00FemaleNoSunDinner48.82Diane Macias4577817359320969Sun6686
1215.421.57MaleNoSunDinner27.71Chad Harrington577040572932Sun1300
1318.433.00MaleNoSunDinner44.61Joshua Jones6011163105616890Sun2971
1414.833.02FemaleNoSunDinner27.42Vanessa Jones30016702287574Sun3848
1521.583.92MaleNoSunDinner210.79Matthew Reilly180073029785069Sun1878
1610.331.67FemaleNoSunDinner33.44Elizabeth Foster4240025044626033Sun9715
1716.293.71MaleNoSunDinner35.43John Pittman6521340257218708Sun2998
1816.973.50FemaleNoSunDinner35.66Laura Martinez30422275171379Sun2789
1920.653.35MaleNoSatDinner36.88Timothy Oneal6568069240986485Sat9213
2017.924.08MaleNoSatDinner28.96Thomas Rice4403296224639756Sat1709
2120.292.75FemaleNoSatDinner210.14Natalie Gardner5448125351489749Sat9618
2215.772.23FemaleNoSatDinner27.88Ashley Shelton3524119516293213Sat9786
2339.427.58MaleNoSatDinner49.86Lance Peterson3542584061609808Sat239
2419.823.18MaleNoSatDinner29.91Christopher Ross36739148167928Sat6236
2517.812.34MaleNoSatDinner44.45Robert Perkins30502930499388Sat907
2613.372.00MaleNoSatDinner26.68Kyle Avery6531339539615499Sat6651
2712.692.00MaleNoSatDinner26.34Patrick Barber30155551880343Sat394
2821.704.30MaleNoSatDinner210.85David Collier5529694315416009Sat3697
2919.653.00FemaleNoSatDinner29.82Melinda Murphy5489272944576051Sat2467
....................................
21428.176.50FemaleYesSatDinner39.39Marissa Jackson4922302538691962Sat3374
21512.901.10FemaleYesSatDinner26.45Jessica Owen4726904879471Sat6983
21628.153.00MaleYesSatDinner55.63Shawn Barnett PhD4590982568244Sat7320
21711.591.50MaleYesSatDinner25.80Gary Orr30324521283406Sat8489
2187.741.44MaleYesSatDinner23.87Nicholas Archer340517153733524Sat4772
21930.143.09FemaleYesSatDinner47.54Shelby House502097403252Sat8863
22012.162.20MaleYesFriLunch26.08Ricky Johnson213109508670736Fri4607
22113.423.48FemaleYesFriLunch26.71Leslie Kaufman379437981958785Fri7511
2228.581.92MaleYesFriLunch18.58Jason Lawrence3505302934650403Fri6624
22315.983.00FemaleNoFriLunch35.33Mary Rivera5343428579353069Fri6014
22413.421.58MaleYesFriLunch26.71Ronald Vaughn DVM341503466406403Fri5959
22516.272.50FemaleYesFriLunch28.14Whitney Arnold3579111947217428Fri6665
22610.092.00FemaleYesFriLunch25.04Ruth Weiss5268689490381635Fri6359
22720.453.00MaleNoSatDinner45.11Robert Bradley213141668145910Sat4319
22813.282.72MaleNoSatDinner26.64Glenn Jones502061651712Sat2937
22922.122.88FemaleYesSatDinner211.06Jennifer Russell4793003293608Sat3943
23024.012.00MaleYesSatDinner46.00Michael Osborne4258682154026Sat7872
23115.693.00MaleYesSatDinner35.23Jason Parks4812333796161Sat6334
23211.613.39MaleNoSatDinner25.80James Taylor6011482917327995Sat2124
23310.771.47MaleNoSatDinner25.38Paul Novak6011698897610858Sat1467
23415.533.00MaleYesSatDinner27.76Tracy Douglas4097938155941930Sat7220
23510.071.25MaleNoSatDinner25.04Sean Gonzalez3534021246117605Sat4615
23612.601.00MaleYesSatDinner26.30Matthew Myers3543676378973965Sat5032
23732.831.17MaleYesSatDinner216.42Thomas Brown4284722681265508Sat2929
23835.834.67FemaleNoSatDinner311.94Kimberly Crane676184013727Sat9777
23929.035.92MaleNoSatDinner39.68Michael Avila5296068606052842Sat2657
24027.182.00FemaleYesSatDinner213.59Monica Sanders3506806155565404Sat1766
24122.672.00MaleYesSatDinner211.34Keith Wong6011891618747196Sat3880
24217.821.75MaleNoSatDinner28.91Dennis Dixon4375220550950Sat17
24318.783.00FemaleNoThurDinner29.39Michelle Hardin3511451626698139Thur672
\n", "

244 rows × 11 columns

\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
total_billtipsexsmokerdaytimesizeprice_per_personPayer NameCC NumberPayment ID
016.991.01FemaleNoSunDinner28.49Christy Cunningham3560325168603410Sun2959
110.341.66MaleNoSunDinner33.45Douglas Tucker4478071379779230Sun4608
221.013.50MaleNoSunDinner37.00Travis Walters6011812112971322Sun4458
\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
total_billtipsexsmokerdaytimesizeprice_per_personPayer NameCC NumberPayment ID
24122.672.00MaleYesSatDinner211.34Keith Wong6011891618747196Sat3880
24217.821.75MaleNoSatDinner28.91Dennis Dixon4375220550950Sat17
24318.783.00FemaleNoThurDinner29.39Michelle Hardin3511451626698139Thur672
\n", "
" ], "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": [ "\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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
total_billtipsizeprice_per_personCC Number
count244.000000244.000000244.000000244.0000002.440000e+02
mean19.7859432.9982792.5696727.8881972.563496e+15
std8.9024121.3836380.9511002.9142342.369340e+15
min3.0700001.0000001.0000002.8800006.040679e+10
25%13.3475002.0000002.0000005.8000003.040731e+13
50%17.7950002.9000002.0000007.2550003.525318e+15
75%24.1275003.5625003.0000009.3900004.553675e+15
max50.81000010.0000006.00000020.2700006.596454e+15
\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
countmeanstdmin25%50%75%max
total_bill244.01.978594e+018.902412e+003.070000e+001.334750e+011.779500e+012.412750e+015.081000e+01
tip244.02.998279e+001.383638e+001.000000e+002.000000e+002.900000e+003.562500e+001.000000e+01
size244.02.569672e+009.510998e-011.000000e+002.000000e+002.000000e+003.000000e+006.000000e+00
price_per_person244.07.888197e+002.914234e+002.880000e+005.800000e+007.255000e+009.390000e+002.027000e+01
CC Number244.02.563496e+152.369340e+156.040679e+103.040731e+133.525318e+154.553675e+156.596454e+15
\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
total_billtipsexsmokerdaytimesizeprice_per_personPayer NameCC NumberPayment ID
016.991.01FemaleNoSunDinner28.49Christy Cunningham3560325168603410Sun2959
110.341.66MaleNoSunDinner33.45Douglas Tucker4478071379779230Sun4608
221.013.50MaleNoSunDinner37.00Travis Walters6011812112971322Sun4458
323.683.31MaleNoSunDinner211.84Nathaniel Harris4676137647685994Sun5260
424.593.61FemaleNoSunDinner46.15Tonya Carter4832732618637221Sun2251
\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
total_billtip
016.991.01
110.341.66
221.013.50
323.683.31
424.593.61
525.294.71
68.772.00
726.883.12
815.041.96
914.783.23
1010.271.71
1135.265.00
1215.421.57
1318.433.00
1414.833.02
1521.583.92
1610.331.67
1716.293.71
1816.973.50
1920.653.35
2017.924.08
2120.292.75
2215.772.23
2339.427.58
2419.823.18
2517.812.34
2613.372.00
2712.692.00
2821.704.30
2919.653.00
.........
21428.176.50
21512.901.10
21628.153.00
21711.591.50
2187.741.44
21930.143.09
22012.162.20
22113.423.48
2228.581.92
22315.983.00
22413.421.58
22516.272.50
22610.092.00
22720.453.00
22813.282.72
22922.122.88
23024.012.00
23115.693.00
23211.613.39
23310.771.47
23415.533.00
23510.071.25
23612.601.00
23732.831.17
23835.834.67
23929.035.92
24027.182.00
24122.672.00
24217.821.75
24318.783.00
\n", "

244 rows × 2 columns

\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
total_billtipsexsmokerdaytimesizeprice_per_personPayer NameCC NumberPayment IDtip_percentage
016.991.01FemaleNoSunDinner28.49Christy Cunningham3560325168603410Sun29595.944673
110.341.66MaleNoSunDinner33.45Douglas Tucker4478071379779230Sun460816.054159
221.013.50MaleNoSunDinner37.00Travis Walters6011812112971322Sun445816.658734
323.683.31MaleNoSunDinner211.84Nathaniel Harris4676137647685994Sun526013.978041
424.593.61FemaleNoSunDinner46.15Tonya Carter4832732618637221Sun225114.680765
\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
total_billtipsexsmokerdaytimesizeprice_per_personPayer NameCC NumberPayment IDtip_percentage
016.991.01FemaleNoSunDinner28.495000Christy Cunningham3560325168603410Sun29595.944673
110.341.66MaleNoSunDinner33.446667Douglas Tucker4478071379779230Sun460816.054159
221.013.50MaleNoSunDinner37.003333Travis Walters6011812112971322Sun445816.658734
323.683.31MaleNoSunDinner211.840000Nathaniel Harris4676137647685994Sun526013.978041
424.593.61FemaleNoSunDinner46.147500Tonya Carter4832732618637221Sun225114.680765
\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
total_billtipsexsmokerdaytimesizeprice_per_personPayer NameCC NumberPayment IDtip_percentage
016.991.01FemaleNoSunDinner28.49Christy Cunningham3560325168603410Sun29595.944673
110.341.66MaleNoSunDinner33.45Douglas Tucker4478071379779230Sun460816.054159
221.013.50MaleNoSunDinner37.00Travis Walters6011812112971322Sun445816.658734
323.683.31MaleNoSunDinner211.84Nathaniel Harris4676137647685994Sun526013.978041
424.593.61FemaleNoSunDinner46.15Tonya Carter4832732618637221Sun225114.680765
\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
total_billtipsexsmokerdaytimesizeprice_per_personPayer NameCC NumberPayment ID
016.991.01FemaleNoSunDinner28.49Christy Cunningham3560325168603410Sun2959
110.341.66MaleNoSunDinner33.45Douglas Tucker4478071379779230Sun4608
221.013.50MaleNoSunDinner37.00Travis Walters6011812112971322Sun4458
323.683.31MaleNoSunDinner211.84Nathaniel Harris4676137647685994Sun5260
424.593.61FemaleNoSunDinner46.15Tonya Carter4832732618637221Sun2251
\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
total_billtipsexsmokerdaytimesizeprice_per_personPayer NameCC NumberPayment ID
016.991.01FemaleNoSunDinner28.49Christy Cunningham3560325168603410Sun2959
110.341.66MaleNoSunDinner33.45Douglas Tucker4478071379779230Sun4608
221.013.50MaleNoSunDinner37.00Travis Walters6011812112971322Sun4458
323.683.31MaleNoSunDinner211.84Nathaniel Harris4676137647685994Sun5260
424.593.61FemaleNoSunDinner46.15Tonya Carter4832732618637221Sun2251
\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
total_billtipsexsmokerdaytimesizeprice_per_personPayer NameCC Number
Payment ID
Sun295916.991.01FemaleNoSunDinner28.49Christy Cunningham3560325168603410
Sun460810.341.66MaleNoSunDinner33.45Douglas Tucker4478071379779230
Sun445821.013.50MaleNoSunDinner37.00Travis Walters6011812112971322
Sun526023.683.31MaleNoSunDinner211.84Nathaniel Harris4676137647685994
Sun225124.593.61FemaleNoSunDinner46.15Tonya Carter4832732618637221
Sun967925.294.71MaleNoSunDinner46.32Erik Smith213140353657882
Sun59858.772.00MaleNoSunDinner24.38Kristopher Johnson2223727524230344
Sun815726.883.12MaleNoSunDinner46.72Robert Buck3514785077705092
Sun682015.041.96MaleNoSunDinner27.52Joseph Mcdonald3522866365840377
Sun377514.783.23MaleNoSunDinner27.39Jerome Abbott3532124519049786
Sun254610.271.71MaleNoSunDinner25.14William Riley566287581219
Sun668635.265.00FemaleNoSunDinner48.82Diane Macias4577817359320969
Sun130015.421.57MaleNoSunDinner27.71Chad Harrington577040572932
Sun297118.433.00MaleNoSunDinner44.61Joshua Jones6011163105616890
Sun384814.833.02FemaleNoSunDinner27.42Vanessa Jones30016702287574
Sun187821.583.92MaleNoSunDinner210.79Matthew Reilly180073029785069
Sun971510.331.67FemaleNoSunDinner33.44Elizabeth Foster4240025044626033
Sun299816.293.71MaleNoSunDinner35.43John Pittman6521340257218708
Sun278916.973.50FemaleNoSunDinner35.66Laura Martinez30422275171379
Sat921320.653.35MaleNoSatDinner36.88Timothy Oneal6568069240986485
Sat170917.924.08MaleNoSatDinner28.96Thomas Rice4403296224639756
Sat961820.292.75FemaleNoSatDinner210.14Natalie Gardner5448125351489749
Sat978615.772.23FemaleNoSatDinner27.88Ashley Shelton3524119516293213
Sat23939.427.58MaleNoSatDinner49.86Lance Peterson3542584061609808
Sat623619.823.18MaleNoSatDinner29.91Christopher Ross36739148167928
Sat90717.812.34MaleNoSatDinner44.45Robert Perkins30502930499388
Sat665113.372.00MaleNoSatDinner26.68Kyle Avery6531339539615499
Sat39412.692.00MaleNoSatDinner26.34Patrick Barber30155551880343
Sat369721.704.30MaleNoSatDinner210.85David Collier5529694315416009
Sat246719.653.00FemaleNoSatDinner29.82Melinda Murphy5489272944576051
.................................
Sat337428.176.50FemaleYesSatDinner39.39Marissa Jackson4922302538691962
Sat698312.901.10FemaleYesSatDinner26.45Jessica Owen4726904879471
Sat732028.153.00MaleYesSatDinner55.63Shawn Barnett PhD4590982568244
Sat848911.591.50MaleYesSatDinner25.80Gary Orr30324521283406
Sat47727.741.44MaleYesSatDinner23.87Nicholas Archer340517153733524
Sat886330.143.09FemaleYesSatDinner47.54Shelby House502097403252
Fri460712.162.20MaleYesFriLunch26.08Ricky Johnson213109508670736
Fri751113.423.48FemaleYesFriLunch26.71Leslie Kaufman379437981958785
Fri66248.581.92MaleYesFriLunch18.58Jason Lawrence3505302934650403
Fri601415.983.00FemaleNoFriLunch35.33Mary Rivera5343428579353069
Fri595913.421.58MaleYesFriLunch26.71Ronald Vaughn DVM341503466406403
Fri666516.272.50FemaleYesFriLunch28.14Whitney Arnold3579111947217428
Fri635910.092.00FemaleYesFriLunch25.04Ruth Weiss5268689490381635
Sat431920.453.00MaleNoSatDinner45.11Robert Bradley213141668145910
Sat293713.282.72MaleNoSatDinner26.64Glenn Jones502061651712
Sat394322.122.88FemaleYesSatDinner211.06Jennifer Russell4793003293608
Sat787224.012.00MaleYesSatDinner46.00Michael Osborne4258682154026
Sat633415.693.00MaleYesSatDinner35.23Jason Parks4812333796161
Sat212411.613.39MaleNoSatDinner25.80James Taylor6011482917327995
Sat146710.771.47MaleNoSatDinner25.38Paul Novak6011698897610858
Sat722015.533.00MaleYesSatDinner27.76Tracy Douglas4097938155941930
Sat461510.071.25MaleNoSatDinner25.04Sean Gonzalez3534021246117605
Sat503212.601.00MaleYesSatDinner26.30Matthew Myers3543676378973965
Sat292932.831.17MaleYesSatDinner216.42Thomas Brown4284722681265508
Sat977735.834.67FemaleNoSatDinner311.94Kimberly Crane676184013727
Sat265729.035.92MaleNoSatDinner39.68Michael Avila5296068606052842
Sat176627.182.00FemaleYesSatDinner213.59Monica Sanders3506806155565404
Sat388022.672.00MaleYesSatDinner211.34Keith Wong6011891618747196
Sat1717.821.75MaleNoSatDinner28.91Dennis Dixon4375220550950
Thur67218.783.00FemaleNoThurDinner29.39Michelle Hardin3511451626698139
\n", "

244 rows × 10 columns

\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
total_billtipsexsmokerdaytimesizeprice_per_personPayer NameCC NumberPayment ID
016.991.01FemaleNoSunDinner28.49Christy Cunningham3560325168603410Sun2959
110.341.66MaleNoSunDinner33.45Douglas Tucker4478071379779230Sun4608
221.013.50MaleNoSunDinner37.00Travis Walters6011812112971322Sun4458
323.683.31MaleNoSunDinner211.84Nathaniel Harris4676137647685994Sun5260
424.593.61FemaleNoSunDinner46.15Tonya Carter4832732618637221Sun2251
\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
total_billtipsexsmokerdaytimesizeprice_per_personPayer NameCC Number
Payment ID
Sun295916.991.01FemaleNoSunDinner28.49Christy Cunningham3560325168603410
Sun460810.341.66MaleNoSunDinner33.45Douglas Tucker4478071379779230
Sun445821.013.50MaleNoSunDinner37.00Travis Walters6011812112971322
Sun526023.683.31MaleNoSunDinner211.84Nathaniel Harris4676137647685994
Sun225124.593.61FemaleNoSunDinner46.15Tonya Carter4832732618637221
\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Payment IDtotal_billtipsexsmokerdaytimesizeprice_per_personPayer NameCC Number
0Sun295916.991.01FemaleNoSunDinner28.49Christy Cunningham3560325168603410
1Sun460810.341.66MaleNoSunDinner33.45Douglas Tucker4478071379779230
2Sun445821.013.50MaleNoSunDinner37.00Travis Walters6011812112971322
3Sun526023.683.31MaleNoSunDinner211.84Nathaniel Harris4676137647685994
4Sun225124.593.61FemaleNoSunDinner46.15Tonya Carter4832732618637221
\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Payment IDtotal_billtipsexsmokerdaytimesizeprice_per_personPayer NameCC Number
0Sun295916.991.01FemaleNoSunDinner28.49Christy Cunningham3560325168603410
1Sun460810.341.66MaleNoSunDinner33.45Douglas Tucker4478071379779230
2Sun445821.013.50MaleNoSunDinner37.00Travis Walters6011812112971322
3Sun526023.683.31MaleNoSunDinner211.84Nathaniel Harris4676137647685994
4Sun225124.593.61FemaleNoSunDinner46.15Tonya Carter4832732618637221
\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
total_billtipsexsmokerdaytimesizeprice_per_personPayer NameCC Number
Payment ID
Sun295916.991.01FemaleNoSunDinner28.49Christy Cunningham3560325168603410
Sun460810.341.66MaleNoSunDinner33.45Douglas Tucker4478071379779230
Sun445821.013.50MaleNoSunDinner37.00Travis Walters6011812112971322
Sun526023.683.31MaleNoSunDinner211.84Nathaniel Harris4676137647685994
Sun225124.593.61FemaleNoSunDinner46.15Tonya Carter4832732618637221
\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
total_billtipsexsmokerdaytimesizeprice_per_personPayer NameCC Number
Payment ID
Sun295916.991.01FemaleNoSunDinner28.49Christy Cunningham3560325168603410
Sun460810.341.66MaleNoSunDinner33.45Douglas Tucker4478071379779230
Sun445821.013.50MaleNoSunDinner37.00Travis Walters6011812112971322
Sun526023.683.31MaleNoSunDinner211.84Nathaniel Harris4676137647685994
\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
total_billtipsexsmokerdaytimesizeprice_per_personPayer NameCC Number
Payment ID
Sun295916.991.01FemaleNoSunDinner28.49Christy Cunningham3560325168603410
Sun526023.683.31MaleNoSunDinner211.84Nathaniel Harris4676137647685994
\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
total_billtipsexsmokerdaytimesizeprice_per_personPayer NameCC Number
Payment ID
Sun295916.991.01FemaleNoSunDinner28.49Christy Cunningham3560325168603410
Sun460810.341.66MaleNoSunDinner33.45Douglas Tucker4478071379779230
Sun445821.013.50MaleNoSunDinner37.00Travis Walters6011812112971322
Sun526023.683.31MaleNoSunDinner211.84Nathaniel Harris4676137647685994
Sun225124.593.61FemaleNoSunDinner46.15Tonya Carter4832732618637221
\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
total_billtipsexsmokerdaytimesizeprice_per_personPayer NameCC Number
Payment ID
Sun460810.341.66MaleNoSunDinner33.45Douglas Tucker4478071379779230
Sun445821.013.50MaleNoSunDinner37.00Travis Walters6011812112971322
Sun526023.683.31MaleNoSunDinner211.84Nathaniel Harris4676137647685994
Sun225124.593.61FemaleNoSunDinner46.15Tonya Carter4832732618637221
Sun967925.294.71MaleNoSunDinner46.32Erik Smith213140353657882
\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
total_billtipsexsmokerdaytimesizeprice_per_personPayer NameCC Number
Payment ID
Sat265729.035.92MaleNoSatDinner39.68Michael Avila5296068606052842
Sat176627.182.00FemaleYesSatDinner213.59Monica Sanders3506806155565404
Sat388022.672.00MaleYesSatDinner211.34Keith Wong6011891618747196
Sat1717.821.75MaleNoSatDinner28.91Dennis Dixon4375220550950
Thur67218.783.00FemaleNoThurDinner29.39Michelle Hardin3511451626698139
\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
total_billtipsexsmokerdaytimesizeprice_per_personPayer NameCC Number
Payment ID
Sat176627.182.00FemaleYesSatDinner213.59Monica Sanders3506806155565404
Sat388022.672.00MaleYesSatDinner211.34Keith Wong6011891618747196
Sat1717.821.75MaleNoSatDinner28.91Dennis Dixon4375220550950
Thur67218.783.00FemaleNoThurDinner29.39Michelle Hardin3511451626698139
Sun295916.991.01FemaleNoSunDinner28.49Christy Cunningham3560325168603410
\n", "
" ], "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 }