{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Introducing Thanksgiving Dinner Data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>RespondentID</th>\n",
       "      <th>Do you celebrate Thanksgiving?</th>\n",
       "      <th>What is typically the main dish at your Thanksgiving dinner?</th>\n",
       "      <th>What is typically the main dish at your Thanksgiving dinner? - Other (please specify)</th>\n",
       "      <th>How is the main dish typically cooked?</th>\n",
       "      <th>How is the main dish typically cooked? - Other (please specify)</th>\n",
       "      <th>What kind of stuffing/dressing do you typically have?</th>\n",
       "      <th>What kind of stuffing/dressing do you typically have? - Other (please specify)</th>\n",
       "      <th>What type of cranberry saucedo you typically have?</th>\n",
       "      <th>What type of cranberry saucedo you typically have? - Other (please specify)</th>\n",
       "      <th>...</th>\n",
       "      <th>Have you ever tried to meet up with hometown friends on Thanksgiving night?</th>\n",
       "      <th>Have you ever attended a \"Friendsgiving?\"</th>\n",
       "      <th>Will you shop any Black Friday sales on Thanksgiving Day?</th>\n",
       "      <th>Do you work in retail?</th>\n",
       "      <th>Will you employer make you work on Black Friday?</th>\n",
       "      <th>How would you describe where you live?</th>\n",
       "      <th>Age</th>\n",
       "      <th>What is your gender?</th>\n",
       "      <th>How much total combined money did all members of your HOUSEHOLD earn last year?</th>\n",
       "      <th>US Region</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>4337954960</td>\n",
       "      <td>Yes</td>\n",
       "      <td>Turkey</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Baked</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Bread-based</td>\n",
       "      <td>NaN</td>\n",
       "      <td>None</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>Yes</td>\n",
       "      <td>No</td>\n",
       "      <td>No</td>\n",
       "      <td>No</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Suburban</td>\n",
       "      <td>18 - 29</td>\n",
       "      <td>Male</td>\n",
       "      <td>$75,000 to $99,999</td>\n",
       "      <td>Middle Atlantic</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>4337951949</td>\n",
       "      <td>Yes</td>\n",
       "      <td>Turkey</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Baked</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Bread-based</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Other (please specify)</td>\n",
       "      <td>Homemade cranberry gelatin ring</td>\n",
       "      <td>...</td>\n",
       "      <td>No</td>\n",
       "      <td>No</td>\n",
       "      <td>Yes</td>\n",
       "      <td>No</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Rural</td>\n",
       "      <td>18 - 29</td>\n",
       "      <td>Female</td>\n",
       "      <td>$50,000 to $74,999</td>\n",
       "      <td>East South Central</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4337935621</td>\n",
       "      <td>Yes</td>\n",
       "      <td>Turkey</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Roasted</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Rice-based</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Homemade</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>Yes</td>\n",
       "      <td>Yes</td>\n",
       "      <td>Yes</td>\n",
       "      <td>No</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Suburban</td>\n",
       "      <td>18 - 29</td>\n",
       "      <td>Male</td>\n",
       "      <td>$0 to $9,999</td>\n",
       "      <td>Mountain</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4337933040</td>\n",
       "      <td>Yes</td>\n",
       "      <td>Turkey</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Baked</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Bread-based</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Homemade</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>Yes</td>\n",
       "      <td>No</td>\n",
       "      <td>No</td>\n",
       "      <td>No</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Urban</td>\n",
       "      <td>30 - 44</td>\n",
       "      <td>Male</td>\n",
       "      <td>$200,000 and up</td>\n",
       "      <td>Pacific</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4337931983</td>\n",
       "      <td>Yes</td>\n",
       "      <td>Tofurkey</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Baked</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Bread-based</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Canned</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>Yes</td>\n",
       "      <td>No</td>\n",
       "      <td>No</td>\n",
       "      <td>No</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Urban</td>\n",
       "      <td>30 - 44</td>\n",
       "      <td>Male</td>\n",
       "      <td>$100,000 to $124,999</td>\n",
       "      <td>Pacific</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 65 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   RespondentID Do you celebrate Thanksgiving?  \\\n",
       "0    4337954960                            Yes   \n",
       "1    4337951949                            Yes   \n",
       "2    4337935621                            Yes   \n",
       "3    4337933040                            Yes   \n",
       "4    4337931983                            Yes   \n",
       "\n",
       "  What is typically the main dish at your Thanksgiving dinner?  \\\n",
       "0                                             Turkey             \n",
       "1                                             Turkey             \n",
       "2                                             Turkey             \n",
       "3                                             Turkey             \n",
       "4                                           Tofurkey             \n",
       "\n",
       "  What is typically the main dish at your Thanksgiving dinner? - Other (please specify)  \\\n",
       "0                                                NaN                                      \n",
       "1                                                NaN                                      \n",
       "2                                                NaN                                      \n",
       "3                                                NaN                                      \n",
       "4                                                NaN                                      \n",
       "\n",
       "  How is the main dish typically cooked?  \\\n",
       "0                                  Baked   \n",
       "1                                  Baked   \n",
       "2                                Roasted   \n",
       "3                                  Baked   \n",
       "4                                  Baked   \n",
       "\n",
       "  How is the main dish typically cooked? - Other (please specify)  \\\n",
       "0                                                NaN                \n",
       "1                                                NaN                \n",
       "2                                                NaN                \n",
       "3                                                NaN                \n",
       "4                                                NaN                \n",
       "\n",
       "  What kind of stuffing/dressing do you typically have?  \\\n",
       "0                                        Bread-based      \n",
       "1                                        Bread-based      \n",
       "2                                         Rice-based      \n",
       "3                                        Bread-based      \n",
       "4                                        Bread-based      \n",
       "\n",
       "  What kind of stuffing/dressing do you typically have? - Other (please specify)  \\\n",
       "0                                                NaN                               \n",
       "1                                                NaN                               \n",
       "2                                                NaN                               \n",
       "3                                                NaN                               \n",
       "4                                                NaN                               \n",
       "\n",
       "  What type of cranberry saucedo you typically have?  \\\n",
       "0                                               None   \n",
       "1                             Other (please specify)   \n",
       "2                                           Homemade   \n",
       "3                                           Homemade   \n",
       "4                                             Canned   \n",
       "\n",
       "  What type of cranberry saucedo you typically have? - Other (please specify)  \\\n",
       "0                                                NaN                            \n",
       "1                    Homemade cranberry gelatin ring                            \n",
       "2                                                NaN                            \n",
       "3                                                NaN                            \n",
       "4                                                NaN                            \n",
       "\n",
       "          ...          \\\n",
       "0         ...           \n",
       "1         ...           \n",
       "2         ...           \n",
       "3         ...           \n",
       "4         ...           \n",
       "\n",
       "  Have you ever tried to meet up with hometown friends on Thanksgiving night?  \\\n",
       "0                                                Yes                            \n",
       "1                                                 No                            \n",
       "2                                                Yes                            \n",
       "3                                                Yes                            \n",
       "4                                                Yes                            \n",
       "\n",
       "  Have you ever attended a \"Friendsgiving?\"  \\\n",
       "0                                        No   \n",
       "1                                        No   \n",
       "2                                       Yes   \n",
       "3                                        No   \n",
       "4                                        No   \n",
       "\n",
       "  Will you shop any Black Friday sales on Thanksgiving Day?  \\\n",
       "0                                                 No          \n",
       "1                                                Yes          \n",
       "2                                                Yes          \n",
       "3                                                 No          \n",
       "4                                                 No          \n",
       "\n",
       "  Do you work in retail? Will you employer make you work on Black Friday?  \\\n",
       "0                     No                                              NaN   \n",
       "1                     No                                              NaN   \n",
       "2                     No                                              NaN   \n",
       "3                     No                                              NaN   \n",
       "4                     No                                              NaN   \n",
       "\n",
       "  How would you describe where you live?      Age What is your gender?  \\\n",
       "0                               Suburban  18 - 29                 Male   \n",
       "1                                  Rural  18 - 29               Female   \n",
       "2                               Suburban  18 - 29                 Male   \n",
       "3                                  Urban  30 - 44                 Male   \n",
       "4                                  Urban  30 - 44                 Male   \n",
       "\n",
       "  How much total combined money did all members of your HOUSEHOLD earn last year?  \\\n",
       "0                                 $75,000 to $99,999                                \n",
       "1                                 $50,000 to $74,999                                \n",
       "2                                       $0 to $9,999                                \n",
       "3                                    $200,000 and up                                \n",
       "4                               $100,000 to $124,999                                \n",
       "\n",
       "            US Region  \n",
       "0     Middle Atlantic  \n",
       "1  East South Central  \n",
       "2            Mountain  \n",
       "3             Pacific  \n",
       "4             Pacific  \n",
       "\n",
       "[5 rows x 65 columns]"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "data = pd.read_csv(\"thanksgiving.csv\", encoding=\"Latin-1\")\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['RespondentID', 'Do you celebrate Thanksgiving?',\n",
       "       'What is typically the main dish at your Thanksgiving dinner?',\n",
       "       'What is typically the main dish at your Thanksgiving dinner? - Other (please specify)',\n",
       "       'How is the main dish typically cooked?',\n",
       "       'How is the main dish typically cooked? - Other (please specify)',\n",
       "       'What kind of stuffing/dressing do you typically have?',\n",
       "       'What kind of stuffing/dressing do you typically have? - Other (please specify)',\n",
       "       'What type of cranberry saucedo you typically have?',\n",
       "       'What type of cranberry saucedo you typically have? - Other (please specify)',\n",
       "       'Do you typically have gravy?',\n",
       "       'Which of these side dishes aretypically served at your Thanksgiving dinner? Please select all that apply. - Brussel sprouts',\n",
       "       'Which of these side dishes aretypically served at your Thanksgiving dinner? Please select all that apply. - Carrots',\n",
       "       'Which of these side dishes aretypically served at your Thanksgiving dinner? Please select all that apply. - Cauliflower',\n",
       "       'Which of these side dishes aretypically served at your Thanksgiving dinner? Please select all that apply. - Corn',\n",
       "       'Which of these side dishes aretypically served at your Thanksgiving dinner? Please select all that apply. - Cornbread',\n",
       "       'Which of these side dishes aretypically served at your Thanksgiving dinner? Please select all that apply. - Fruit salad',\n",
       "       'Which of these side dishes aretypically served at your Thanksgiving dinner? Please select all that apply. - Green beans/green bean casserole',\n",
       "       'Which of these side dishes aretypically served at your Thanksgiving dinner? Please select all that apply. - Macaroni and cheese',\n",
       "       'Which of these side dishes aretypically served at your Thanksgiving dinner? Please select all that apply. - Mashed potatoes',\n",
       "       'Which of these side dishes aretypically served at your Thanksgiving dinner? Please select all that apply. - Rolls/biscuits',\n",
       "       'Which of these side dishes aretypically served at your Thanksgiving dinner? Please select all that apply. - Squash',\n",
       "       'Which of these side dishes aretypically served at your Thanksgiving dinner? Please select all that apply. - Vegetable salad',\n",
       "       'Which of these side dishes aretypically served at your Thanksgiving dinner? Please select all that apply. - Yams/sweet potato casserole',\n",
       "       'Which of these side dishes aretypically served at your Thanksgiving dinner? Please select all that apply. - Other (please specify)',\n",
       "       'Which of these side dishes aretypically served at your Thanksgiving dinner? Please select all that apply. - Other (please specify).1',\n",
       "       'Which type of pie is typically served at your Thanksgiving dinner? Please select all that apply. - Apple',\n",
       "       'Which type of pie is typically served at your Thanksgiving dinner? Please select all that apply. - Buttermilk',\n",
       "       'Which type of pie is typically served at your Thanksgiving dinner? Please select all that apply. - Cherry',\n",
       "       'Which type of pie is typically served at your Thanksgiving dinner? Please select all that apply. - Chocolate',\n",
       "       'Which type of pie is typically served at your Thanksgiving dinner? Please select all that apply. - Coconut cream',\n",
       "       'Which type of pie is typically served at your Thanksgiving dinner? Please select all that apply. - Key lime',\n",
       "       'Which type of pie is typically served at your Thanksgiving dinner? Please select all that apply. - Peach',\n",
       "       'Which type of pie is typically served at your Thanksgiving dinner? Please select all that apply. - Pecan',\n",
       "       'Which type of pie is typically served at your Thanksgiving dinner? Please select all that apply. - Pumpkin',\n",
       "       'Which type of pie is typically served at your Thanksgiving dinner? Please select all that apply. - Sweet Potato',\n",
       "       'Which type of pie is typically served at your Thanksgiving dinner? Please select all that apply. - None',\n",
       "       'Which type of pie is typically served at your Thanksgiving dinner? Please select all that apply. - Other (please specify)',\n",
       "       'Which type of pie is typically served at your Thanksgiving dinner? Please select all that apply. - Other (please specify).1',\n",
       "       'Which of these desserts do you typically have at Thanksgiving dinner? Please select all that apply.   - Apple cobbler',\n",
       "       'Which of these desserts do you typically have at Thanksgiving dinner? Please select all that apply.   - Blondies',\n",
       "       'Which of these desserts do you typically have at Thanksgiving dinner? Please select all that apply.   - Brownies',\n",
       "       'Which of these desserts do you typically have at Thanksgiving dinner? Please select all that apply.   - Carrot cake',\n",
       "       'Which of these desserts do you typically have at Thanksgiving dinner? Please select all that apply.   - Cheesecake',\n",
       "       'Which of these desserts do you typically have at Thanksgiving dinner? Please select all that apply.   - Cookies',\n",
       "       'Which of these desserts do you typically have at Thanksgiving dinner? Please select all that apply.   - Fudge',\n",
       "       'Which of these desserts do you typically have at Thanksgiving dinner? Please select all that apply.   - Ice cream',\n",
       "       'Which of these desserts do you typically have at Thanksgiving dinner? Please select all that apply.   - Peach cobbler',\n",
       "       'Which of these desserts do you typically have at Thanksgiving dinner? Please select all that apply.   - None',\n",
       "       'Which of these desserts do you typically have at Thanksgiving dinner? Please select all that apply.   - Other (please specify)',\n",
       "       'Which of these desserts do you typically have at Thanksgiving dinner? Please select all that apply.   - Other (please specify).1',\n",
       "       'Do you typically pray before or after the Thanksgiving meal?',\n",
       "       'How far will you travel for Thanksgiving?',\n",
       "       'Will you watch any of the following programs on Thanksgiving? Please select all that apply. - Macy's Parade',\n",
       "       'What's the age cutoff at your \"kids' table\" at Thanksgiving?',\n",
       "       'Have you ever tried to meet up with hometown friends on Thanksgiving night?',\n",
       "       'Have you ever attended a \"Friendsgiving?\"',\n",
       "       'Will you shop any Black Friday sales on Thanksgiving Day?',\n",
       "       'Do you work in retail?',\n",
       "       'Will you employer make you work on Black Friday?',\n",
       "       'How would you describe where you live?', 'Age', 'What is your gender?',\n",
       "       'How much total combined money did all members of your HOUSEHOLD earn last year?',\n",
       "       'US Region'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.columns"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Filtering out Rows from A DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Yes    980\n",
       "No      78\n",
       "Name: Do you celebrate Thanksgiving?, dtype: int64"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[\"Do you celebrate Thanksgiving?\"].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "data = data[data[\"Do you celebrate Thanksgiving?\"] == \"Yes\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Using value_counts to Explore Main Dishes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Turkey                    859\n",
       "Other (please specify)     35\n",
       "Ham/Pork                   29\n",
       "Tofurkey                   20\n",
       "Chicken                    12\n",
       "Roast beef                 11\n",
       "I don't know                5\n",
       "Turducken                   3\n",
       "Name: What is typically the main dish at your Thanksgiving dinner?, dtype: int64"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[\"What is typically the main dish at your Thanksgiving dinner?\"].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4      Yes\n",
       "33     Yes\n",
       "69      No\n",
       "72      No\n",
       "77     Yes\n",
       "145    Yes\n",
       "175    Yes\n",
       "218     No\n",
       "243    Yes\n",
       "275     No\n",
       "393    Yes\n",
       "399    Yes\n",
       "571    Yes\n",
       "594    Yes\n",
       "628     No\n",
       "774     No\n",
       "820     No\n",
       "837    Yes\n",
       "860     No\n",
       "953    Yes\n",
       "Name: Do you typically have gravy?, dtype: object"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[data[\"What is typically the main dish at your Thanksgiving dinner?\"] == \"Tofurkey\"][\"Do you typically have gravy?\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Determining Which Pies People Eat"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Apple    514\n",
       "Name: Which type of pie is typically served at your Thanksgiving dinner? Please select all that apply. - Apple, dtype: int64"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[\"Which type of pie is typically served at your Thanksgiving dinner? Please select all that apply. - Apple\"].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False    876\n",
       "True     104\n",
       "dtype: int64"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ate_pies = (pd.isnull(data[\"Which type of pie is typically served at your Thanksgiving dinner? Please select all that apply. - Apple\"])\n",
    "&\n",
    "pd.isnull(data[\"Which type of pie is typically served at your Thanksgiving dinner? Please select all that apply. - Pecan\"])\n",
    " &\n",
    " pd.isnull(data[\"Which type of pie is typically served at your Thanksgiving dinner? Please select all that apply. - Pumpkin\"])\n",
    ")\n",
    "\n",
    "ate_pies.value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Converting Age to Numeric"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "45 - 59    269\n",
       "60+        258\n",
       "30 - 44    235\n",
       "18 - 29    185\n",
       "Name: Age, dtype: int64"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[\"Age\"].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "count    947.000000\n",
       "mean      40.089757\n",
       "std       15.352014\n",
       "min       18.000000\n",
       "25%       30.000000\n",
       "50%       45.000000\n",
       "75%       60.000000\n",
       "max       60.000000\n",
       "Name: int_age, dtype: float64"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def extract_age(age_str):\n",
    "    if pd.isnull(age_str):\n",
    "        return None\n",
    "    age_str = age_str.split(\" \")[0]\n",
    "    age_str = age_str.replace(\"+\", \"\")\n",
    "    return int(age_str)\n",
    "\n",
    "data[\"int_age\"] = data[\"Age\"].apply(extract_age)\n",
    "data[\"int_age\"].describe()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Findings\n",
    "\n",
    "Although we only have a rough approximation of age, and it skews downward because we took the first value in each string (the lower bound), we can see that the age groups of respondents are fairly evenly distributed."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Converting Income to Numeric"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "$25,000 to $49,999      166\n",
       "$50,000 to $74,999      127\n",
       "$75,000 to $99,999      127\n",
       "Prefer not to answer    118\n",
       "$100,000 to $124,999    109\n",
       "$200,000 and up          76\n",
       "$10,000 to $24,999       60\n",
       "$0 to $9,999             52\n",
       "$125,000 to $149,999     48\n",
       "$150,000 to $174,999     38\n",
       "$175,000 to $199,999     26\n",
       "Name: How much total combined money did all members of your HOUSEHOLD earn last year?, dtype: int64"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[\"How much total combined money did all members of your HOUSEHOLD earn last year?\"].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "count       829.000000\n",
       "mean      75965.018094\n",
       "std       59068.636748\n",
       "min           0.000000\n",
       "25%       25000.000000\n",
       "50%       75000.000000\n",
       "75%      100000.000000\n",
       "max      200000.000000\n",
       "Name: int_income, dtype: float64"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def extract_income(income_str):\n",
    "    if pd.isnull(income_str):\n",
    "        return None\n",
    "    income_str = income_str.split(\" \")[0]\n",
    "    if income_str == \"Prefer\":\n",
    "        return None\n",
    "    income_str = income_str.replace(\",\", \"\")\n",
    "    income_str = income_str.replace(\"$\", \"\")\n",
    "    return int(income_str)\n",
    "\n",
    "data[\"int_income\"] = data[\"How much total combined money did all members of your HOUSEHOLD earn last year?\"].apply(extract_income)\n",
    "data[\"int_income\"].describe()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Findings\n",
    "\n",
    "Although we only have a rough approximation of income, and it skews downward because we took the first value in each string (the lower bound), the average income seems to be fairly high, although there is also a large standard deviation."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Correlating Travel Distance and Income"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Thanksgiving is happening at my home--I won't travel at all                         281\n",
       "Thanksgiving is local--it will take place in the town I live in                     203\n",
       "Thanksgiving is out of town but not too far--it's a drive of a few hours or less    150\n",
       "Thanksgiving is out of town and far away--I have to drive several hours or fly       55\n",
       "Name: How far will you travel for Thanksgiving?, dtype: int64"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[data[\"int_income\"] < 150000][\"How far will you travel for Thanksgiving?\"].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Thanksgiving is happening at my home--I won't travel at all                         49\n",
       "Thanksgiving is local--it will take place in the town I live in                     25\n",
       "Thanksgiving is out of town but not too far--it's a drive of a few hours or less    16\n",
       "Thanksgiving is out of town and far away--I have to drive several hours or fly      12\n",
       "Name: How far will you travel for Thanksgiving?, dtype: int64"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[data[\"int_income\"] > 150000][\"How far will you travel for Thanksgiving?\"].value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Findings\n",
    "\n",
    "It appears that more people with high income have Thanksgiving at home than people with low income. This may be because younger students, who don't have a high income, tend to go home, whereas parents, who have higher incomes, don't."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Linking Friendship and Age"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>Have you ever attended a \"Friendsgiving?\"</th>\n",
       "      <th>No</th>\n",
       "      <th>Yes</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Have you ever tried to meet up with hometown friends on Thanksgiving night?</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>No</th>\n",
       "      <td>42.283702</td>\n",
       "      <td>37.010526</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Yes</th>\n",
       "      <td>41.475410</td>\n",
       "      <td>33.976744</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Have you ever attended a \"Friendsgiving?\"                  No        Yes\n",
       "Have you ever tried to meet up with hometown fr...                      \n",
       "No                                                  42.283702  37.010526\n",
       "Yes                                                 41.475410  33.976744"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.pivot_table(\n",
    "    index=\"Have you ever tried to meet up with hometown friends on Thanksgiving night?\", \n",
    "    columns='Have you ever attended a \"Friendsgiving?\"',\n",
    "    values=\"int_age\"\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>Have you ever attended a \"Friendsgiving?\"</th>\n",
       "      <th>No</th>\n",
       "      <th>Yes</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Have you ever tried to meet up with hometown friends on Thanksgiving night?</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>No</th>\n",
       "      <td>78914.549654</td>\n",
       "      <td>72894.736842</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Yes</th>\n",
       "      <td>78750.000000</td>\n",
       "      <td>66019.736842</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Have you ever attended a \"Friendsgiving?\"                     No           Yes\n",
       "Have you ever tried to meet up with hometown fr...                            \n",
       "No                                                  78914.549654  72894.736842\n",
       "Yes                                                 78750.000000  66019.736842"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.pivot_table(\n",
    "    index=\"Have you ever tried to meet up with hometown friends on Thanksgiving night?\", \n",
    "    columns='Have you ever attended a \"Friendsgiving?\"',\n",
    "    values=\"int_income\"\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Findings\n",
    "\n",
    "It appears that people who are younger are more likely to attend a Friendsgiving and try to meet up with friends on Thanksgiving."
   ]
  }
 ],
 "metadata": {
  "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.8.5"
  },
  "widgets": {
   "state": {},
   "version": "1.1.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
