{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Heroes Of Pymoli Data Analysis\n",
    "* Of the 1163 active players, the vast majority are male (84%). There also exists, a smaller, but notable proportion of female players (14%).\n",
    "\n",
    "* Our peak age demographic falls between 20-24 (44.8%) with secondary groups falling between 15-19 (18.60%) and 25-29 (13.4%).  \n",
    "-----"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Note\n",
    "* Instructions have been included for each segment. You do not have to follow them exactly, but they are included to help you think through the steps."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Dependencies and Setup\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "from IPython.core.interactiveshell import InteractiveShell\n",
    "InteractiveShell.ast_node_interactivity = \"all\"\n",
    "# File to Load (Remember to Change These)\n",
    "file_to_load = \"purchase_data.csv\"\n",
    "\n",
    "# Read Purchasing File and store into Pandas data frame\n",
    "purchase_data = pd.read_csv(file_to_load)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Player Count"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Display the total number of players\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'Total Players': 780}\n"
     ]
    }
   ],
   "source": [
    "purchase_anadf0 = []\n",
    "Total_Players = purchase_data['SN'].count()\n",
    "Total_Players = {'Total Players': Total_Players}\n",
    "print(Total_Players)\n",
    "# purchase_anadf0 = purchase_anadf0.append({'Total Players' : Total_Players})\n",
    "# purchase_anadf0 = purchase_anadf0.append(Total_Players)\n",
    "# print (purchase_anadf0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Purchasing Analysis (Total)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Run basic calculations to obtain number of unique items, average price, etc.\n",
    "\n",
    "\n",
    "* Create a summary data frame to hold the results\n",
    "\n",
    "\n",
    "* Optional: give the displayed data cleaner formatting\n",
    "\n",
    "\n",
    "* Display the summary data frame\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   Number unique items Average Price  Total Purchases Total Revenue\n",
      "0                  179         $3.05              780     $2,379.77\n"
     ]
    }
   ],
   "source": [
    "#purchase_anadf = {'Number unique items': (purchase_data['Item Name'].nunique())}\n",
    "Average_Price = {'Average Price': ('${:,.2f}'.format (purchase_data['Price'].mean()))}                                  \n",
    "# purchase_anadf3 = {'Total Revenue': ('${:,.2f}'.format (purchase_data['Price'].sum()))}\n",
    "\n",
    "#Purchase_df = purchase_anadfpurchase_anadfpurchase_anadfpurchase_anadf\n",
    "list_para = pd.DataFrame({'Number unique items': (purchase_data['Item Name'].nunique()), 'Average Price': '${:,.2f}'.format (purchase_data['Price'].mean())\n",
    "             , 'Total Purchases': (purchase_data['SN'].count()), 'Total Revenue': ('${:,.2f}'.format (purchase_data['Price'].sum()))\n",
    "                         }, index =[0])\n",
    "# Purchase_df0 = pd.DataFrame.from_dict(list_para, orient='index')\n",
    "print (list_para)\n",
    "# purchase_anadf4 = '${:,.2f}'.format (purchase_data['Price'])\n",
    "# purchase_anadf2 = '${:,.2f}'.format(purchase_anadf2)\n",
    "# print (dfPur_tab)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Gender Demographics"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Percentage and Count of Male Players\n",
    "\n",
    "\n",
    "* Percentage and Count of Female Players\n",
    "\n",
    "\n",
    "* Percentage and Count of Other / Non-Disclosed\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   Gender Percent of Players  Total Players\n",
      "0    Male                84%            652\n",
      "1  Female                14%            113\n",
      "2   Other                 2%             15\n"
     ]
    }
   ],
   "source": [
    "# percent and count of Male Players\n",
    "Total_players = purchase_data['Gender'].count()\n",
    "Total_male = purchase_data.loc[purchase_data['Gender'] == 'Male',['Gender']].count()\n",
    "Percent_male = ( Total_male / Total_players)\n",
    "Percent_male2 = ( Total_male / Total_players)\n",
    "Percent_male = '{:.0%}'.format(Percent_male['Gender'])\n",
    "PerCount_maledf = pd.DataFrame({\"Percent of Players\" : Percent_male, \"Total Players\" : Total_male})\n",
    "PerCount_maledf.index.name = 'Male'\n",
    "# print(PerCount_maledf)\n",
    "\n",
    "#PerCount_maledf.columns(0) = 'Gender'\n",
    "# percent and count of Female Players\n",
    "Total_female = purchase_data.loc[purchase_data['Gender'] == 'Female',['Gender']].count()\n",
    "Percent_female = ( Total_female / Total_players)\n",
    "Percent_female2 = ( Total_female / Total_players)\n",
    "Percent_female = '{:.0%}'.format(Percent_female['Gender'])\n",
    "PerCount_femaledf = pd.DataFrame({\"Percent of Players\" : Percent_female, \"Total Players\" : Total_female})\n",
    "PerCount_femaledf.index.name = 'Female'\n",
    "\n",
    "# percent and count of other Players\n",
    "# Other / Non-Disclosed\n",
    "Total_other = purchase_data.loc[purchase_data['Gender'] == 'Other / Non-Disclosed',['Gender']].count()\n",
    "Percent_other = ( Total_other / Total_players)\n",
    "Percent_other2 = ( Total_other / Total_players)\n",
    "Percent_other = '{:.0%}'.format(Percent_other['Gender'])\n",
    "PerCount_otherdf = pd.DataFrame({\"Percent of Players\" : Percent_other, \"Total Players\" : Total_other})\n",
    "PerCount_otherdf.index.name = 'Other'\n",
    "# print (Percent_other)\n",
    "# merge tables \n",
    "# print(Percent_male2 * int(purchase_data['Price'].sum()))\n",
    "gender_demodf = pd.merge(PerCount_maledf, PerCount_femaledf, how='outer')\n",
    "gender_demodf = pd.merge(gender_demodf, PerCount_otherdf, how='outer')\n",
    "gender = ['Male', 'Female', 'Other']\n",
    "idx = 0\n",
    "gender_demodf.insert(loc=idx, column = 'Gender', value = gender)\n",
    "print(gender_demodf)\n",
    "#df.insert(idx, column='A', value=new_col)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "#def add_mkt_return(grp):\n",
    "#   .....:     grp['mkt_return'] = grp['return'].sum()\n",
    "#   .....:     return grp\n",
    "#   .....: \n",
    "\n",
    "#In [238]: df.groupby('yearmonth').apply(add_mkt_return)\n",
    "#Out[238]: "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "## Purchasing Analysis (Gender)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Run basic calculations to obtain purchase count, avg. purchase price, avg. purchase total per person etc. by gender\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "* Create a summary data frame to hold the results\n",
    "\n",
    "\n",
    "* Optional: give the displayed data cleaner formatting\n",
    "\n",
    "\n",
    "* Display the summary data frame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   Gender  Purchase Count  Average Purchase Price  Total Purchase Value  \\\n",
      "0    Male             652                3.017853                  1989   \n",
      "1  Female             113                3.203009                   344   \n",
      "2   Other              15                3.050987                    45   \n",
      "\n",
      "   Avg Purchase Total per Person  \n",
      "0                       4.065372  \n",
      "1                       4.468395  \n",
      "2                       4.562727  \n"
     ]
    }
   ],
   "source": [
    "\n",
    "\n",
    "\n",
    "# percent and count of Male Players\n",
    "Total_players = purchase_data['Gender'].count()\n",
    "Total_male = purchase_data.loc[purchase_data['Gender'] == 'Male',['Gender']].count()\n",
    "Totalavg_male = purchase_data['Price'].loc[purchase_data['Gender'] == 'Male'].mean()\n",
    "# Totalavgall_male = (purchase_data['Price'].sum()) / (purchase_data['Gender'] == 'Male').count()\n",
    "Totalavgall_male = (purchase_data[(purchase_data['Gender'] == 'Male')]['Price'].sum()) / (purchase_data[(purchase_data['Gender'] == 'Male')]['SN'].nunique())\n",
    "\n",
    "# print(Totalavgall_male)\n",
    "Total_malePurchase = int((Total_male / Total_players) * (purchase_data['Price'].sum()))\n",
    "\n",
    "# print(Total_malePurchase)\n",
    "PerCount_maledf = pd.DataFrame({\"Purchase Count\" : Total_male, \"Average Purchase Price\": Totalavg_male, \"Total Purchase Value\" : Total_malePurchase, \"Avg Purchase Total per Person\" : Totalavgall_male})\n",
    "PerCount_maledf.index.name = 'Male'\n",
    "# print(PerCount_maledf)\n",
    "\n",
    "\n",
    "# percent and count of Female Players\n",
    "Total_female = purchase_data.loc[purchase_data['Gender'] == 'Female',['Gender']].count()\n",
    "Total_femalePurchase = int(( Total_female / Total_players) * (purchase_data['Price'].sum()))\n",
    "Totalavg_female = purchase_data['Price'].loc[purchase_data['Gender'] == 'Female'].mean()\n",
    "Totalavgall_female = (purchase_data[(purchase_data['Gender'] == 'Female')]['Price'].sum()) / (purchase_data[(purchase_data['Gender'] == 'Female')]['SN'].nunique())\n",
    "# Percent_female2 = ( Total_female / Total_players)\n",
    "# Percent_female = '{:.0%}'.format(Percent_female['Gender'])\n",
    "PerCount_femaledf = pd.DataFrame({\"Purchase Count\" : Total_female,\"Average Purchase Price\": Totalavg_female, \"Total Purchase Value\" : Total_femalePurchase, \"Avg Purchase Total per Person\": Totalavgall_female})           \n",
    "PerCount_femaledf.index.name = 'Female'\n",
    "# print(PerCount_femaledf)\n",
    "\n",
    "# percent and count of other Players\n",
    "# Other / Non-Disclosed\n",
    "Total_other = purchase_data.loc[purchase_data['Gender'] == 'Other / Non-Disclosed',['Gender']].count()\n",
    "# Percent_other = ( Total_other / Total_players)\n",
    "Total_otherPurchase = int(((purchase_data['Price'].sum() * (Total_other / Total_players))))\n",
    "Totalavg_other = purchase_data['Price'].loc[pd.notnull(purchase_data['Gender'] == 'Other / Non-Disclosed')].mean()\n",
    "\n",
    "# Totalavgall_other = (purchase_data['Price'].sum()) / purchase_data[(purchase_data['Gender'] == 'Other / Non-Disclosed')]['SN'].nunique()\n",
    "Totalavgall_other = (purchase_data[(purchase_data['Gender'] == 'Other / Non-Disclosed')]['Price'].sum()) / (purchase_data[(purchase_data['Gender'] == 'Other / Non-Disclosed')]['SN'].nunique())\n",
    "\n",
    "# print(Totalavgall_other)\n",
    "# df.groupby('ID')['domain'].nunique()\n",
    "# print(purchase_data['Price'].sum())\n",
    "# print(purchase_data[(purchase_data['Gender'] == 'Other / Non-Disclosed')].count())\n",
    "\n",
    "# Percent_other2 = ( Total_other / Total_players)\n",
    "# Percent_other = '{:.0%}'.format(Percent_other['Gender'])\n",
    "#PerCount_otherdf = pd.DataFrame({\"Purchase Count\" : Total_other, \"Total Purchase Value\" : Total_otherPurchase})\n",
    "PerCount_otherdf = pd.DataFrame({\"Purchase Count\" : Total_other,\"Average Purchase Price\": Totalavg_other, \"Total Purchase Value\" : Total_otherPurchase, \"Avg Purchase Total per Person\": Totalavgall_other})           \n",
    "PerCount_otherdf.index.name = 'Other'\n",
    "# print(PerCount_otherdf)\n",
    "# print (Percent_other)\n",
    "# merge tables \n",
    "# print(Percent_male2 * int(purchase_data['Price'].sum()))\n",
    "gender_demodf = pd.merge(PerCount_maledf, PerCount_femaledf, how='outer')\n",
    "gender_demodf = pd.merge(gender_demodf, PerCount_otherdf, how='outer')\n",
    "gender = ['Male', 'Female', 'Other']\n",
    "idx = 0\n",
    "gender_demodf.insert(loc=idx, column = 'Gender', value = gender)\n",
    "print(gender_demodf)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Age Demographics"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Establish bins for ages\n",
    "\n",
    "\n",
    "* Categorize the existing players using the age bins. Hint: use pd.cut()\n",
    "\n",
    "\n",
    "* Calculate the numbers and percentages by age group\n",
    "\n",
    "\n",
    "* Create a summary data frame to hold the results\n",
    "\n",
    "\n",
    "* Optional: round the percentage column to two decimal points\n",
    "\n",
    "\n",
    "* Display Age Demographics Table\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Purchase ID</th>\n",
       "      <th>SN</th>\n",
       "      <th>Age</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Item ID</th>\n",
       "      <th>Item Name</th>\n",
       "      <th>Price</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Age Range</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>&lt;10</th>\n",
       "      <td>778</td>\n",
       "      <td>Tyeurith29</td>\n",
       "      <td>9</td>\n",
       "      <td>Male</td>\n",
       "      <td>179</td>\n",
       "      <td>Wolf, Promise of the Moonwalker</td>\n",
       "      <td>4.93</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10-14</th>\n",
       "      <td>774</td>\n",
       "      <td>Zhisrisu83</td>\n",
       "      <td>14</td>\n",
       "      <td>Male</td>\n",
       "      <td>180</td>\n",
       "      <td>Wolf</td>\n",
       "      <td>4.94</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15-19</th>\n",
       "      <td>771</td>\n",
       "      <td>Yoishirrala98</td>\n",
       "      <td>19</td>\n",
       "      <td>Other / Non-Disclosed</td>\n",
       "      <td>183</td>\n",
       "      <td>Yearning Mageblade</td>\n",
       "      <td>4.91</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20-24</th>\n",
       "      <td>779</td>\n",
       "      <td>Zontibe81</td>\n",
       "      <td>24</td>\n",
       "      <td>Other / Non-Disclosed</td>\n",
       "      <td>183</td>\n",
       "      <td>Yearning Mageblade</td>\n",
       "      <td>4.99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25-29</th>\n",
       "      <td>772</td>\n",
       "      <td>Yasur35</td>\n",
       "      <td>29</td>\n",
       "      <td>Other / Non-Disclosed</td>\n",
       "      <td>183</td>\n",
       "      <td>Worldbreaker</td>\n",
       "      <td>4.94</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30-34</th>\n",
       "      <td>770</td>\n",
       "      <td>Yarolwen77</td>\n",
       "      <td>34</td>\n",
       "      <td>Male</td>\n",
       "      <td>178</td>\n",
       "      <td>Yearning Mageblade</td>\n",
       "      <td>4.93</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35-39</th>\n",
       "      <td>768</td>\n",
       "      <td>Tyaerith73</td>\n",
       "      <td>39</td>\n",
       "      <td>Other / Non-Disclosed</td>\n",
       "      <td>179</td>\n",
       "      <td>Wolf, Promise of the Moonwalker</td>\n",
       "      <td>4.91</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40+</th>\n",
       "      <td>761</td>\n",
       "      <td>Salilis27</td>\n",
       "      <td>45</td>\n",
       "      <td>Male</td>\n",
       "      <td>173</td>\n",
       "      <td>Victor Iron Spikes</td>\n",
       "      <td>4.93</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           Purchase ID             SN  Age                 Gender  Item ID  \\\n",
       "Age Range                                                                    \n",
       "<10                778     Tyeurith29    9                   Male      179   \n",
       "10-14              774     Zhisrisu83   14                   Male      180   \n",
       "15-19              771  Yoishirrala98   19  Other / Non-Disclosed      183   \n",
       "20-24              779      Zontibe81   24  Other / Non-Disclosed      183   \n",
       "25-29              772        Yasur35   29  Other / Non-Disclosed      183   \n",
       "30-34              770     Yarolwen77   34                   Male      178   \n",
       "35-39              768     Tyaerith73   39  Other / Non-Disclosed      179   \n",
       "40+                761      Salilis27   45                   Male      173   \n",
       "\n",
       "                                 Item Name  Price  \n",
       "Age Range                                          \n",
       "<10        Wolf, Promise of the Moonwalker   4.93  \n",
       "10-14                                 Wolf   4.94  \n",
       "15-19                   Yearning Mageblade   4.91  \n",
       "20-24                   Yearning Mageblade   4.99  \n",
       "25-29                         Worldbreaker   4.94  \n",
       "30-34                   Yearning Mageblade   4.93  \n",
       "35-39      Wolf, Promise of the Moonwalker   4.91  \n",
       "40+                     Victor Iron Spikes   4.93  "
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Age Range</th>\n",
       "      <th>Percent of Players</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>23</td>\n",
       "      <td>2.95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>28</td>\n",
       "      <td>3.59</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>136</td>\n",
       "      <td>17.44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>365</td>\n",
       "      <td>46.79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>101</td>\n",
       "      <td>12.95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>73</td>\n",
       "      <td>9.36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>41</td>\n",
       "      <td>5.26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>13</td>\n",
       "      <td>1.67</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Age Range Percent of Players\n",
       "0         23               2.95\n",
       "1         28               3.59\n",
       "2        136              17.44\n",
       "3        365              46.79\n",
       "4        101              12.95\n",
       "5         73               9.36\n",
       "6         41               5.26\n",
       "7         13               1.67"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Total Count</th>\n",
       "      <th>Percent of Players</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Age Range</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>&lt;10</th>\n",
       "      <td>23</td>\n",
       "      <td>2.95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10-14</th>\n",
       "      <td>28</td>\n",
       "      <td>3.59</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15-19</th>\n",
       "      <td>136</td>\n",
       "      <td>17.44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20-24</th>\n",
       "      <td>365</td>\n",
       "      <td>46.79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25-29</th>\n",
       "      <td>101</td>\n",
       "      <td>12.95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30-34</th>\n",
       "      <td>73</td>\n",
       "      <td>9.36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35-39</th>\n",
       "      <td>41</td>\n",
       "      <td>5.26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40+</th>\n",
       "      <td>13</td>\n",
       "      <td>1.67</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           Total Count Percent of Players\n",
       "Age Range                                \n",
       "<10                 23               2.95\n",
       "10-14               28               3.59\n",
       "15-19              136              17.44\n",
       "20-24              365              46.79\n",
       "25-29              101              12.95\n",
       "30-34               73               9.36\n",
       "35-39               41               5.26\n",
       "40+                 13               1.67"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "df_age2 = pd.DataFrame(purchase_data)\n",
    "bins = [0, 9.90, 14.90, 19.90, 24.90, 29.90, 34.90, 39.90, 99999]\n",
    "group_names = ['<10', '10-14','15-19', '20-24', '25-29', '30-34', '35-39', '40+']\n",
    "df_age2[\"Age Range\"] = pd.cut(purchase_data[\"Age\"], bins, labels=group_names)\n",
    "df_age2= df_age2.groupby(\"Age Range\")\n",
    "df_age2.max()\n",
    "# df_age2 = df_age2.groupby('Age Range')\n",
    "# df_age2.head(0)\n",
    "age_count = pd.DataFrame((df_age2['Age Range'].count()))\n",
    "# df_age2= pd.DataFrame(\n",
    "\n",
    "age_count[\"Percent of Players\"] = (age_count['Age Range'].divide((purchase_data['SN'].count())))*100\n",
    "\n",
    "\n",
    "age_count['Percent of Players'] = age_count['Percent of Players'].apply('{:.2f}'.format)\n",
    "age_count.reset_index(drop=True)\n",
    "age_count = age_count.rename(columns={'Age Range': 'Total Count'})\n",
    "#age_count[\"Age Range\"] = age_count[\"Percent of Players\"]\n",
    "# ('{:.2f}'.format(age_count['Percent of Players']))\n",
    "\n",
    "# df = df.rename(columns={'oldName1': 'newName1', 'oldName2': 'newName2'})\n",
    "\n",
    "# df['Rate'] = df['Rate'].apply('{:.2f}%'.format)\n",
    "# format(math.pi, '.2f')\n",
    "# df['c'] = df['a'].divide(df['b'], fill_value=1)\n",
    "# (\"{0:.2f}\".format(a))\n",
    "\n",
    "age_count.head(10)\n",
    "\n",
    "\n",
    "# df_age = pd.DataFrame(df_age['Age Range'].count())\n",
    "# df_age[\"Percentage of Players\"] = df_age(age_count[\"Age Range\"] / (purchase_data['SN'].count()))\n",
    "#age_count = ((age_count[\"Age Range\"] / purchase_data['Gender'].count()) * 100)\n",
    "\n",
    "# age_count = ((df_age2['Age Range'].count()))\n",
    "# b = np.insert(a, insert_index, values=a[:,2], axis=1)\n",
    "# df.insert( index,name,value)\n",
    "\n",
    "# df_age[\"Percent of Players\"] = df_age[\"Age Range\"]\n",
    "# df_age2.reset_index()\n",
    "\n",
    "# df_age.set_index(['Age Range', 'Total Count'])\n",
    "# df.set_index(['year', 'month'])\n",
    "# df_age[\"Percentage of Players\"] = df_age[\"Age Range\"] / (purchase_data['SN'].count())\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Purchasing Analysis (Age)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Bin the purchase_data data frame by age\n",
    "\n",
    "\n",
    "* Run basic calculations to obtain purchase count, avg. purchase price, avg. purchase total per person etc. in the table below\n",
    "\n",
    "\n",
    "* Create a summary data frame to hold the results\n",
    "\n",
    "\n",
    "* Optional: give the displayed data cleaner formatting\n",
    "\n",
    "\n",
    "* Display the summary data frame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "            SN    Price\n",
      "Age Range              \n",
      "<10         23    77.13\n",
      "10-14       28    82.78\n",
      "15-19      136   412.89\n",
      "20-24      365  1114.06\n",
      "25-29      101   293.00\n",
      "30-34       73   214.00\n",
      "35-39       41   147.67\n",
      "40+         13    38.24\n"
     ]
    }
   ],
   "source": [
    "\n",
    "df_purchase = pd.DataFrame(purchase_data)\n",
    "bins = [0, 9.90, 14.90, 19.90, 24.90, 29.90, 34.90, 39.90, 99999]\n",
    "group_names = ['<10', '10-14','15-19', '20-24', '25-29', '30-34', '35-39', '40+']\n",
    "df_purchase[\"Age Range\"] = pd.cut(purchase_data[\"Age\"], bins, labels=group_names)\n",
    "\n",
    "#df_purchasedf= df_purchase[[\"Age Range\", \"SN\", \"Price\"]]\n",
    "# print(df_purchasedf)\n",
    "df_purchasedf= df_purchase.groupby(['Age Range']).agg({'SN': \"count\", 'Price': \"sum\"})\n",
    "print(df_purchasedf)\n",
    "#\n",
    "#new_group = df_topspenders.groupby(['SN']).agg({ 'SN': \"count\", 'Price': \"sum\"})\n",
    "#new_group2 = new_group.sort_values(by='SN', ascending=False)\n",
    "#new_group2\n",
    "#new_group2['Average'] =round((new_group2['Price']/new_group2['SN']),2)\n",
    "#\n",
    "\n",
    "\n",
    "#df_purchasedf\n",
    "#df_purchasedf1 = df_purchasedf['Age Range'].count()\n",
    "#df_purchasedf2 = df_purchasedf['Price'].sum() / df_purchasedf['Age Range'].count()\n",
    "#df_purchasedf3 = pd.DataFrame[df_purchasedf['SN'].mean()]\n",
    "# df_purchasedf[ \"Purchase Count\", \"Average Purchase Price\",\t\"Total Purchase Value\",\t\"Average Purchase Total per Person\"] = \n",
    "#            [df_purchasedf['SN'].count(), df_purchasedf[''] \n",
    "# df_purchase.sort_index(by='Age Range',ascending=False)\n",
    "\n",
    "# df_count_purchase = pd.DataFrame((df_purchase['Age Range'].count()))\n",
    "\n",
    "# Averag_price = df_purchase['Price'].sum()/ df_purchase['Price'].count()\n",
    "# Totalg_price = df_purchase['Price'].sum()\n",
    "# df_purchase.head()\n",
    "#df_purchasedf.head()\n",
    "# AverPur_Total = df_purchase.groupby('SN')['Price'].mean()\n",
    "# df.groupby('male')['age'].mean()\n",
    "#df_count_purchase.head()\n",
    "# df.groupby(['reciept','date'])['reciept'].count()\n",
    "# df_age2 = df_age2.groupby('Age Range')\n",
    "# df_age2.head(0)\n",
    "#age_count = pd.DataFrame((df_age2['Age Range'].count()))\n",
    "# df_age2= pd.DataFrame(\n",
    "\n",
    "#age_count[\"Percent of Players\"] = (age_count['Age Range'].divide((purchase_data['SN'].count())))*100\n",
    "\n",
    "\n",
    "#age_count['Percent of Players'] = age_count['Percent of Players'].apply('{:.2f}'.format)\n",
    "#age_count.reset_index(drop=True)\n",
    "#age_count = age_count.rename(columns={'Age Range': 'Total Count'})\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "#Purchase Count\tAverage Purchase Price\tTotal Purchase Value\tAvg Total Purchase per Person\n",
    "#10-14\t28\t$2.96\t$82.78\t$3.76\n",
    "#15-19\t136\t$3.04\t$412.89\t$3.86\n",
    "#20-24\t365\t$3.05\t$1,114.06\t$4.3"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Top Spenders"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Run basic calculations to obtain the results in the table below\n",
    "\n",
    "\n",
    "* Create a summary data frame to hold the results\n",
    "\n",
    "\n",
    "* Sort the total purchase value column in descending order\n",
    "\n",
    "\n",
    "* Optional: give the displayed data cleaner formatting\n",
    "\n",
    "\n",
    "* Display a preview of the summary data frame\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\lcc25\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:3: FutureWarning: 'SN' is both an index level and a column label.\n",
      "Defaulting to column, but this will raise an ambiguity error in a future version\n",
      "  This is separate from the ipykernel package so we can avoid doing imports until\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>SN</th>\n",
       "      <th>Price</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SN</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Lisosia93</th>\n",
       "      <td>5</td>\n",
       "      <td>18.96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Iral74</th>\n",
       "      <td>4</td>\n",
       "      <td>13.62</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Idastidru52</th>\n",
       "      <td>4</td>\n",
       "      <td>15.45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Asur53</th>\n",
       "      <td>3</td>\n",
       "      <td>7.44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Inguron55</th>\n",
       "      <td>3</td>\n",
       "      <td>11.11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Aina42</th>\n",
       "      <td>3</td>\n",
       "      <td>9.22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ilarin91</th>\n",
       "      <td>3</td>\n",
       "      <td>12.70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Idai61</th>\n",
       "      <td>3</td>\n",
       "      <td>8.23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Umolrian85</th>\n",
       "      <td>3</td>\n",
       "      <td>8.13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ialallo29</th>\n",
       "      <td>3</td>\n",
       "      <td>11.84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tyisur83</th>\n",
       "      <td>3</td>\n",
       "      <td>5.36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tyidaim51</th>\n",
       "      <td>3</td>\n",
       "      <td>11.83</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Pheodaisun84</th>\n",
       "      <td>3</td>\n",
       "      <td>8.31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hiaral50</th>\n",
       "      <td>3</td>\n",
       "      <td>4.19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Haillyrgue51</th>\n",
       "      <td>3</td>\n",
       "      <td>9.50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zontibe81</th>\n",
       "      <td>3</td>\n",
       "      <td>8.03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Iri67</th>\n",
       "      <td>3</td>\n",
       "      <td>11.37</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hada39</th>\n",
       "      <td>3</td>\n",
       "      <td>8.57</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Raesty92</th>\n",
       "      <td>3</td>\n",
       "      <td>8.73</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Rarallo90</th>\n",
       "      <td>3</td>\n",
       "      <td>9.05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chadolyla44</th>\n",
       "      <td>3</td>\n",
       "      <td>11.46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Saedaiphos46</th>\n",
       "      <td>3</td>\n",
       "      <td>8.83</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Saistyphos30</th>\n",
       "      <td>3</td>\n",
       "      <td>10.33</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Siallylis44</th>\n",
       "      <td>3</td>\n",
       "      <td>10.37</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chamimla85</th>\n",
       "      <td>3</td>\n",
       "      <td>6.30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Silaera56</th>\n",
       "      <td>3</td>\n",
       "      <td>8.48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chamjask73</th>\n",
       "      <td>3</td>\n",
       "      <td>13.83</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chanastnya43</th>\n",
       "      <td>3</td>\n",
       "      <td>8.82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Strithenu87</th>\n",
       "      <td>3</td>\n",
       "      <td>10.18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sondastsda82</th>\n",
       "      <td>3</td>\n",
       "      <td>7.89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Haerith37</th>\n",
       "      <td>1</td>\n",
       "      <td>1.66</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Iduelis31</th>\n",
       "      <td>1</td>\n",
       "      <td>1.10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hiral75</th>\n",
       "      <td>1</td>\n",
       "      <td>1.98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Idaisuir85</th>\n",
       "      <td>1</td>\n",
       "      <td>3.15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Idacal95</th>\n",
       "      <td>1</td>\n",
       "      <td>2.07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Iathenudil29</th>\n",
       "      <td>1</td>\n",
       "      <td>4.60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Iathem87</th>\n",
       "      <td>1</td>\n",
       "      <td>3.19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Iasursti71</th>\n",
       "      <td>1</td>\n",
       "      <td>1.66</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Iasurriacal29</th>\n",
       "      <td>1</td>\n",
       "      <td>4.07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Iarallo65</th>\n",
       "      <td>1</td>\n",
       "      <td>1.75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Iana95</th>\n",
       "      <td>1</td>\n",
       "      <td>3.10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ialidru40</th>\n",
       "      <td>1</td>\n",
       "      <td>3.16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Iadueria43</th>\n",
       "      <td>1</td>\n",
       "      <td>1.71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hyaduesu61</th>\n",
       "      <td>1</td>\n",
       "      <td>4.23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hisridru55</th>\n",
       "      <td>1</td>\n",
       "      <td>3.08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hilaerin92</th>\n",
       "      <td>1</td>\n",
       "      <td>3.61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Haerithp41</th>\n",
       "      <td>1</td>\n",
       "      <td>4.40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hiasurria41</th>\n",
       "      <td>1</td>\n",
       "      <td>1.61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hiarideu73</th>\n",
       "      <td>1</td>\n",
       "      <td>2.50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Heunadil74</th>\n",
       "      <td>1</td>\n",
       "      <td>1.54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Heudai45</th>\n",
       "      <td>1</td>\n",
       "      <td>3.47</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Heollyriap59</th>\n",
       "      <td>1</td>\n",
       "      <td>3.47</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Heollyra92</th>\n",
       "      <td>1</td>\n",
       "      <td>3.07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hariphos58</th>\n",
       "      <td>1</td>\n",
       "      <td>2.05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hallysucal81</th>\n",
       "      <td>1</td>\n",
       "      <td>1.66</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hala31</th>\n",
       "      <td>1</td>\n",
       "      <td>1.02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Haisurra41</th>\n",
       "      <td>1</td>\n",
       "      <td>4.40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hailaphos89</th>\n",
       "      <td>1</td>\n",
       "      <td>3.81</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Haestyphos66</th>\n",
       "      <td>1</td>\n",
       "      <td>1.97</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Iskosian40</th>\n",
       "      <td>1</td>\n",
       "      <td>3.07</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>576 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "               SN  Price\n",
       "SN                      \n",
       "Lisosia93       5  18.96\n",
       "Iral74          4  13.62\n",
       "Idastidru52     4  15.45\n",
       "Asur53          3   7.44\n",
       "Inguron55       3  11.11\n",
       "Aina42          3   9.22\n",
       "Ilarin91        3  12.70\n",
       "Idai61          3   8.23\n",
       "Umolrian85      3   8.13\n",
       "Ialallo29       3  11.84\n",
       "Tyisur83        3   5.36\n",
       "Tyidaim51       3  11.83\n",
       "Pheodaisun84    3   8.31\n",
       "Hiaral50        3   4.19\n",
       "Haillyrgue51    3   9.50\n",
       "Zontibe81       3   8.03\n",
       "Iri67           3  11.37\n",
       "Hada39          3   8.57\n",
       "Raesty92        3   8.73\n",
       "Rarallo90       3   9.05\n",
       "Chadolyla44     3  11.46\n",
       "Saedaiphos46    3   8.83\n",
       "Saistyphos30    3  10.33\n",
       "Siallylis44     3  10.37\n",
       "Chamimla85      3   6.30\n",
       "Silaera56       3   8.48\n",
       "Chamjask73      3  13.83\n",
       "Chanastnya43    3   8.82\n",
       "Strithenu87     3  10.18\n",
       "Sondastsda82    3   7.89\n",
       "...            ..    ...\n",
       "Haerith37       1   1.66\n",
       "Iduelis31       1   1.10\n",
       "Hiral75         1   1.98\n",
       "Idaisuir85      1   3.15\n",
       "Idacal95        1   2.07\n",
       "Iathenudil29    1   4.60\n",
       "Iathem87        1   3.19\n",
       "Iasursti71      1   1.66\n",
       "Iasurriacal29   1   4.07\n",
       "Iarallo65       1   1.75\n",
       "Iana95          1   3.10\n",
       "Ialidru40       1   3.16\n",
       "Iadueria43      1   1.71\n",
       "Hyaduesu61      1   4.23\n",
       "Hisridru55      1   3.08\n",
       "Hilaerin92      1   3.61\n",
       "Haerithp41      1   4.40\n",
       "Hiasurria41     1   1.61\n",
       "Hiarideu73      1   2.50\n",
       "Heunadil74      1   1.54\n",
       "Heudai45        1   3.47\n",
       "Heollyriap59    1   3.47\n",
       "Heollyra92      1   3.07\n",
       "Hariphos58      1   2.05\n",
       "Hallysucal81    1   1.66\n",
       "Hala31          1   1.02\n",
       "Haisurra41      1   4.40\n",
       "Hailaphos89     1   3.81\n",
       "Haestyphos66    1   1.97\n",
       "Iskosian40      1   3.07\n",
       "\n",
       "[576 rows x 2 columns]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Count</th>\n",
       "      <th>Price</th>\n",
       "      <th>Avg Price</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SN</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Lisosia93</th>\n",
       "      <td>5</td>\n",
       "      <td>18.96</td>\n",
       "      <td>3.79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Iral74</th>\n",
       "      <td>4</td>\n",
       "      <td>13.62</td>\n",
       "      <td>3.40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Idastidru52</th>\n",
       "      <td>4</td>\n",
       "      <td>15.45</td>\n",
       "      <td>3.86</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Asur53</th>\n",
       "      <td>3</td>\n",
       "      <td>7.44</td>\n",
       "      <td>2.48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Inguron55</th>\n",
       "      <td>3</td>\n",
       "      <td>11.11</td>\n",
       "      <td>3.70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Aina42</th>\n",
       "      <td>3</td>\n",
       "      <td>9.22</td>\n",
       "      <td>3.07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ilarin91</th>\n",
       "      <td>3</td>\n",
       "      <td>12.70</td>\n",
       "      <td>4.23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Idai61</th>\n",
       "      <td>3</td>\n",
       "      <td>8.23</td>\n",
       "      <td>2.74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Umolrian85</th>\n",
       "      <td>3</td>\n",
       "      <td>8.13</td>\n",
       "      <td>2.71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ialallo29</th>\n",
       "      <td>3</td>\n",
       "      <td>11.84</td>\n",
       "      <td>3.95</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             Count  Price  Avg Price\n",
       "SN                                  \n",
       "Lisosia93        5  18.96       3.79\n",
       "Iral74           4  13.62       3.40\n",
       "Idastidru52      4  15.45       3.86\n",
       "Asur53           3   7.44       2.48\n",
       "Inguron55        3  11.11       3.70\n",
       "Aina42           3   9.22       3.07\n",
       "Ilarin91         3  12.70       4.23\n",
       "Idai61           3   8.23       2.74\n",
       "Umolrian85       3   8.13       2.71\n",
       "Ialallo29        3  11.84       3.95"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_topspenders = pd.DataFrame(purchase_data)\n",
    "new_group = df_topspenders.groupby(['SN']).agg({ 'SN': \"count\", 'Price': \"sum\"})\n",
    "new_group2 = new_group.sort_values(by='SN', ascending=False)\n",
    "new_group2\n",
    "new_group2['Average'] =round((new_group2['Price']/new_group2['SN']),2)\n",
    "# new_group2 = new_group2.reset_index(drop=False)\n",
    "new_group2.columns=['Count', 'Price', 'Avg Price']\n",
    "new_group2.head(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Purchase ID',\n",
       " 'SN',\n",
       " 'Age',\n",
       " 'Gender',\n",
       " 'Item ID',\n",
       " 'Item Name',\n",
       " 'Price',\n",
       " 'Age Range']"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Item ID</th>\n",
       "      <th>Price</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Item ID</th>\n",
       "      <th>Item Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <th>Splinter</th>\n",
       "      <td>4</td>\n",
       "      <td>5.12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <th>Crucifer</th>\n",
       "      <td>3</td>\n",
       "      <td>9.78</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <th>Verdict</th>\n",
       "      <td>6</td>\n",
       "      <td>14.88</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <th>Phantomlight</th>\n",
       "      <td>6</td>\n",
       "      <td>14.94</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <th>Bloodlord's Fetish</th>\n",
       "      <td>5</td>\n",
       "      <td>8.50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <th>Putrid Fan</th>\n",
       "      <td>4</td>\n",
       "      <td>16.32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <th>Rusty Skull</th>\n",
       "      <td>2</td>\n",
       "      <td>7.40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <th>Thorn, Satchel of Dark Souls</th>\n",
       "      <td>7</td>\n",
       "      <td>9.31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <th>Purgatory, Gem of Regret</th>\n",
       "      <td>3</td>\n",
       "      <td>11.79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <th>Thorn, Conqueror of the Corrupted</th>\n",
       "      <td>4</td>\n",
       "      <td>10.92</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                           Item ID  Price\n",
       "Item ID Item Name                                        \n",
       "0       Splinter                                 4   5.12\n",
       "1       Crucifer                                 3   9.78\n",
       "2       Verdict                                  6  14.88\n",
       "3       Phantomlight                             6  14.94\n",
       "4       Bloodlord's Fetish                       5   8.50\n",
       "5       Putrid Fan                               4  16.32\n",
       "6       Rusty Skull                              2   7.40\n",
       "7       Thorn, Satchel of Dark Souls             7   9.31\n",
       "8       Purgatory, Gem of Regret                 3  11.79\n",
       "9       Thorn, Conqueror of the Corrupted        4  10.92"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\lcc25\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:7: FutureWarning: 'Item ID' is both an index level and a column label.\n",
      "Defaulting to column, but this will raise an ambiguity error in a future version\n",
      "  import sys\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Purchase Count</th>\n",
       "      <th>Item Price</th>\n",
       "      <th>Total Purchase Value</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Item ID</th>\n",
       "      <th>Item Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>178</th>\n",
       "      <th>Oathbreaker, Last Hope of the Breaking Storm</th>\n",
       "      <td>12</td>\n",
       "      <td>4.23</td>\n",
       "      <td>50.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>145</th>\n",
       "      <th>Fiery Glass Crusader</th>\n",
       "      <td>9</td>\n",
       "      <td>4.58</td>\n",
       "      <td>41.22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>108</th>\n",
       "      <th>Extraction, Quickblade Of Trembling Hands</th>\n",
       "      <td>9</td>\n",
       "      <td>3.53</td>\n",
       "      <td>31.77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <th>Nirvana</th>\n",
       "      <td>9</td>\n",
       "      <td>4.90</td>\n",
       "      <td>44.10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <th>Pursuit, Cudgel of Necromancy</th>\n",
       "      <td>8</td>\n",
       "      <td>1.02</td>\n",
       "      <td>8.16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>103</th>\n",
       "      <th>Singed Scalpel</th>\n",
       "      <td>8</td>\n",
       "      <td>4.35</td>\n",
       "      <td>34.80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75</th>\n",
       "      <th>Brutality Ivory Warmace</th>\n",
       "      <td>8</td>\n",
       "      <td>2.42</td>\n",
       "      <td>19.36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>72</th>\n",
       "      <th>Winter's Bite</th>\n",
       "      <td>8</td>\n",
       "      <td>3.77</td>\n",
       "      <td>30.16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>60</th>\n",
       "      <th>Wolf</th>\n",
       "      <td>8</td>\n",
       "      <td>3.54</td>\n",
       "      <td>28.32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>59</th>\n",
       "      <th>Lightning, Etcher of the King</th>\n",
       "      <td>8</td>\n",
       "      <td>4.23</td>\n",
       "      <td>33.84</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                      Purchase Count  \\\n",
       "Item ID Item Name                                                      \n",
       "178     Oathbreaker, Last Hope of the Breaking Storm              12   \n",
       "145     Fiery Glass Crusader                                       9   \n",
       "108     Extraction, Quickblade Of Trembling Hands                  9   \n",
       "82      Nirvana                                                    9   \n",
       "19      Pursuit, Cudgel of Necromancy                              8   \n",
       "103     Singed Scalpel                                             8   \n",
       "75      Brutality Ivory Warmace                                    8   \n",
       "72      Winter's Bite                                              8   \n",
       "60      Wolf                                                       8   \n",
       "59      Lightning, Etcher of the King                              8   \n",
       "\n",
       "                                                      Item Price  \\\n",
       "Item ID Item Name                                                  \n",
       "178     Oathbreaker, Last Hope of the Breaking Storm        4.23   \n",
       "145     Fiery Glass Crusader                                4.58   \n",
       "108     Extraction, Quickblade Of Trembling Hands           3.53   \n",
       "82      Nirvana                                             4.90   \n",
       "19      Pursuit, Cudgel of Necromancy                       1.02   \n",
       "103     Singed Scalpel                                      4.35   \n",
       "75      Brutality Ivory Warmace                             2.42   \n",
       "72      Winter's Bite                                       3.77   \n",
       "60      Wolf                                                3.54   \n",
       "59      Lightning, Etcher of the King                       4.23   \n",
       "\n",
       "                                                      Total Purchase Value  \n",
       "Item ID Item Name                                                           \n",
       "178     Oathbreaker, Last Hope of the Breaking Storm                 50.76  \n",
       "145     Fiery Glass Crusader                                         41.22  \n",
       "108     Extraction, Quickblade Of Trembling Hands                    31.77  \n",
       "82      Nirvana                                                      44.10  \n",
       "19      Pursuit, Cudgel of Necromancy                                 8.16  \n",
       "103     Singed Scalpel                                               34.80  \n",
       "75      Brutality Ivory Warmace                                      19.36  \n",
       "72      Winter's Bite                                                30.16  \n",
       "60      Wolf                                                         28.32  \n",
       "59      Lightning, Etcher of the King                                33.84  "
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_topitem = pd.DataFrame(purchase_data)\n",
    "\n",
    "df_topitem.columns.tolist()\n",
    "df_topitem2 = df_topitem.groupby(['Item ID', 'Item Name']).agg({ 'Item ID': \"count\", 'Price': \"sum\"})\n",
    "df_topitem2.head(10)\n",
    "# new_group = df_topspenders.groupby(['SN']).agg({ 'SN': \"count\", 'Price': \"sum\"})\n",
    "new_group2 = df_topitem2.sort_values(by='Item ID', ascending=False)\n",
    "# new_group2 = new_group2.reset_index(drop=True)\n",
    "new_group2.columns=['Purchase Count', 'Total Purchase Value']\n",
    "new_group2['Item Price'] =round((new_group2['Total Purchase Value']/new_group2['Purchase Count']),2)\n",
    "# new_group2 = new_group2.reset_index(drop=FalsTo\n",
    "new_group2 = pd.DataFrame(new_group2)\n",
    "Top_purchase_item = new_group2[['Purchase Count', 'Item Price', 'Total Purchase Value']]\n",
    "Top_purchase_item.head(10)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Most Popular Items"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Retrieve the Item ID, Item Name, and Item Price columns\n",
    "\n",
    "\n",
    "* Group by Item ID and Item Name. Perform calculations to obtain purchase count, item price, and total purchase value\n",
    "\n",
    "\n",
    "* Create a summary data frame to hold the results\n",
    "\n",
    "\n",
    "* Sort the purchase count column in descending order\n",
    "\n",
    "\n",
    "* Optional: give the displayed data cleaner formatting\n",
    "\n",
    "\n",
    "* Display a preview of the summary data frame\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Purchase Count</th>\n",
       "      <th>Item Price</th>\n",
       "      <th>Total Purchase Value</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Item ID</th>\n",
       "      <th>Item Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>178</th>\n",
       "      <th>Oathbreaker, Last Hope of the Breaking Storm</th>\n",
       "      <td>12</td>\n",
       "      <td>$4.23</td>\n",
       "      <td>$50.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>145</th>\n",
       "      <th>Fiery Glass Crusader</th>\n",
       "      <td>9</td>\n",
       "      <td>$4.58</td>\n",
       "      <td>$41.22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>108</th>\n",
       "      <th>Extraction, Quickblade Of Trembling Hands</th>\n",
       "      <td>9</td>\n",
       "      <td>$3.53</td>\n",
       "      <td>$31.77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <th>Nirvana</th>\n",
       "      <td>9</td>\n",
       "      <td>$4.90</td>\n",
       "      <td>$44.10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <th>Pursuit, Cudgel of Necromancy</th>\n",
       "      <td>8</td>\n",
       "      <td>$1.02</td>\n",
       "      <td>$8.16</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                     Purchase Count  \\\n",
       "Item ID Item Name                                                     \n",
       "178     Oathbreaker, Last Hope of the Breaking Storm             12   \n",
       "145     Fiery Glass Crusader                                      9   \n",
       "108     Extraction, Quickblade Of Trembling Hands                 9   \n",
       "82      Nirvana                                                   9   \n",
       "19      Pursuit, Cudgel of Necromancy                             8   \n",
       "\n",
       "                                                     Item Price  \\\n",
       "Item ID Item Name                                                 \n",
       "178     Oathbreaker, Last Hope of the Breaking Storm      $4.23   \n",
       "145     Fiery Glass Crusader                              $4.58   \n",
       "108     Extraction, Quickblade Of Trembling Hands         $3.53   \n",
       "82      Nirvana                                           $4.90   \n",
       "19      Pursuit, Cudgel of Necromancy                     $1.02   \n",
       "\n",
       "                                                     Total Purchase Value  \n",
       "Item ID Item Name                                                          \n",
       "178     Oathbreaker, Last Hope of the Breaking Storm               $50.76  \n",
       "145     Fiery Glass Crusader                                       $41.22  \n",
       "108     Extraction, Quickblade Of Trembling Hands                  $31.77  \n",
       "82      Nirvana                                                    $44.10  \n",
       "19      Pursuit, Cudgel of Necromancy                               $8.16  "
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Purchase Count</th>\n",
       "      <th>Item Price</th>\n",
       "      <th>Total Purchase Value</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Item ID</th>\n",
       "      <th>Item Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>178</th>\n",
       "      <th>Oathbreaker, Last Hope of the Breaking Storm</th>\n",
       "      <td>12</td>\n",
       "      <td>4.23</td>\n",
       "      <td>50.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <th>Nirvana</th>\n",
       "      <td>9</td>\n",
       "      <td>4.90</td>\n",
       "      <td>44.10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>145</th>\n",
       "      <th>Fiery Glass Crusader</th>\n",
       "      <td>9</td>\n",
       "      <td>4.58</td>\n",
       "      <td>41.22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>92</th>\n",
       "      <th>Final Critic</th>\n",
       "      <td>8</td>\n",
       "      <td>4.88</td>\n",
       "      <td>39.04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>103</th>\n",
       "      <th>Singed Scalpel</th>\n",
       "      <td>8</td>\n",
       "      <td>4.35</td>\n",
       "      <td>34.80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>59</th>\n",
       "      <th>Lightning, Etcher of the King</th>\n",
       "      <td>8</td>\n",
       "      <td>4.23</td>\n",
       "      <td>33.84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>108</th>\n",
       "      <th>Extraction, Quickblade Of Trembling Hands</th>\n",
       "      <td>9</td>\n",
       "      <td>3.53</td>\n",
       "      <td>31.77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>78</th>\n",
       "      <th>Glimmer, Ender of the Moon</th>\n",
       "      <td>7</td>\n",
       "      <td>4.40</td>\n",
       "      <td>30.80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>72</th>\n",
       "      <th>Winter's Bite</th>\n",
       "      <td>8</td>\n",
       "      <td>3.77</td>\n",
       "      <td>30.16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>60</th>\n",
       "      <th>Wolf</th>\n",
       "      <td>8</td>\n",
       "      <td>3.54</td>\n",
       "      <td>28.32</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                      Purchase Count  \\\n",
       "Item ID Item Name                                                      \n",
       "178     Oathbreaker, Last Hope of the Breaking Storm              12   \n",
       "82      Nirvana                                                    9   \n",
       "145     Fiery Glass Crusader                                       9   \n",
       "92      Final Critic                                               8   \n",
       "103     Singed Scalpel                                             8   \n",
       "59      Lightning, Etcher of the King                              8   \n",
       "108     Extraction, Quickblade Of Trembling Hands                  9   \n",
       "78      Glimmer, Ender of the Moon                                 7   \n",
       "72      Winter's Bite                                              8   \n",
       "60      Wolf                                                       8   \n",
       "\n",
       "                                                      Item Price  \\\n",
       "Item ID Item Name                                                  \n",
       "178     Oathbreaker, Last Hope of the Breaking Storm        4.23   \n",
       "82      Nirvana                                             4.90   \n",
       "145     Fiery Glass Crusader                                4.58   \n",
       "92      Final Critic                                        4.88   \n",
       "103     Singed Scalpel                                      4.35   \n",
       "59      Lightning, Etcher of the King                       4.23   \n",
       "108     Extraction, Quickblade Of Trembling Hands           3.53   \n",
       "78      Glimmer, Ender of the Moon                          4.40   \n",
       "72      Winter's Bite                                       3.77   \n",
       "60      Wolf                                                3.54   \n",
       "\n",
       "                                                      Total Purchase Value  \n",
       "Item ID Item Name                                                           \n",
       "178     Oathbreaker, Last Hope of the Breaking Storm                 50.76  \n",
       "82      Nirvana                                                      44.10  \n",
       "145     Fiery Glass Crusader                                         41.22  \n",
       "92      Final Critic                                                 39.04  \n",
       "103     Singed Scalpel                                               34.80  \n",
       "59      Lightning, Etcher of the King                                33.84  \n",
       "108     Extraction, Quickblade Of Trembling Hands                    31.77  \n",
       "78      Glimmer, Ender of the Moon                                   30.80  \n",
       "72      Winter's Bite                                                30.16  \n",
       "60      Wolf                                                         28.32  "
      ]
     },
     "execution_count": 102,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "\n",
    "df_top_profit = pd.DataFrame(Top_purchase_item)\n",
    "\n",
    "df_top_profit.columns.tolist()\n",
    "# df_topitem2 = df_topitem.groupby(['Item ID', 'Item Name']).agg({ 'Item ID': \"count\", 'Price': \"sum\"})\n",
    "# df_topitem2.head(10)\n",
    "# new_group = df_topspenders.groupby(['SN']).agg({ 'SN': \"count\", 'Price': \"sum\"})\n",
    "new_group2 = df_top_profit.sort_values(by='Total Purchase Value', ascending=False)\n",
    "# new_group2 = new_group2.reset_index(drop=True)\n",
    "#new_group2.columns=['Purchase Count', 'Total Purchase Value']\n",
    "#new_group2['Item Price'] =round((new_group2['Total Purchase Value']/new_group2['Purchase Count']),2)\n",
    "# new_group2 = new_group2.reset_index(drop=FalsTo\n",
    "#new_group2 = pd.DataFrame(new_group2)\n",
    "#new_group2 = new_group2[['Purchase Count', 'Item Price', 'Total Purchase Value']]\n",
    "new_group2.head(10)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Most Profitable Items"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Sort the above table by total purchase value in descending order\n",
    "\n",
    "\n",
    "* Optional: give the displayed data cleaner formatting\n",
    "\n",
    "\n",
    "* Display a preview of the data frame\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Purchase Count</th>\n",
       "      <th>Item Price</th>\n",
       "      <th>Total Purchase Value</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Item ID</th>\n",
       "      <th>Item Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>178</th>\n",
       "      <th>Oathbreaker, Last Hope of the Breaking Storm</th>\n",
       "      <td>12</td>\n",
       "      <td>$4.23</td>\n",
       "      <td>$50.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <th>Nirvana</th>\n",
       "      <td>9</td>\n",
       "      <td>$4.90</td>\n",
       "      <td>$44.10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>145</th>\n",
       "      <th>Fiery Glass Crusader</th>\n",
       "      <td>9</td>\n",
       "      <td>$4.58</td>\n",
       "      <td>$41.22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>92</th>\n",
       "      <th>Final Critic</th>\n",
       "      <td>8</td>\n",
       "      <td>$4.88</td>\n",
       "      <td>$39.04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>103</th>\n",
       "      <th>Singed Scalpel</th>\n",
       "      <td>8</td>\n",
       "      <td>$4.35</td>\n",
       "      <td>$34.80</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                     Purchase Count  \\\n",
       "Item ID Item Name                                                     \n",
       "178     Oathbreaker, Last Hope of the Breaking Storm             12   \n",
       "82      Nirvana                                                   9   \n",
       "145     Fiery Glass Crusader                                      9   \n",
       "92      Final Critic                                              8   \n",
       "103     Singed Scalpel                                            8   \n",
       "\n",
       "                                                     Item Price  \\\n",
       "Item ID Item Name                                                 \n",
       "178     Oathbreaker, Last Hope of the Breaking Storm      $4.23   \n",
       "82      Nirvana                                           $4.90   \n",
       "145     Fiery Glass Crusader                              $4.58   \n",
       "92      Final Critic                                      $4.88   \n",
       "103     Singed Scalpel                                    $4.35   \n",
       "\n",
       "                                                     Total Purchase Value  \n",
       "Item ID Item Name                                                          \n",
       "178     Oathbreaker, Last Hope of the Breaking Storm               $50.76  \n",
       "82      Nirvana                                                    $44.10  \n",
       "145     Fiery Glass Crusader                                       $41.22  \n",
       "92      Final Critic                                               $39.04  \n",
       "103     Singed Scalpel                                             $34.80  "
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernel_info": {
   "name": "python3"
  },
  "kernelspec": {
   "display_name": "Python [default]",
   "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.5"
  },
  "nteract": {
   "version": "0.2.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}

f28f42eb08385c98389dcf68bf97064977c0c8da
<mask token>

{'cells': [{'cell_type': 'markdown', 'metadata': {}, 'source': [
    """### Heroes Of Pymoli Data Analysis
""",
    """* Of the 1163 active players, the vast majority are male (84%). There also exists, a smaller, but notable proportion of female players (14%).
"""
    , '\n',
    """* Our peak age demographic falls between 20-24 (44.8%) with secondary groups falling between 15-19 (18.60%) and 25-29 (13.4%).  
"""
    , '-----']}, {'cell_type': 'markdown', 'metadata': {}, 'source': [
    '### Note\n',
    '* Instructions have been included for each segment. You do not have to follow them exactly, but they are included to help you think through the steps.'
    ]}, {'cell_type': 'code', 'execution_count': 1, 'metadata': {},
    'outputs': [], 'source': ["""# Dependencies and Setup
""",
    'import pandas as pd\n', 'import numpy as np\n',
    """from IPython.core.interactiveshell import InteractiveShell
""",
    'InteractiveShell.ast_node_interactivity = "all"\n',
    """# File to Load (Remember to Change These)
""",
    'file_to_load = "purchase_data.csv"\n', '\n',
    """# Read Purchasing File and store into Pandas data frame
""",
    'purchase_data = pd.read_csv(file_to_load)']}, {'cell_type': 'markdown',
    'metadata': {}, 'source': ['## Player Count']}, {'cell_type':
    'markdown', 'metadata': {}, 'source': [
    """* Display the total number of players
"""]}, {'cell_type': 'code',
    'execution_count': 8, 'metadata': {}, 'outputs': [{'name': 'stdout',
    'output_type': 'stream', 'text': ["""{'Total Players': 780}
"""]}],
    'source': ['purchase_anadf0 = []\n',
    "Total_Players = purchase_data['SN'].count()\n",
    """Total_Players = {'Total Players': Total_Players}
""",
    'print(Total_Players)\n',
    """# purchase_anadf0 = purchase_anadf0.append({'Total Players' : Total_Players})
"""
    , '# purchase_anadf0 = purchase_anadf0.append(Total_Players)\n',
    '# print (purchase_anadf0)']}, {'cell_type': 'markdown', 'metadata': {},
    'source': ['## Purchasing Analysis (Total)']}, {'cell_type': 'markdown',
    'metadata': {}, 'source': [
    """* Run basic calculations to obtain number of unique items, average price, etc.
"""
    , '\n', '\n', '* Create a summary data frame to hold the results\n',
    '\n', '\n',
    """* Optional: give the displayed data cleaner formatting
""", '\n',
    '\n', '* Display the summary data frame\n']}, {'cell_type': 'code',
    'execution_count': 3, 'metadata': {'scrolled': true}, 'outputs': [{
    'name': 'stdout', 'output_type': 'stream', 'text': [
    """   Number unique items Average Price  Total Purchases Total Revenue
""",
    '0                  179         $3.05              780     $2,379.77\n'
    ]}], 'source': [
    """#purchase_anadf = {'Number unique items': (purchase_data['Item Name'].nunique())}
"""
    ,
    """Average_Price = {'Average Price': ('${:,.2f}'.format (purchase_data['Price'].mean()))}                                  
"""
    ,
    "# purchase_anadf3 = {'Total Revenue': ('${:,.2f}'.format (purchase_data['Price'].sum()))}\n"
    , '\n',
    """#Purchase_df = purchase_anadfpurchase_anadfpurchase_anadfpurchase_anadf
"""
    ,
    """list_para = pd.DataFrame({'Number unique items': (purchase_data['Item Name'].nunique()), 'Average Price': '${:,.2f}'.format (purchase_data['Price'].mean())
"""
    ,
    """             , 'Total Purchases': (purchase_data['SN'].count()), 'Total Revenue': ('${:,.2f}'.format (purchase_data['Price'].sum()))
"""
    , '                         }, index =[0])\n',
    """# Purchase_df0 = pd.DataFrame.from_dict(list_para, orient='index')
""",
    'print (list_para)\n',
    "# purchase_anadf4 = '${:,.2f}'.format (purchase_data['Price'])\n",
    """# purchase_anadf2 = '${:,.2f}'.format(purchase_anadf2)
""",
    '# print (dfPur_tab)']}, {'cell_type': 'markdown', 'metadata': {},
    'source': ['## Gender Demographics']}, {'cell_type': 'markdown',
    'metadata': {}, 'source': [
    """* Percentage and Count of Male Players
""", '\n', '\n',
    '* Percentage and Count of Female Players\n', '\n', '\n',
    """* Percentage and Count of Other / Non-Disclosed
""", '\n', '\n']}, {
    'cell_type': 'code', 'execution_count': 9, 'metadata': {}, 'outputs': [
    {'name': 'stdout', 'output_type': 'stream', 'text': [
    """   Gender Percent of Players  Total Players
""",
    '0    Male                84%            652\n',
    """1  Female                14%            113
""",
    '2   Other                 2%             15\n']}], 'source': [
    """# percent and count of Male Players
""",
    "Total_players = purchase_data['Gender'].count()\n",
    """Total_male = purchase_data.loc[purchase_data['Gender'] == 'Male',['Gender']].count()
"""
    , 'Percent_male = ( Total_male / Total_players)\n',
    """Percent_male2 = ( Total_male / Total_players)
""",
    "Percent_male = '{:.0%}'.format(Percent_male['Gender'])\n",
    """PerCount_maledf = pd.DataFrame({"Percent of Players" : Percent_male, "Total Players" : Total_male})
"""
    , "PerCount_maledf.index.name = 'Male'\n", '# print(PerCount_maledf)\n',
    '\n', """#PerCount_maledf.columns(0) = 'Gender'
""",
    '# percent and count of Female Players\n',
    """Total_female = purchase_data.loc[purchase_data['Gender'] == 'Female',['Gender']].count()
"""
    , 'Percent_female = ( Total_female / Total_players)\n',
    """Percent_female2 = ( Total_female / Total_players)
""",
    "Percent_female = '{:.0%}'.format(Percent_female['Gender'])\n",
    """PerCount_femaledf = pd.DataFrame({"Percent of Players" : Percent_female, "Total Players" : Total_female})
"""
    , "PerCount_femaledf.index.name = 'Female'\n", '\n',
    '# percent and count of other Players\n',
    """# Other / Non-Disclosed
""",
    """Total_other = purchase_data.loc[purchase_data['Gender'] == 'Other / Non-Disclosed',['Gender']].count()
"""
    , 'Percent_other = ( Total_other / Total_players)\n',
    """Percent_other2 = ( Total_other / Total_players)
""",
    "Percent_other = '{:.0%}'.format(Percent_other['Gender'])\n",
    """PerCount_otherdf = pd.DataFrame({"Percent of Players" : Percent_other, "Total Players" : Total_other})
"""
    , "PerCount_otherdf.index.name = 'Other'\n",
    '# print (Percent_other)\n', '# merge tables \n',
    """# print(Percent_male2 * int(purchase_data['Price'].sum()))
""",
    "gender_demodf = pd.merge(PerCount_maledf, PerCount_femaledf, how='outer')\n"
    ,
    """gender_demodf = pd.merge(gender_demodf, PerCount_otherdf, how='outer')
"""
    , "gender = ['Male', 'Female', 'Other']\n", 'idx = 0\n',
    """gender_demodf.insert(loc=idx, column = 'Gender', value = gender)
""",
    'print(gender_demodf)\n', "#df.insert(idx, column='A', value=new_col)"]
    }, {'cell_type': 'code', 'execution_count': 5, 'metadata': {},
    'outputs': [], 'source': ["""#def add_mkt_return(grp):
""",
    "#   .....:     grp['mkt_return'] = grp['return'].sum()\n",
    '#   .....:     return grp\n', '#   .....: \n', '\n',
    """#In [238]: df.groupby('yearmonth').apply(add_mkt_return)
""",
    '#Out[238]: ']}, {'cell_type': 'markdown', 'metadata': {}, 'source': [
    '\n', '## Purchasing Analysis (Gender)']}, {'cell_type': 'markdown',
    'metadata': {}, 'source': [
    """* Run basic calculations to obtain purchase count, avg. purchase price, avg. purchase total per person etc. by gender
"""
    , '\n', '\n', '\n', '\n',
    '* Create a summary data frame to hold the results\n', '\n', '\n',
    """* Optional: give the displayed data cleaner formatting
""", '\n',
    '\n', '* Display the summary data frame']}, {'cell_type': 'code',
    'execution_count': 11, 'metadata': {}, 'outputs': [{'name': 'stdout',
    'output_type': 'stream', 'text': [
    """   Gender  Purchase Count  Average Purchase Price  Total Purchase Value  \\
"""
    ,
    '0    Male             652                3.017853                  1989   \n'
    ,
    """1  Female             113                3.203009                   344   
"""
    ,
    '2   Other              15                3.050987                    45   \n'
    , '\n', """   Avg Purchase Total per Person  
""",
    '0                       4.065372  \n',
    '1                       4.468395  \n',
    """2                       4.562727  
"""]}], 'source': ['\n', '\n',
    '\n', '# percent and count of Male Players\n',
    """Total_players = purchase_data['Gender'].count()
""",
    "Total_male = purchase_data.loc[purchase_data['Gender'] == 'Male',['Gender']].count()\n"
    ,
    """Totalavg_male = purchase_data['Price'].loc[purchase_data['Gender'] == 'Male'].mean()
"""
    ,
    """# Totalavgall_male = (purchase_data['Price'].sum()) / (purchase_data['Gender'] == 'Male').count()
"""
    ,
    """Totalavgall_male = (purchase_data[(purchase_data['Gender'] == 'Male')]['Price'].sum()) / (purchase_data[(purchase_data['Gender'] == 'Male')]['SN'].nunique())
"""
    , '\n', '# print(Totalavgall_male)\n',
    """Total_malePurchase = int((Total_male / Total_players) * (purchase_data['Price'].sum()))
"""
    , '\n', '# print(Total_malePurchase)\n',
    """PerCount_maledf = pd.DataFrame({"Purchase Count" : Total_male, "Average Purchase Price": Totalavg_male, "Total Purchase Value" : Total_malePurchase, "Avg Purchase Total per Person" : Totalavgall_male})
"""
    , "PerCount_maledf.index.name = 'Male'\n", '# print(PerCount_maledf)\n',
    '\n', '\n', """# percent and count of Female Players
""",
    "Total_female = purchase_data.loc[purchase_data['Gender'] == 'Female',['Gender']].count()\n"
    ,
    """Total_femalePurchase = int(( Total_female / Total_players) * (purchase_data['Price'].sum()))
"""
    ,
    "Totalavg_female = purchase_data['Price'].loc[purchase_data['Gender'] == 'Female'].mean()\n"
    ,
    """Totalavgall_female = (purchase_data[(purchase_data['Gender'] == 'Female')]['Price'].sum()) / (purchase_data[(purchase_data['Gender'] == 'Female')]['SN'].nunique())
"""
    , '# Percent_female2 = ( Total_female / Total_players)\n',
    """# Percent_female = '{:.0%}'.format(Percent_female['Gender'])
""",
    """PerCount_femaledf = pd.DataFrame({"Purchase Count" : Total_female,"Average Purchase Price": Totalavg_female, "Total Purchase Value" : Total_femalePurchase, "Avg Purchase Total per Person": Totalavgall_female})           
"""
    , "PerCount_femaledf.index.name = 'Female'\n",
    '# print(PerCount_femaledf)\n', '\n',
    """# percent and count of other Players
""",
    '# Other / Non-Disclosed\n',
    """Total_other = purchase_data.loc[purchase_data['Gender'] == 'Other / Non-Disclosed',['Gender']].count()
"""
    , '# Percent_other = ( Total_other / Total_players)\n',
    """Total_otherPurchase = int(((purchase_data['Price'].sum() * (Total_other / Total_players))))
"""
    ,
    """Totalavg_other = purchase_data['Price'].loc[pd.notnull(purchase_data['Gender'] == 'Other / Non-Disclosed')].mean()
"""
    , '\n',
    """# Totalavgall_other = (purchase_data['Price'].sum()) / purchase_data[(purchase_data['Gender'] == 'Other / Non-Disclosed')]['SN'].nunique()
"""
    ,
    """Totalavgall_other = (purchase_data[(purchase_data['Gender'] == 'Other / Non-Disclosed')]['Price'].sum()) / (purchase_data[(purchase_data['Gender'] == 'Other / Non-Disclosed')]['SN'].nunique())
"""
    , '\n', '# print(Totalavgall_other)\n',
    "# df.groupby('ID')['domain'].nunique()\n",
    """# print(purchase_data['Price'].sum())
""",
    "# print(purchase_data[(purchase_data['Gender'] == 'Other / Non-Disclosed')].count())\n"
    , '\n', """# Percent_other2 = ( Total_other / Total_players)
""",
    "# Percent_other = '{:.0%}'.format(Percent_other['Gender'])\n",
    """#PerCount_otherdf = pd.DataFrame({"Purchase Count" : Total_other, "Total Purchase Value" : Total_otherPurchase})
"""
    ,
    """PerCount_otherdf = pd.DataFrame({"Purchase Count" : Total_other,"Average Purchase Price": Totalavg_other, "Total Purchase Value" : Total_otherPurchase, "Avg Purchase Total per Person": Totalavgall_other})           
"""
    , "PerCount_otherdf.index.name = 'Other'\n",
    '# print(PerCount_otherdf)\n', """# print (Percent_other)
""",
    '# merge tables \n',
    "# print(Percent_male2 * int(purchase_data['Price'].sum()))\n",
    """gender_demodf = pd.merge(PerCount_maledf, PerCount_femaledf, how='outer')
"""
    ,
    "gender_demodf = pd.merge(gender_demodf, PerCount_otherdf, how='outer')\n",
    """gender = ['Male', 'Female', 'Other']
""", 'idx = 0\n',
    "gender_demodf.insert(loc=idx, column = 'Gender', value = gender)\n",
    'print(gender_demodf)']}, {'cell_type': 'markdown', 'metadata': {},
    'source': ['## Age Demographics']}, {'cell_type': 'markdown',
    'metadata': {}, 'source': ["""* Establish bins for ages
""", '\n', '\n',
    '* Categorize the existing players using the age bins. Hint: use pd.cut()\n'
    , '\n', '\n',
    """* Calculate the numbers and percentages by age group
""", '\n', '\n',
    '* Create a summary data frame to hold the results\n', '\n', '\n',
    """* Optional: round the percentage column to two decimal points
""",
    '\n', '\n', '* Display Age Demographics Table\n']}, {'cell_type':
    'code', 'execution_count': 12, 'metadata': {}, 'outputs': [{'data': {
    'text/html': ['<div>\n', '<style scoped>\n',
    """    .dataframe tbody tr th:only-of-type {
""",
    '        vertical-align: middle;\n', '    }\n', '\n',
    '    .dataframe tbody tr th {\n', """        vertical-align: top;
""",
    '    }\n', '\n', '    .dataframe thead th {\n',
    '        text-align: right;\n', '    }\n', '</style>\n',
    """<table border="1" class="dataframe">
""", '  <thead>\n',
    '    <tr style="text-align: right;">\n', '      <th></th>\n',
    """      <th>Purchase ID</th>
""", '      <th>SN</th>\n',
    '      <th>Age</th>\n', '      <th>Gender</th>\n',
    """      <th>Item ID</th>
""", '      <th>Item Name</th>\n',
    '      <th>Price</th>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Age Range</th>
""", '      <th></th>\n',
    '      <th></th>\n', '      <th></th>\n', '      <th></th>\n',
    '      <th></th>\n', '      <th></th>\n', '      <th></th>\n',
    '    </tr>\n', '  </thead>\n', '  <tbody>\n', '    <tr>\n',
    """      <th>&lt;10</th>
""", '      <td>778</td>\n',
    '      <td>Tyeurith29</td>\n', '      <td>9</td>\n',
    """      <td>Male</td>
""", '      <td>179</td>\n',
    '      <td>Wolf, Promise of the Moonwalker</td>\n',
    """      <td>4.93</td>
""", '    </tr>\n', '    <tr>\n',
    '      <th>10-14</th>\n', '      <td>774</td>\n',
    """      <td>Zhisrisu83</td>
""", '      <td>14</td>\n',
    '      <td>Male</td>\n', '      <td>180</td>\n',
    """      <td>Wolf</td>
""", '      <td>4.94</td>\n', '    </tr>\n',
    '    <tr>\n', '      <th>15-19</th>\n', """      <td>771</td>
""",
    '      <td>Yoishirrala98</td>\n', '      <td>19</td>\n',
    """      <td>Other / Non-Disclosed</td>
""", '      <td>183</td>\n',
    '      <td>Yearning Mageblade</td>\n', '      <td>4.91</td>\n',
    '    </tr>\n', '    <tr>\n', """      <th>20-24</th>
""",
    '      <td>779</td>\n', '      <td>Zontibe81</td>\n',
    '      <td>24</td>\n', """      <td>Other / Non-Disclosed</td>
""",
    '      <td>183</td>\n', '      <td>Yearning Mageblade</td>\n',
    '      <td>4.99</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>25-29</th>
""", '      <td>772</td>\n',
    '      <td>Yasur35</td>\n', '      <td>29</td>\n',
    """      <td>Other / Non-Disclosed</td>
""", '      <td>183</td>\n',
    '      <td>Worldbreaker</td>\n', '      <td>4.94</td>\n', '    </tr>\n',
    '    <tr>\n', """      <th>30-34</th>
""", '      <td>770</td>\n',
    '      <td>Yarolwen77</td>\n', '      <td>34</td>\n',
    """      <td>Male</td>
""", '      <td>178</td>\n',
    '      <td>Yearning Mageblade</td>\n', '      <td>4.93</td>\n',
    '    </tr>\n', '    <tr>\n', """      <th>35-39</th>
""",
    '      <td>768</td>\n', '      <td>Tyaerith73</td>\n',
    '      <td>39</td>\n', """      <td>Other / Non-Disclosed</td>
""",
    '      <td>179</td>\n',
    '      <td>Wolf, Promise of the Moonwalker</td>\n',
    """      <td>4.91</td>
""", '    </tr>\n', '    <tr>\n',
    '      <th>40+</th>\n', '      <td>761</td>\n',
    """      <td>Salilis27</td>
""", '      <td>45</td>\n',
    '      <td>Male</td>\n', '      <td>173</td>\n',
    """      <td>Victor Iron Spikes</td>
""", '      <td>4.93</td>\n',
    '    </tr>\n', '  </tbody>\n', '</table>\n', '</div>'], 'text/plain': [
    """           Purchase ID             SN  Age                 Gender  Item ID  \\
"""
    ,
    'Age Range                                                                    \n'
    ,
    """<10                778     Tyeurith29    9                   Male      179   
"""
    ,
    '10-14              774     Zhisrisu83   14                   Male      180   \n'
    ,
    """15-19              771  Yoishirrala98   19  Other / Non-Disclosed      183   
"""
    ,
    '20-24              779      Zontibe81   24  Other / Non-Disclosed      183   \n'
    ,
    """25-29              772        Yasur35   29  Other / Non-Disclosed      183   
"""
    ,
    '30-34              770     Yarolwen77   34                   Male      178   \n'
    ,
    """35-39              768     Tyaerith73   39  Other / Non-Disclosed      179   
"""
    ,
    '40+                761      Salilis27   45                   Male      173   \n'
    , '\n', """                                 Item Name  Price  
""",
    'Age Range                                          \n',
    """<10        Wolf, Promise of the Moonwalker   4.93  
""",
    '10-14                                 Wolf   4.94  \n',
    """15-19                   Yearning Mageblade   4.91  
""",
    '20-24                   Yearning Mageblade   4.99  \n',
    """25-29                         Worldbreaker   4.94  
""",
    '30-34                   Yearning Mageblade   4.93  \n',
    """35-39      Wolf, Promise of the Moonwalker   4.91  
""",
    '40+                     Victor Iron Spikes   4.93  ']},
    'execution_count': 12, 'metadata': {}, 'output_type': 'execute_result'},
    {'data': {'text/html': ['<div>\n', '<style scoped>\n',
    """    .dataframe tbody tr th:only-of-type {
""",
    '        vertical-align: middle;\n', '    }\n', '\n',
    '    .dataframe tbody tr th {\n', """        vertical-align: top;
""",
    '    }\n', '\n', '    .dataframe thead th {\n',
    '        text-align: right;\n', '    }\n', '</style>\n',
    """<table border="1" class="dataframe">
""", '  <thead>\n',
    '    <tr style="text-align: right;">\n', '      <th></th>\n',
    """      <th>Age Range</th>
""", '      <th>Percent of Players</th>\n',
    '    </tr>\n', '  </thead>\n', '  <tbody>\n', '    <tr>\n',
    """      <th>0</th>
""", '      <td>23</td>\n', '      <td>2.95</td>\n',
    '    </tr>\n', '    <tr>\n', """      <th>1</th>
""",
    '      <td>28</td>\n', '      <td>3.59</td>\n', '    </tr>\n',
    '    <tr>\n', """      <th>2</th>
""", '      <td>136</td>\n',
    '      <td>17.44</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>3</th>
""", '      <td>365</td>\n',
    '      <td>46.79</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>4</th>
""", '      <td>101</td>\n',
    '      <td>12.95</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>5</th>
""", '      <td>73</td>\n', '      <td>9.36</td>\n',
    '    </tr>\n', '    <tr>\n', """      <th>6</th>
""",
    '      <td>41</td>\n', '      <td>5.26</td>\n', '    </tr>\n',
    '    <tr>\n', """      <th>7</th>
""", '      <td>13</td>\n',
    '      <td>1.67</td>\n', '    </tr>\n', '  </tbody>\n', '</table>\n',
    '</div>'], 'text/plain': ["""   Age Range Percent of Players
""",
    '0         23               2.95\n',
    '1         28               3.59\n',
    """2        136              17.44
""",
    '3        365              46.79\n',
    '4        101              12.95\n',
    """5         73               9.36
""",
    '6         41               5.26\n', '7         13               1.67']
    }, 'execution_count': 12, 'metadata': {}, 'output_type':
    'execute_result'}, {'data': {'text/html': ['<div>\n',
    '<style scoped>\n', """    .dataframe tbody tr th:only-of-type {
""",
    '        vertical-align: middle;\n', '    }\n', '\n',
    '    .dataframe tbody tr th {\n', """        vertical-align: top;
""",
    '    }\n', '\n', '    .dataframe thead th {\n',
    '        text-align: right;\n', '    }\n', '</style>\n',
    """<table border="1" class="dataframe">
""", '  <thead>\n',
    '    <tr style="text-align: right;">\n', '      <th></th>\n',
    """      <th>Total Count</th>
""",
    '      <th>Percent of Players</th>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Age Range</th>
""", '      <th></th>\n',
    '      <th></th>\n', '    </tr>\n', '  </thead>\n', '  <tbody>\n',
    '    <tr>\n', """      <th>&lt;10</th>
""", '      <td>23</td>\n',
    '      <td>2.95</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>10-14</th>
""", '      <td>28</td>\n',
    '      <td>3.59</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>15-19</th>
""", '      <td>136</td>\n',
    '      <td>17.44</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>20-24</th>
""", '      <td>365</td>\n',
    '      <td>46.79</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>25-29</th>
""", '      <td>101</td>\n',
    '      <td>12.95</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>30-34</th>
""", '      <td>73</td>\n',
    '      <td>9.36</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>35-39</th>
""", '      <td>41</td>\n',
    '      <td>5.26</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>40+</th>
""", '      <td>13</td>\n',
    '      <td>1.67</td>\n', '    </tr>\n', '  </tbody>\n', '</table>\n',
    '</div>'], 'text/plain': [
    """           Total Count Percent of Players
""",
    'Age Range                                \n',
    '<10                 23               2.95\n',
    """10-14               28               3.59
""",
    '15-19              136              17.44\n',
    '20-24              365              46.79\n',
    """25-29              101              12.95
""",
    '30-34               73               9.36\n',
    '35-39               41               5.26\n',
    '40+                 13               1.67']}, 'execution_count': 12,
    'metadata': {}, 'output_type': 'execute_result'}], 'source': ['\n',
    """df_age2 = pd.DataFrame(purchase_data)
""",
    'bins = [0, 9.90, 14.90, 19.90, 24.90, 29.90, 34.90, 39.90, 99999]\n',
    """group_names = ['<10', '10-14','15-19', '20-24', '25-29', '30-34', '35-39', '40+']
"""
    ,
    'df_age2["Age Range"] = pd.cut(purchase_data["Age"], bins, labels=group_names)\n'
    , """df_age2= df_age2.groupby("Age Range")
""", 'df_age2.max()\n',
    "# df_age2 = df_age2.groupby('Age Range')\n", '# df_age2.head(0)\n',
    """age_count = pd.DataFrame((df_age2['Age Range'].count()))
""",
    '# df_age2= pd.DataFrame(\n', '\n',
    """age_count["Percent of Players"] = (age_count['Age Range'].divide((purchase_data['SN'].count())))*100
"""
    , '\n', '\n',
    """age_count['Percent of Players'] = age_count['Percent of Players'].apply('{:.2f}'.format)
"""
    , 'age_count.reset_index(drop=True)\n',
    """age_count = age_count.rename(columns={'Age Range': 'Total Count'})
""",
    '#age_count["Age Range"] = age_count["Percent of Players"]\n',
    """# ('{:.2f}'.format(age_count['Percent of Players']))
""", '\n',
    "# df = df.rename(columns={'oldName1': 'newName1', 'oldName2': 'newName2'})\n"
    , '\n', """# df['Rate'] = df['Rate'].apply('{:.2f}%'.format)
""",
    "# format(math.pi, '.2f')\n",
    "# df['c'] = df['a'].divide(df['b'], fill_value=1)\n",
    """# ("{0:.2f}".format(a))
""", '\n', 'age_count.head(10)\n', '\n',
    '\n', """# df_age = pd.DataFrame(df_age['Age Range'].count())
""",
    """# df_age["Percentage of Players"] = df_age(age_count["Age Range"] / (purchase_data['SN'].count()))
"""
    ,
    '#age_count = ((age_count["Age Range"] / purchase_data[\'Gender\'].count()) * 100)\n'
    , '\n', """# age_count = ((df_age2['Age Range'].count()))
""",
    '# b = np.insert(a, insert_index, values=a[:,2], axis=1)\n',
    """# df.insert( index,name,value)
""", '\n',
    '# df_age["Percent of Players"] = df_age["Age Range"]\n',
    '# df_age2.reset_index()\n', '\n',
    """# df_age.set_index(['Age Range', 'Total Count'])
""",
    "# df.set_index(['year', 'month'])\n",
    """# df_age["Percentage of Players"] = df_age["Age Range"] / (purchase_data['SN'].count())
"""
    , '\n', '\n', '\n', '\n']}, {'cell_type': 'markdown', 'metadata': {},
    'source': ['## Purchasing Analysis (Age)']}, {'cell_type': 'markdown',
    'metadata': {}, 'source': [
    """* Bin the purchase_data data frame by age
""", '\n', '\n',
    """* Run basic calculations to obtain purchase count, avg. purchase price, avg. purchase total per person etc. in the table below
"""
    , '\n', '\n', '* Create a summary data frame to hold the results\n',
    '\n', '\n',
    """* Optional: give the displayed data cleaner formatting
""", '\n',
    '\n', '* Display the summary data frame']}, {'cell_type': 'code',
    'execution_count': 13, 'metadata': {}, 'outputs': [{'name': 'stdout',
    'output_type': 'stream', 'text': ["""            SN    Price
""",
    'Age Range              \n', '<10         23    77.13\n',
    '10-14       28    82.78\n', """15-19      136   412.89
""",
    '20-24      365  1114.06\n', '25-29      101   293.00\n',
    '30-34       73   214.00\n', """35-39       41   147.67
""",
    '40+         13    38.24\n']}], 'source': ['\n',
    'df_purchase = pd.DataFrame(purchase_data)\n',
    """bins = [0, 9.90, 14.90, 19.90, 24.90, 29.90, 34.90, 39.90, 99999]
""",
    "group_names = ['<10', '10-14','15-19', '20-24', '25-29', '30-34', '35-39', '40+']\n"
    ,
    """df_purchase["Age Range"] = pd.cut(purchase_data["Age"], bins, labels=group_names)
"""
    , '\n', '#df_purchasedf= df_purchase[["Age Range", "SN", "Price"]]\n',
    """# print(df_purchasedf)
""",
    """df_purchasedf= df_purchase.groupby(['Age Range']).agg({'SN': "count", 'Price': "sum"})
"""
    , 'print(df_purchasedf)\n', '#\n',
    """#new_group = df_topspenders.groupby(['SN']).agg({ 'SN': "count", 'Price': "sum"})
"""
    , "#new_group2 = new_group.sort_values(by='SN', ascending=False)\n",
    '#new_group2\n',
    """#new_group2['Average'] =round((new_group2['Price']/new_group2['SN']),2)
"""
    , '#\n', '\n', '\n', '#df_purchasedf\n',
    """#df_purchasedf1 = df_purchasedf['Age Range'].count()
""",
    "#df_purchasedf2 = df_purchasedf['Price'].sum() / df_purchasedf['Age Range'].count()\n"
    , """#df_purchasedf3 = pd.DataFrame[df_purchasedf['SN'].mean()]
""",
    """# df_purchasedf[ "Purchase Count", "Average Purchase Price",	"Total Purchase Value",	"Average Purchase Total per Person"] = 
"""
    , "#            [df_purchasedf['SN'].count(), df_purchasedf[''] \n",
    """# df_purchase.sort_index(by='Age Range',ascending=False)
""", '\n',
    "# df_count_purchase = pd.DataFrame((df_purchase['Age Range'].count()))\n",
    '\n',
    """# Averag_price = df_purchase['Price'].sum()/ df_purchase['Price'].count()
"""
    , "# Totalg_price = df_purchase['Price'].sum()\n",
    '# df_purchase.head()\n', """#df_purchasedf.head()
""",
    "# AverPur_Total = df_purchase.groupby('SN')['Price'].mean()\n",
    """# df.groupby('male')['age'].mean()
""",
    '#df_count_purchase.head()\n',
    "# df.groupby(['reciept','date'])['reciept'].count()\n",
    """# df_age2 = df_age2.groupby('Age Range')
""", '# df_age2.head(0)\n',
    "#age_count = pd.DataFrame((df_age2['Age Range'].count()))\n",
    """# df_age2= pd.DataFrame(
""", '\n',
    """#age_count["Percent of Players"] = (age_count['Age Range'].divide((purchase_data['SN'].count())))*100
"""
    , '\n', '\n',
    """#age_count['Percent of Players'] = age_count['Percent of Players'].apply('{:.2f}'.format)
"""
    , '#age_count.reset_index(drop=True)\n',
    """#age_count = age_count.rename(columns={'Age Range': 'Total Count'})
""",
    '\n', '\n', '\n', '\n', '\n', '\n',
    """#Purchase Count	Average Purchase Price	Total Purchase Value	Avg Total Purchase per Person
"""
    , '#10-14\t28\t$2.96\t$82.78\t$3.76\n',
    '#15-19\t136\t$3.04\t$412.89\t$3.86\n',
    '#20-24\t365\t$3.05\t$1,114.06\t$4.3']}, {'cell_type': 'markdown',
    'metadata': {}, 'source': ['## Top Spenders']}, {'cell_type':
    'markdown', 'metadata': {}, 'source': [
    """* Run basic calculations to obtain the results in the table below
""",
    '\n', '\n', '* Create a summary data frame to hold the results\n', '\n',
    '\n', """* Sort the total purchase value column in descending order
""",
    '\n', '\n', '* Optional: give the displayed data cleaner formatting\n',
    '\n', '\n', """* Display a preview of the summary data frame
""", '\n']
    }, {'cell_type': 'code', 'execution_count': 14, 'metadata': {},
    'outputs': [{'name': 'stderr', 'output_type': 'stream', 'text': [
    """C:\\Users\\lcc25\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:3: FutureWarning: 'SN' is both an index level and a column label.
"""
    ,
    'Defaulting to column, but this will raise an ambiguity error in a future version\n'
    ,
    """  This is separate from the ipykernel package so we can avoid doing imports until
"""
    ]}, {'data': {'text/html': ['<div>\n', '<style scoped>\n',
    """    .dataframe tbody tr th:only-of-type {
""",
    '        vertical-align: middle;\n', '    }\n', '\n',
    '    .dataframe tbody tr th {\n', """        vertical-align: top;
""",
    '    }\n', '\n', '    .dataframe thead th {\n',
    '        text-align: right;\n', '    }\n', '</style>\n',
    """<table border="1" class="dataframe">
""", '  <thead>\n',
    '    <tr style="text-align: right;">\n', '      <th></th>\n',
    """      <th>SN</th>
""", '      <th>Price</th>\n', '    </tr>\n',
    '    <tr>\n', '      <th>SN</th>\n', '      <th></th>\n',
    '      <th></th>\n', '    </tr>\n', '  </thead>\n', '  <tbody>\n',
    '    <tr>\n', """      <th>Lisosia93</th>
""", '      <td>5</td>\n',
    '      <td>18.96</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Iral74</th>
""", '      <td>4</td>\n',
    '      <td>13.62</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Idastidru52</th>
""", '      <td>4</td>\n',
    '      <td>15.45</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Asur53</th>
""", '      <td>3</td>\n',
    '      <td>7.44</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Inguron55</th>
""", '      <td>3</td>\n',
    '      <td>11.11</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Aina42</th>
""", '      <td>3</td>\n',
    '      <td>9.22</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Ilarin91</th>
""", '      <td>3</td>\n',
    '      <td>12.70</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Idai61</th>
""", '      <td>3</td>\n',
    '      <td>8.23</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Umolrian85</th>
""", '      <td>3</td>\n',
    '      <td>8.13</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Ialallo29</th>
""", '      <td>3</td>\n',
    '      <td>11.84</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Tyisur83</th>
""", '      <td>3</td>\n',
    '      <td>5.36</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Tyidaim51</th>
""", '      <td>3</td>\n',
    '      <td>11.83</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Pheodaisun84</th>
""", '      <td>3</td>\n',
    '      <td>8.31</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Hiaral50</th>
""", '      <td>3</td>\n',
    '      <td>4.19</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Haillyrgue51</th>
""", '      <td>3</td>\n',
    '      <td>9.50</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Zontibe81</th>
""", '      <td>3</td>\n',
    '      <td>8.03</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Iri67</th>
""", '      <td>3</td>\n',
    '      <td>11.37</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Hada39</th>
""", '      <td>3</td>\n',
    '      <td>8.57</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Raesty92</th>
""", '      <td>3</td>\n',
    '      <td>8.73</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Rarallo90</th>
""", '      <td>3</td>\n',
    '      <td>9.05</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Chadolyla44</th>
""", '      <td>3</td>\n',
    '      <td>11.46</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Saedaiphos46</th>
""", '      <td>3</td>\n',
    '      <td>8.83</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Saistyphos30</th>
""", '      <td>3</td>\n',
    '      <td>10.33</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Siallylis44</th>
""", '      <td>3</td>\n',
    '      <td>10.37</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Chamimla85</th>
""", '      <td>3</td>\n',
    '      <td>6.30</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Silaera56</th>
""", '      <td>3</td>\n',
    '      <td>8.48</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Chamjask73</th>
""", '      <td>3</td>\n',
    '      <td>13.83</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Chanastnya43</th>
""", '      <td>3</td>\n',
    '      <td>8.82</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Strithenu87</th>
""", '      <td>3</td>\n',
    '      <td>10.18</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Sondastsda82</th>
""", '      <td>3</td>\n',
    '      <td>7.89</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>...</th>
""", '      <td>...</td>\n',
    '      <td>...</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Haerith37</th>
""", '      <td>1</td>\n',
    '      <td>1.66</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Iduelis31</th>
""", '      <td>1</td>\n',
    '      <td>1.10</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Hiral75</th>
""", '      <td>1</td>\n',
    '      <td>1.98</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Idaisuir85</th>
""", '      <td>1</td>\n',
    '      <td>3.15</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Idacal95</th>
""", '      <td>1</td>\n',
    '      <td>2.07</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Iathenudil29</th>
""", '      <td>1</td>\n',
    '      <td>4.60</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Iathem87</th>
""", '      <td>1</td>\n',
    '      <td>3.19</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Iasursti71</th>
""", '      <td>1</td>\n',
    '      <td>1.66</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Iasurriacal29</th>
""", '      <td>1</td>\n',
    '      <td>4.07</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Iarallo65</th>
""", '      <td>1</td>\n',
    '      <td>1.75</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Iana95</th>
""", '      <td>1</td>\n',
    '      <td>3.10</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Ialidru40</th>
""", '      <td>1</td>\n',
    '      <td>3.16</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Iadueria43</th>
""", '      <td>1</td>\n',
    '      <td>1.71</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Hyaduesu61</th>
""", '      <td>1</td>\n',
    '      <td>4.23</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Hisridru55</th>
""", '      <td>1</td>\n',
    '      <td>3.08</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Hilaerin92</th>
""", '      <td>1</td>\n',
    '      <td>3.61</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Haerithp41</th>
""", '      <td>1</td>\n',
    '      <td>4.40</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Hiasurria41</th>
""", '      <td>1</td>\n',
    '      <td>1.61</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Hiarideu73</th>
""", '      <td>1</td>\n',
    '      <td>2.50</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Heunadil74</th>
""", '      <td>1</td>\n',
    '      <td>1.54</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Heudai45</th>
""", '      <td>1</td>\n',
    '      <td>3.47</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Heollyriap59</th>
""", '      <td>1</td>\n',
    '      <td>3.47</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Heollyra92</th>
""", '      <td>1</td>\n',
    '      <td>3.07</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Hariphos58</th>
""", '      <td>1</td>\n',
    '      <td>2.05</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Hallysucal81</th>
""", '      <td>1</td>\n',
    '      <td>1.66</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Hala31</th>
""", '      <td>1</td>\n',
    '      <td>1.02</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Haisurra41</th>
""", '      <td>1</td>\n',
    '      <td>4.40</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Hailaphos89</th>
""", '      <td>1</td>\n',
    '      <td>3.81</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Haestyphos66</th>
""", '      <td>1</td>\n',
    '      <td>1.97</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>Iskosian40</th>
""", '      <td>1</td>\n',
    '      <td>3.07</td>\n', '    </tr>\n', '  </tbody>\n', '</table>\n',
    """<p>576 rows × 2 columns</p>
""", '</div>'], 'text/plain': [
    '               SN  Price\n', 'SN                      \n',
    """Lisosia93       5  18.96
""", 'Iral74          4  13.62\n',
    'Idastidru52     4  15.45\n', 'Asur53          3   7.44\n',
    """Inguron55       3  11.11
""", 'Aina42          3   9.22\n',
    'Ilarin91        3  12.70\n', 'Idai61          3   8.23\n',
    """Umolrian85      3   8.13
""", 'Ialallo29       3  11.84\n',
    'Tyisur83        3   5.36\n', 'Tyidaim51       3  11.83\n',
    """Pheodaisun84    3   8.31
""", 'Hiaral50        3   4.19\n',
    'Haillyrgue51    3   9.50\n', 'Zontibe81       3   8.03\n',
    """Iri67           3  11.37
""", 'Hada39          3   8.57\n',
    'Raesty92        3   8.73\n', 'Rarallo90       3   9.05\n',
    """Chadolyla44     3  11.46
""", 'Saedaiphos46    3   8.83\n',
    'Saistyphos30    3  10.33\n', 'Siallylis44     3  10.37\n',
    """Chamimla85      3   6.30
""", 'Silaera56       3   8.48\n',
    'Chamjask73      3  13.83\n', 'Chanastnya43    3   8.82\n',
    """Strithenu87     3  10.18
""", 'Sondastsda82    3   7.89\n',
    '...            ..    ...\n', 'Haerith37       1   1.66\n',
    """Iduelis31       1   1.10
""", 'Hiral75         1   1.98\n',
    'Idaisuir85      1   3.15\n', 'Idacal95        1   2.07\n',
    """Iathenudil29    1   4.60
""", 'Iathem87        1   3.19\n',
    'Iasursti71      1   1.66\n', 'Iasurriacal29   1   4.07\n',
    """Iarallo65       1   1.75
""", 'Iana95          1   3.10\n',
    'Ialidru40       1   3.16\n', 'Iadueria43      1   1.71\n',
    """Hyaduesu61      1   4.23
""", 'Hisridru55      1   3.08\n',
    'Hilaerin92      1   3.61\n', 'Haerithp41      1   4.40\n',
    """Hiasurria41     1   1.61
""", 'Hiarideu73      1   2.50\n',
    'Heunadil74      1   1.54\n', 'Heudai45        1   3.47\n',
    """Heollyriap59    1   3.47
""", 'Heollyra92      1   3.07\n',
    'Hariphos58      1   2.05\n', 'Hallysucal81    1   1.66\n',
    """Hala31          1   1.02
""", 'Haisurra41      1   4.40\n',
    'Hailaphos89     1   3.81\n', 'Haestyphos66    1   1.97\n',
    """Iskosian40      1   3.07
""", '\n', '[576 rows x 2 columns]']},
    'execution_count': 14, 'metadata': {}, 'output_type': 'execute_result'},
    {'data': {'text/html': ['<div>\n', '<style scoped>\n',
    """    .dataframe tbody tr th:only-of-type {
""",
    '        vertical-align: middle;\n', '    }\n', '\n',
    '    .dataframe tbody tr th {\n', """        vertical-align: top;
""",
    '    }\n', '\n', '    .dataframe thead th {\n',
    '        text-align: right;\n', '    }\n', '</style>\n',
    """<table border="1" class="dataframe">
""", '  <thead>\n',
    '    <tr style="text-align: right;">\n', '      <th></th>\n',
    """      <th>Count</th>
""", '      <th>Price</th>\n',
    '      <th>Avg Price</th>\n', '    </tr>\n', '    <tr>\n',
    """      <th>SN</th>
""", '      <th></th>\n', '      <th></th>\n',
    '      <th></th>\n', '    </tr>\n', '  </thead>\n', '  <tbody>\n',
    '    <tr>\n', """      <th>Lisosia93</th>
""", '      <td>5</td>\n',
    '      <td>18.96</td>\n', '      <td>3.79</td>\n', '    </tr>\n',
    '    <tr>\n', """      <th>Iral74</th>
""", '      <td>4</td>\n',
    '      <td>13.62</td>\n', '      <td>3.40</td>\n', '    </tr>\n',
    '    <tr>\n', """      <th>Idastidru52</th>
""", '      <td>4</td>\n',
    '      <td>15.45</td>\n', '      <td>3.86</td>\n', '    </tr>\n',
    '    <tr>\n', """      <th>Asur53</th>
""", '      <td>3</td>\n',
    '      <td>7.44</td>\n', '      <td>2.48</td>\n', '    </tr>\n',
    '    <tr>\n', """      <th>Inguron55</th>
""", '      <td>3</td>\n',
    '      <td>11.11</td>\n', '      <td>3.70</td>\n', '    </tr>\n',
    '    <tr>\n', """      <th>Aina42</th>
""", '      <td>3</td>\n',
    '      <td>9.22</td>\n', '      <td>3.07</td>\n', '    </tr>\n',
    '    <tr>\n', """      <th>Ilarin91</th>
""", '      <td>3</td>\n',
    '      <td>12.70</td>\n', '      <td>4.23</td>\n', '    </tr>\n',
    '    <tr>\n', """      <th>Idai61</th>
""", '      <td>3</td>\n',
    '      <td>8.23</td>\n', '      <td>2.74</td>\n', '    </tr>\n',
    '    <tr>\n', """      <th>Umolrian85</th>
""", '      <td>3</td>\n',
    '      <td>8.13</td>\n', '      <td>2.71</td>\n', '    </tr>\n',
    '    <tr>\n', """      <th>Ialallo29</th>
""", '      <td>3</td>\n',
    '      <td>11.84</td>\n', '      <td>3.95</td>\n', '    </tr>\n',
    '  </tbody>\n', '</table>\n', '</div>'], 'text/plain': [
    """             Count  Price  Avg Price
""",
    'SN                                  \n',
    'Lisosia93        5  18.96       3.79\n',
    """Iral74           4  13.62       3.40
""",
    'Idastidru52      4  15.45       3.86\n',
    'Asur53           3   7.44       2.48\n',
    """Inguron55        3  11.11       3.70
""",
    'Aina42           3   9.22       3.07\n',
    'Ilarin91         3  12.70       4.23\n',
    """Idai61           3   8.23       2.74
""",
    'Umolrian85       3   8.13       2.71\n',
    'Ialallo29        3  11.84       3.95']}, 'execution_count': 14,
    'metadata': {}, 'output_type': 'execute_result'}], 'source': [
    """df_topspenders = pd.DataFrame(purchase_data)
""",
    'new_group = df_topspenders.groupby([\'SN\']).agg({ \'SN\': "count", \'Price\': "sum"})\n'
    , """new_group2 = new_group.sort_values(by='SN', ascending=False)
""",
    'new_group2\n',
    "new_group2['Average'] =round((new_group2['Price']/new_group2['SN']),2)\n",
    """# new_group2 = new_group2.reset_index(drop=False)
""",
    "new_group2.columns=['Count', 'Price', 'Avg Price']\n",
    'new_group2.head(10)']}, {'cell_type': 'code', 'execution_count': 15,
    'metadata': {}, 'outputs': [{'data': {'text/plain': [
    "['Purchase ID',\n", " 'SN',\n", " 'Age',\n", " 'Gender',\n",
    " 'Item ID',\n", " 'Item Name',\n", " 'Price',\n", " 'Age Range']"]},
    'execution_count': 15, 'metadata': {}, 'output_type': 'execute_result'},
    {'data': {'text/html': ['<div>\n', '<style scoped>\n',
    """    .dataframe tbody tr th:only-of-type {
""",
    '        vertical-align: middle;\n', '    }\n', '\n',
    '    .dataframe tbody tr th {\n', """        vertical-align: top;
""",
    '    }\n', '\n', '    .dataframe thead th {\n',
    '        text-align: right;\n', '    }\n', '</style>\n',
    """<table border="1" class="dataframe">
""", '  <thead>\n',
    '    <tr style="text-align: right;">\n', '      <th></th>\n',
    '      <th></th>\n', """      <th>Item ID</th>
""",
    '      <th>Price</th>\n', '    </tr>\n', '    <tr>\n',
    '      <th>Item ID</th>\n', """      <th>Item Name</th>
""",
    '      <th></th>\n', '      <th></th>\n', '    </tr>\n', '  </thead>\n',
    '  <tbody>\n', '    <tr>\n', """      <th>0</th>
""",
    '      <th>Splinter</th>\n', '      <td>4</td>\n',
    '      <td>5.12</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>1</th>
""", '      <th>Crucifer</th>\n',
    '      <td>3</td>\n', '      <td>9.78</td>\n', '    </tr>\n',
    '    <tr>\n', """      <th>2</th>
""", '      <th>Verdict</th>\n',
    '      <td>6</td>\n', '      <td>14.88</td>\n', '    </tr>\n',
    '    <tr>\n', """      <th>3</th>
""", '      <th>Phantomlight</th>\n',
    '      <td>6</td>\n', '      <td>14.94</td>\n', '    </tr>\n',
    '    <tr>\n', """      <th>4</th>
""",
    "      <th>Bloodlord's Fetish</th>\n", '      <td>5</td>\n',
    '      <td>8.50</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>5</th>
""", '      <th>Putrid Fan</th>\n',
    '      <td>4</td>\n', '      <td>16.32</td>\n', '    </tr>\n',
    '    <tr>\n', """      <th>6</th>
""", '      <th>Rusty Skull</th>\n',
    '      <td>2</td>\n', '      <td>7.40</td>\n', '    </tr>\n',
    '    <tr>\n', """      <th>7</th>
""",
    '      <th>Thorn, Satchel of Dark Souls</th>\n', '      <td>7</td>\n',
    '      <td>9.31</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>8</th>
""", '      <th>Purgatory, Gem of Regret</th>\n',
    '      <td>3</td>\n', '      <td>11.79</td>\n', '    </tr>\n',
    '    <tr>\n', """      <th>9</th>
""",
    '      <th>Thorn, Conqueror of the Corrupted</th>\n',
    '      <td>4</td>\n', """      <td>10.92</td>
""", '    </tr>\n',
    '  </tbody>\n', '</table>\n', '</div>'], 'text/plain': [
    """                                           Item ID  Price
""",
    'Item ID Item Name                                        \n',
    """0       Splinter                                 4   5.12
""",
    '1       Crucifer                                 3   9.78\n',
    """2       Verdict                                  6  14.88
""",
    '3       Phantomlight                             6  14.94\n',
    """4       Bloodlord's Fetish                       5   8.50
""",
    '5       Putrid Fan                               4  16.32\n',
    """6       Rusty Skull                              2   7.40
""",
    '7       Thorn, Satchel of Dark Souls             7   9.31\n',
    """8       Purgatory, Gem of Regret                 3  11.79
""",
    '9       Thorn, Conqueror of the Corrupted        4  10.92']},
    'execution_count': 15, 'metadata': {}, 'output_type': 'execute_result'},
    {'name': 'stderr', 'output_type': 'stream', 'text': [
    """C:\\Users\\lcc25\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:7: FutureWarning: 'Item ID' is both an index level and a column label.
"""
    ,
    'Defaulting to column, but this will raise an ambiguity error in a future version\n'
    , '  import sys\n']}, {'data': {'text/html': ['<div>\n',
    '<style scoped>\n', """    .dataframe tbody tr th:only-of-type {
""",
    '        vertical-align: middle;\n', '    }\n', '\n',
    '    .dataframe tbody tr th {\n', """        vertical-align: top;
""",
    '    }\n', '\n', '    .dataframe thead th {\n',
    '        text-align: right;\n', '    }\n', '</style>\n',
    """<table border="1" class="dataframe">
""", '  <thead>\n',
    '    <tr style="text-align: right;">\n', '      <th></th>\n',
    '      <th></th>\n', """      <th>Purchase Count</th>
""",
    '      <th>Item Price</th>\n', '      <th>Total Purchase Value</th>\n',
    '    </tr>\n', '    <tr>\n', """      <th>Item ID</th>
""",
    '      <th>Item Name</th>\n', '      <th></th>\n', '      <th></th>\n',
    '      <th></th>\n', '    </tr>\n', '  </thead>\n', '  <tbody>\n',
    '    <tr>\n', """      <th>178</th>
""",
    '      <th>Oathbreaker, Last Hope of the Breaking Storm</th>\n',
    '      <td>12</td>\n', """      <td>4.23</td>
""",
    '      <td>50.76</td>\n', '    </tr>\n', '    <tr>\n',
    '      <th>145</th>\n', """      <th>Fiery Glass Crusader</th>
""",
    '      <td>9</td>\n', '      <td>4.58</td>\n', '      <td>41.22</td>\n',
    '    </tr>\n', '    <tr>\n', """      <th>108</th>
""",
    '      <th>Extraction, Quickblade Of Trembling Hands</th>\n',
    '      <td>9</td>\n', """      <td>3.53</td>
""",
    '      <td>31.77</td>\n', '    </tr>\n', '    <tr>\n',
    '      <th>82</th>\n', """      <th>Nirvana</th>
""",
    '      <td>9</td>\n', '      <td>4.90</td>\n', '      <td>44.10</td>\n',
    '    </tr>\n', '    <tr>\n', """      <th>19</th>
""",
    '      <th>Pursuit, Cudgel of Necromancy</th>\n', '      <td>8</td>\n',
    """      <td>1.02</td>
""", '      <td>8.16</td>\n', '    </tr>\n',
    '    <tr>\n', '      <th>103</th>\n',
    """      <th>Singed Scalpel</th>
""", '      <td>8</td>\n',
    '      <td>4.35</td>\n', '      <td>34.80</td>\n', '    </tr>\n',
    '    <tr>\n', """      <th>75</th>
""",
    '      <th>Brutality Ivory Warmace</th>\n', '      <td>8</td>\n',
    '      <td>2.42</td>\n', """      <td>19.36</td>
""", '    </tr>\n',
    '    <tr>\n', '      <th>72</th>\n', "      <th>Winter's Bite</th>\n",
    """      <td>8</td>
""", '      <td>3.77</td>\n',
    '      <td>30.16</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>60</th>
""", '      <th>Wolf</th>\n', '      <td>8</td>\n',
    '      <td>3.54</td>\n', """      <td>28.32</td>
""", '    </tr>\n',
    '    <tr>\n', '      <th>59</th>\n',
    """      <th>Lightning, Etcher of the King</th>
""",
    '      <td>8</td>\n', '      <td>4.23</td>\n', '      <td>33.84</td>\n',
    '    </tr>\n', '  </tbody>\n', '</table>\n', '</div>'], 'text/plain': [
    """                                                      Purchase Count  \\
"""
    ,
    'Item ID Item Name                                                      \n'
    ,
    """178     Oathbreaker, Last Hope of the Breaking Storm              12   
"""
    ,
    '145     Fiery Glass Crusader                                       9   \n'
    ,
    """108     Extraction, Quickblade Of Trembling Hands                  9   
"""
    ,
    '82      Nirvana                                                    9   \n'
    ,
    """19      Pursuit, Cudgel of Necromancy                              8   
"""
    ,
    '103     Singed Scalpel                                             8   \n'
    ,
    """75      Brutality Ivory Warmace                                    8   
"""
    ,
    "72      Winter's Bite                                              8   \n"
    ,
    """60      Wolf                                                       8   
"""
    ,
    '59      Lightning, Etcher of the King                              8   \n'
    , '\n',
    """                                                      Item Price  \\
"""
    ,
    'Item ID Item Name                                                  \n',
    """178     Oathbreaker, Last Hope of the Breaking Storm        4.23   
""",
    '145     Fiery Glass Crusader                                4.58   \n',
    """108     Extraction, Quickblade Of Trembling Hands           3.53   
""",
    '82      Nirvana                                             4.90   \n',
    """19      Pursuit, Cudgel of Necromancy                       1.02   
""",
    '103     Singed Scalpel                                      4.35   \n',
    """75      Brutality Ivory Warmace                             2.42   
""",
    "72      Winter's Bite                                       3.77   \n",
    """60      Wolf                                                3.54   
""",
    '59      Lightning, Etcher of the King                       4.23   \n',
    '\n',
    """                                                      Total Purchase Value  
"""
    ,
    'Item ID Item Name                                                           \n'
    ,
    """178     Oathbreaker, Last Hope of the Breaking Storm                 50.76  
"""
    ,
    '145     Fiery Glass Crusader                                         41.22  \n'
    ,
    """108     Extraction, Quickblade Of Trembling Hands                    31.77  
"""
    ,
    '82      Nirvana                                                      44.10  \n'
    ,
    """19      Pursuit, Cudgel of Necromancy                                 8.16  
"""
    ,
    '103     Singed Scalpel                                               34.80  \n'
    ,
    """75      Brutality Ivory Warmace                                      19.36  
"""
    ,
    "72      Winter's Bite                                                30.16  \n"
    ,
    """60      Wolf                                                         28.32  
"""
    ,
    '59      Lightning, Etcher of the King                                33.84  '
    ]}, 'execution_count': 15, 'metadata': {}, 'output_type':
    'execute_result'}], 'source': [
    """df_topitem = pd.DataFrame(purchase_data)
""", '\n',
    'df_topitem.columns.tolist()\n',
    """df_topitem2 = df_topitem.groupby(['Item ID', 'Item Name']).agg({ 'Item ID': "count", 'Price': "sum"})
"""
    , 'df_topitem2.head(10)\n',
    """# new_group = df_topspenders.groupby(['SN']).agg({ 'SN': "count", 'Price': "sum"})
"""
    ,
    "new_group2 = df_topitem2.sort_values(by='Item ID', ascending=False)\n",
    """# new_group2 = new_group2.reset_index(drop=True)
""",
    "new_group2.columns=['Purchase Count', 'Total Purchase Value']\n",
    """new_group2['Item Price'] =round((new_group2['Total Purchase Value']/new_group2['Purchase Count']),2)
"""
    , '# new_group2 = new_group2.reset_index(drop=FalsTo\n',
    """new_group2 = pd.DataFrame(new_group2)
""",
    "Top_purchase_item = new_group2[['Purchase Count', 'Item Price', 'Total Purchase Value']]\n"
    , 'Top_purchase_item.head(10)']}, {'cell_type': 'markdown', 'metadata':
    {}, 'source': ['## Most Popular Items']}, {'cell_type': 'markdown',
    'metadata': {}, 'source': [
    """* Retrieve the Item ID, Item Name, and Item Price columns
""", '\n',
    '\n',
    """* Group by Item ID and Item Name. Perform calculations to obtain purchase count, item price, and total purchase value
"""
    , '\n', '\n', '* Create a summary data frame to hold the results\n',
    '\n', '\n', """* Sort the purchase count column in descending order
""",
    '\n', '\n', '* Optional: give the displayed data cleaner formatting\n',
    '\n', '\n', """* Display a preview of the summary data frame
""", '\n']
    }, {'cell_type': 'code', 'execution_count': 9, 'metadata': {},
    'outputs': [{'data': {'text/html': ['<div>\n',
    """<table border="1" class="dataframe">
""", '  <thead>\n',
    '    <tr style="text-align: right;">\n', '      <th></th>\n',
    '      <th></th>\n', """      <th>Purchase Count</th>
""",
    '      <th>Item Price</th>\n', '      <th>Total Purchase Value</th>\n',
    '    </tr>\n', '    <tr>\n', """      <th>Item ID</th>
""",
    '      <th>Item Name</th>\n', '      <th></th>\n', '      <th></th>\n',
    '      <th></th>\n', '    </tr>\n', '  </thead>\n', '  <tbody>\n',
    '    <tr>\n', """      <th>178</th>
""",
    '      <th>Oathbreaker, Last Hope of the Breaking Storm</th>\n',
    '      <td>12</td>\n', """      <td>$4.23</td>
""",
    '      <td>$50.76</td>\n', '    </tr>\n', '    <tr>\n',
    '      <th>145</th>\n', """      <th>Fiery Glass Crusader</th>
""",
    '      <td>9</td>\n', '      <td>$4.58</td>\n',
    '      <td>$41.22</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>108</th>
""",
    '      <th>Extraction, Quickblade Of Trembling Hands</th>\n',
    '      <td>9</td>\n', """      <td>$3.53</td>
""",
    '      <td>$31.77</td>\n', '    </tr>\n', '    <tr>\n',
    '      <th>82</th>\n', """      <th>Nirvana</th>
""",
    '      <td>9</td>\n', '      <td>$4.90</td>\n',
    '      <td>$44.10</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>19</th>
""",
    '      <th>Pursuit, Cudgel of Necromancy</th>\n', '      <td>8</td>\n',
    """      <td>$1.02</td>
""", '      <td>$8.16</td>\n', '    </tr>\n',
    '  </tbody>\n', '</table>\n', '</div>'], 'text/plain': [
    """                                                     Purchase Count  \\
"""
    ,
    'Item ID Item Name                                                     \n',
    """178     Oathbreaker, Last Hope of the Breaking Storm             12   
"""
    ,
    '145     Fiery Glass Crusader                                      9   \n',
    """108     Extraction, Quickblade Of Trembling Hands                 9   
"""
    ,
    '82      Nirvana                                                   9   \n',
    """19      Pursuit, Cudgel of Necromancy                             8   
"""
    , '\n',
    '                                                     Item Price  \\\n',
    """Item ID Item Name                                                 
""",
    '178     Oathbreaker, Last Hope of the Breaking Storm      $4.23   \n',
    """145     Fiery Glass Crusader                              $4.58   
""",
    '108     Extraction, Quickblade Of Trembling Hands         $3.53   \n',
    """82      Nirvana                                           $4.90   
""",
    '19      Pursuit, Cudgel of Necromancy                     $1.02   \n',
    '\n',
    """                                                     Total Purchase Value  
"""
    ,
    'Item ID Item Name                                                          \n'
    ,
    """178     Oathbreaker, Last Hope of the Breaking Storm               $50.76  
"""
    ,
    '145     Fiery Glass Crusader                                       $41.22  \n'
    ,
    """108     Extraction, Quickblade Of Trembling Hands                  $31.77  
"""
    ,
    '82      Nirvana                                                    $44.10  \n'
    ,
    '19      Pursuit, Cudgel of Necromancy                               $8.16  '
    ]}, 'execution_count': 9, 'metadata': {}, 'output_type':
    'execute_result'}], 'source': []}, {'cell_type': 'code',
    'execution_count': 102, 'metadata': {}, 'outputs': [{'data': {
    'text/html': ['<div>\n', '<style scoped>\n',
    """    .dataframe tbody tr th:only-of-type {
""",
    '        vertical-align: middle;\n', '    }\n', '\n',
    '    .dataframe tbody tr th {\n', """        vertical-align: top;
""",
    '    }\n', '\n', '    .dataframe thead th {\n',
    '        text-align: right;\n', '    }\n', '</style>\n',
    """<table border="1" class="dataframe">
""", '  <thead>\n',
    '    <tr style="text-align: right;">\n', '      <th></th>\n',
    '      <th></th>\n', """      <th>Purchase Count</th>
""",
    '      <th>Item Price</th>\n', '      <th>Total Purchase Value</th>\n',
    '    </tr>\n', '    <tr>\n', """      <th>Item ID</th>
""",
    '      <th>Item Name</th>\n', '      <th></th>\n', '      <th></th>\n',
    '      <th></th>\n', '    </tr>\n', '  </thead>\n', '  <tbody>\n',
    '    <tr>\n', """      <th>178</th>
""",
    '      <th>Oathbreaker, Last Hope of the Breaking Storm</th>\n',
    '      <td>12</td>\n', """      <td>4.23</td>
""",
    '      <td>50.76</td>\n', '    </tr>\n', '    <tr>\n',
    '      <th>82</th>\n', """      <th>Nirvana</th>
""",
    '      <td>9</td>\n', '      <td>4.90</td>\n', '      <td>44.10</td>\n',
    '    </tr>\n', '    <tr>\n', """      <th>145</th>
""",
    '      <th>Fiery Glass Crusader</th>\n', '      <td>9</td>\n',
    '      <td>4.58</td>\n', """      <td>41.22</td>
""", '    </tr>\n',
    '    <tr>\n', '      <th>92</th>\n', '      <th>Final Critic</th>\n',
    """      <td>8</td>
""", '      <td>4.88</td>\n',
    '      <td>39.04</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>103</th>
""", '      <th>Singed Scalpel</th>\n',
    '      <td>8</td>\n', '      <td>4.35</td>\n',
    """      <td>34.80</td>
""", '    </tr>\n', '    <tr>\n',
    '      <th>59</th>\n',
    """      <th>Lightning, Etcher of the King</th>
""",
    '      <td>8</td>\n', '      <td>4.23</td>\n', '      <td>33.84</td>\n',
    '    </tr>\n', '    <tr>\n', """      <th>108</th>
""",
    '      <th>Extraction, Quickblade Of Trembling Hands</th>\n',
    '      <td>9</td>\n', """      <td>3.53</td>
""",
    '      <td>31.77</td>\n', '    </tr>\n', '    <tr>\n',
    '      <th>78</th>\n', """      <th>Glimmer, Ender of the Moon</th>
""",
    '      <td>7</td>\n', '      <td>4.40</td>\n', '      <td>30.80</td>\n',
    '    </tr>\n', '    <tr>\n', """      <th>72</th>
""",
    "      <th>Winter's Bite</th>\n", '      <td>8</td>\n',
    '      <td>3.77</td>\n', """      <td>30.16</td>
""", '    </tr>\n',
    '    <tr>\n', '      <th>60</th>\n', '      <th>Wolf</th>\n',
    """      <td>8</td>
""", '      <td>3.54</td>\n',
    '      <td>28.32</td>\n', '    </tr>\n', '  </tbody>\n', '</table>\n',
    '</div>'], 'text/plain': [
    """                                                      Purchase Count  \\
"""
    ,
    'Item ID Item Name                                                      \n'
    ,
    """178     Oathbreaker, Last Hope of the Breaking Storm              12   
"""
    ,
    '82      Nirvana                                                    9   \n'
    ,
    """145     Fiery Glass Crusader                                       9   
"""
    ,
    '92      Final Critic                                               8   \n'
    ,
    """103     Singed Scalpel                                             8   
"""
    ,
    '59      Lightning, Etcher of the King                              8   \n'
    ,
    """108     Extraction, Quickblade Of Trembling Hands                  9   
"""
    ,
    '78      Glimmer, Ender of the Moon                                 7   \n'
    ,
    """72      Winter's Bite                                              8   
"""
    ,
    '60      Wolf                                                       8   \n'
    , '\n',
    """                                                      Item Price  \\
"""
    ,
    'Item ID Item Name                                                  \n',
    """178     Oathbreaker, Last Hope of the Breaking Storm        4.23   
""",
    '82      Nirvana                                             4.90   \n',
    """145     Fiery Glass Crusader                                4.58   
""",
    '92      Final Critic                                        4.88   \n',
    """103     Singed Scalpel                                      4.35   
""",
    '59      Lightning, Etcher of the King                       4.23   \n',
    """108     Extraction, Quickblade Of Trembling Hands           3.53   
""",
    '78      Glimmer, Ender of the Moon                          4.40   \n',
    """72      Winter's Bite                                       3.77   
""",
    '60      Wolf                                                3.54   \n',
    '\n',
    """                                                      Total Purchase Value  
"""
    ,
    'Item ID Item Name                                                           \n'
    ,
    """178     Oathbreaker, Last Hope of the Breaking Storm                 50.76  
"""
    ,
    '82      Nirvana                                                      44.10  \n'
    ,
    """145     Fiery Glass Crusader                                         41.22  
"""
    ,
    '92      Final Critic                                                 39.04  \n'
    ,
    """103     Singed Scalpel                                               34.80  
"""
    ,
    '59      Lightning, Etcher of the King                                33.84  \n'
    ,
    """108     Extraction, Quickblade Of Trembling Hands                    31.77  
"""
    ,
    '78      Glimmer, Ender of the Moon                                   30.80  \n'
    ,
    """72      Winter's Bite                                                30.16  
"""
    ,
    '60      Wolf                                                         28.32  '
    ]}, 'execution_count': 102, 'metadata': {}, 'output_type':
    'execute_result'}], 'source': ['\n', '\n',
    """df_top_profit = pd.DataFrame(Top_purchase_item)
""", '\n',
    'df_top_profit.columns.tolist()\n',
    """# df_topitem2 = df_topitem.groupby(['Item ID', 'Item Name']).agg({ 'Item ID': "count", 'Price': "sum"})
"""
    , '# df_topitem2.head(10)\n',
    """# new_group = df_topspenders.groupby(['SN']).agg({ 'SN': "count", 'Price': "sum"})
"""
    ,
    "new_group2 = df_top_profit.sort_values(by='Total Purchase Value', ascending=False)\n"
    , """# new_group2 = new_group2.reset_index(drop=True)
""",
    "#new_group2.columns=['Purchase Count', 'Total Purchase Value']\n",
    """#new_group2['Item Price'] =round((new_group2['Total Purchase Value']/new_group2['Purchase Count']),2)
"""
    , '# new_group2 = new_group2.reset_index(drop=FalsTo\n',
    """#new_group2 = pd.DataFrame(new_group2)
""",
    "#new_group2 = new_group2[['Purchase Count', 'Item Price', 'Total Purchase Value']]\n"
    , 'new_group2.head(10)']}, {'cell_type': 'markdown', 'metadata': {},
    'source': ['## Most Profitable Items']}, {'cell_type': 'markdown',
    'metadata': {}, 'source': [
    """* Sort the above table by total purchase value in descending order
""",
    '\n', '\n', '* Optional: give the displayed data cleaner formatting\n',
    '\n', '\n', """* Display a preview of the data frame
""", '\n']}, {
    'cell_type': 'code', 'execution_count': 10, 'metadata': {'scrolled':
    true}, 'outputs': [{'data': {'text/html': ['<div>\n',
    """<table border="1" class="dataframe">
""", '  <thead>\n',
    '    <tr style="text-align: right;">\n', '      <th></th>\n',
    '      <th></th>\n', """      <th>Purchase Count</th>
""",
    '      <th>Item Price</th>\n', '      <th>Total Purchase Value</th>\n',
    '    </tr>\n', '    <tr>\n', """      <th>Item ID</th>
""",
    '      <th>Item Name</th>\n', '      <th></th>\n', '      <th></th>\n',
    '      <th></th>\n', '    </tr>\n', '  </thead>\n', '  <tbody>\n',
    '    <tr>\n', """      <th>178</th>
""",
    '      <th>Oathbreaker, Last Hope of the Breaking Storm</th>\n',
    '      <td>12</td>\n', """      <td>$4.23</td>
""",
    '      <td>$50.76</td>\n', '    </tr>\n', '    <tr>\n',
    '      <th>82</th>\n', """      <th>Nirvana</th>
""",
    '      <td>9</td>\n', '      <td>$4.90</td>\n',
    '      <td>$44.10</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>145</th>
""", '      <th>Fiery Glass Crusader</th>\n',
    '      <td>9</td>\n', '      <td>$4.58</td>\n',
    """      <td>$41.22</td>
""", '    </tr>\n', '    <tr>\n',
    '      <th>92</th>\n', '      <th>Final Critic</th>\n',
    """      <td>8</td>
""", '      <td>$4.88</td>\n',
    '      <td>$39.04</td>\n', '    </tr>\n', '    <tr>\n',
    """      <th>103</th>
""", '      <th>Singed Scalpel</th>\n',
    '      <td>8</td>\n', '      <td>$4.35</td>\n',
    """      <td>$34.80</td>
""", '    </tr>\n', '  </tbody>\n',
    '</table>\n', '</div>'], 'text/plain': [
    """                                                     Purchase Count  \\
"""
    ,
    'Item ID Item Name                                                     \n',
    """178     Oathbreaker, Last Hope of the Breaking Storm             12   
"""
    ,
    '82      Nirvana                                                   9   \n',
    """145     Fiery Glass Crusader                                      9   
"""
    ,
    '92      Final Critic                                              8   \n',
    """103     Singed Scalpel                                            8   
"""
    , '\n',
    '                                                     Item Price  \\\n',
    """Item ID Item Name                                                 
""",
    '178     Oathbreaker, Last Hope of the Breaking Storm      $4.23   \n',
    """82      Nirvana                                           $4.90   
""",
    '145     Fiery Glass Crusader                              $4.58   \n',
    """92      Final Critic                                      $4.88   
""",
    '103     Singed Scalpel                                    $4.35   \n',
    '\n',
    """                                                     Total Purchase Value  
"""
    ,
    'Item ID Item Name                                                          \n'
    ,
    """178     Oathbreaker, Last Hope of the Breaking Storm               $50.76  
"""
    ,
    '82      Nirvana                                                    $44.10  \n'
    ,
    """145     Fiery Glass Crusader                                       $41.22  
"""
    ,
    '92      Final Critic                                               $39.04  \n'
    ,
    '103     Singed Scalpel                                             $34.80  '
    ]}, 'execution_count': 10, 'metadata': {}, 'output_type':
    'execute_result'}], 'source': []}], 'metadata': {'anaconda-cloud': {},
    'kernel_info': {'name': 'python3'}, 'kernelspec': {'display_name':
    'Python [default]', '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.5'}, 'nteract': {'version': '0.2.0'}}, 'nbformat': 4,
    'nbformat_minor': 2}

{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Heroes Of Pymoli Data Analysis\n",
    "* Of the 1163 active players, the vast majority are male (84%). There also exists, a smaller, but notable proportion of female players (14%).\n",
    "\n",
    "* Our peak age demographic falls between 20-24 (44.8%) with secondary groups falling between 15-19 (18.60%) and 25-29 (13.4%).  \n",
    "-----"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Note\n",
    "* Instructions have been included for each segment. You do not have to follow them exactly, but they are included to help you think through the steps."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Dependencies and Setup\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "from IPython.core.interactiveshell import InteractiveShell\n",
    "InteractiveShell.ast_node_interactivity = \"all\"\n",
    "# File to Load (Remember to Change These)\n",
    "file_to_load = \"purchase_data.csv\"\n",
    "\n",
    "# Read Purchasing File and store into Pandas data frame\n",
    "purchase_data = pd.read_csv(file_to_load)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Player Count"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Display the total number of players\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'Total Players': 780}\n"
     ]
    }
   ],
   "source": [
    "purchase_anadf0 = []\n",
    "Total_Players = purchase_data['SN'].count()\n",
    "Total_Players = {'Total Players': Total_Players}\n",
    "print(Total_Players)\n",
    "# purchase_anadf0 = purchase_anadf0.append({'Total Players' : Total_Players})\n",
    "# purchase_anadf0 = purchase_anadf0.append(Total_Players)\n",
    "# print (purchase_anadf0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Purchasing Analysis (Total)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Run basic calculations to obtain number of unique items, average price, etc.\n",
    "\n",
    "\n",
    "* Create a summary data frame to hold the results\n",
    "\n",
    "\n",
    "* Optional: give the displayed data cleaner formatting\n",
    "\n",
    "\n",
    "* Display the summary data frame\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   Number unique items Average Price  Total Purchases Total Revenue\n",
      "0                  179         $3.05              780     $2,379.77\n"
     ]
    }
   ],
   "source": [
    "#purchase_anadf = {'Number unique items': (purchase_data['Item Name'].nunique())}\n",
    "Average_Price = {'Average Price': ('${:,.2f}'.format (purchase_data['Price'].mean()))}                                  \n",
    "# purchase_anadf3 = {'Total Revenue': ('${:,.2f}'.format (purchase_data['Price'].sum()))}\n",
    "\n",
    "#Purchase_df = purchase_anadfpurchase_anadfpurchase_anadfpurchase_anadf\n",
    "list_para = pd.DataFrame({'Number unique items': (purchase_data['Item Name'].nunique()), 'Average Price': '${:,.2f}'.format (purchase_data['Price'].mean())\n",
    "             , 'Total Purchases': (purchase_data['SN'].count()), 'Total Revenue': ('${:,.2f}'.format (purchase_data['Price'].sum()))\n",
    "                         }, index =[0])\n",
    "# Purchase_df0 = pd.DataFrame.from_dict(list_para, orient='index')\n",
    "print (list_para)\n",
    "# purchase_anadf4 = '${:,.2f}'.format (purchase_data['Price'])\n",
    "# purchase_anadf2 = '${:,.2f}'.format(purchase_anadf2)\n",
    "# print (dfPur_tab)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Gender Demographics"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Percentage and Count of Male Players\n",
    "\n",
    "\n",
    "* Percentage and Count of Female Players\n",
    "\n",
    "\n",
    "* Percentage and Count of Other / Non-Disclosed\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   Gender Percent of Players  Total Players\n",
      "0    Male                84%            652\n",
      "1  Female                14%            113\n",
      "2   Other                 2%             15\n"
     ]
    }
   ],
   "source": [
    "# percent and count of Male Players\n",
    "Total_players = purchase_data['Gender'].count()\n",
    "Total_male = purchase_data.loc[purchase_data['Gender'] == 'Male',['Gender']].count()\n",
    "Percent_male = ( Total_male / Total_players)\n",
    "Percent_male2 = ( Total_male / Total_players)\n",
    "Percent_male = '{:.0%}'.format(Percent_male['Gender'])\n",
    "PerCount_maledf = pd.DataFrame({\"Percent of Players\" : Percent_male, \"Total Players\" : Total_male})\n",
    "PerCount_maledf.index.name = 'Male'\n",
    "# print(PerCount_maledf)\n",
    "\n",
    "#PerCount_maledf.columns(0) = 'Gender'\n",
    "# percent and count of Female Players\n",
    "Total_female = purchase_data.loc[purchase_data['Gender'] == 'Female',['Gender']].count()\n",
    "Percent_female = ( Total_female / Total_players)\n",
    "Percent_female2 = ( Total_female / Total_players)\n",
    "Percent_female = '{:.0%}'.format(Percent_female['Gender'])\n",
    "PerCount_femaledf = pd.DataFrame({\"Percent of Players\" : Percent_female, \"Total Players\" : Total_female})\n",
    "PerCount_femaledf.index.name = 'Female'\n",
    "\n",
    "# percent and count of other Players\n",
    "# Other / Non-Disclosed\n",
    "Total_other = purchase_data.loc[purchase_data['Gender'] == 'Other / Non-Disclosed',['Gender']].count()\n",
    "Percent_other = ( Total_other / Total_players)\n",
    "Percent_other2 = ( Total_other / Total_players)\n",
    "Percent_other = '{:.0%}'.format(Percent_other['Gender'])\n",
    "PerCount_otherdf = pd.DataFrame({\"Percent of Players\" : Percent_other, \"Total Players\" : Total_other})\n",
    "PerCount_otherdf.index.name = 'Other'\n",
    "# print (Percent_other)\n",
    "# merge tables \n",
    "# print(Percent_male2 * int(purchase_data['Price'].sum()))\n",
    "gender_demodf = pd.merge(PerCount_maledf, PerCount_femaledf, how='outer')\n",
    "gender_demodf = pd.merge(gender_demodf, PerCount_otherdf, how='outer')\n",
    "gender = ['Male', 'Female', 'Other']\n",
    "idx = 0\n",
    "gender_demodf.insert(loc=idx, column = 'Gender', value = gender)\n",
    "print(gender_demodf)\n",
    "#df.insert(idx, column='A', value=new_col)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "#def add_mkt_return(grp):\n",
    "#   .....:     grp['mkt_return'] = grp['return'].sum()\n",
    "#   .....:     return grp\n",
    "#   .....: \n",
    "\n",
    "#In [238]: df.groupby('yearmonth').apply(add_mkt_return)\n",
    "#Out[238]: "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "## Purchasing Analysis (Gender)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Run basic calculations to obtain purchase count, avg. purchase price, avg. purchase total per person etc. by gender\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "* Create a summary data frame to hold the results\n",
    "\n",
    "\n",
    "* Optional: give the displayed data cleaner formatting\n",
    "\n",
    "\n",
    "* Display the summary data frame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   Gender  Purchase Count  Average Purchase Price  Total Purchase Value  \\\n",
      "0    Male             652                3.017853                  1989   \n",
      "1  Female             113                3.203009                   344   \n",
      "2   Other              15                3.050987                    45   \n",
      "\n",
      "   Avg Purchase Total per Person  \n",
      "0                       4.065372  \n",
      "1                       4.468395  \n",
      "2                       4.562727  \n"
     ]
    }
   ],
   "source": [
    "\n",
    "\n",
    "\n",
    "# percent and count of Male Players\n",
    "Total_players = purchase_data['Gender'].count()\n",
    "Total_male = purchase_data.loc[purchase_data['Gender'] == 'Male',['Gender']].count()\n",
    "Totalavg_male = purchase_data['Price'].loc[purchase_data['Gender'] == 'Male'].mean()\n",
    "# Totalavgall_male = (purchase_data['Price'].sum()) / (purchase_data['Gender'] == 'Male').count()\n",
    "Totalavgall_male = (purchase_data[(purchase_data['Gender'] == 'Male')]['Price'].sum()) / (purchase_data[(purchase_data['Gender'] == 'Male')]['SN'].nunique())\n",
    "\n",
    "# print(Totalavgall_male)\n",
    "Total_malePurchase = int((Total_male / Total_players) * (purchase_data['Price'].sum()))\n",
    "\n",
    "# print(Total_malePurchase)\n",
    "PerCount_maledf = pd.DataFrame({\"Purchase Count\" : Total_male, \"Average Purchase Price\": Totalavg_male, \"Total Purchase Value\" : Total_malePurchase, \"Avg Purchase Total per Person\" : Totalavgall_male})\n",
    "PerCount_maledf.index.name = 'Male'\n",
    "# print(PerCount_maledf)\n",
    "\n",
    "\n",
    "# percent and count of Female Players\n",
    "Total_female = purchase_data.loc[purchase_data['Gender'] == 'Female',['Gender']].count()\n",
    "Total_femalePurchase = int(( Total_female / Total_players) * (purchase_data['Price'].sum()))\n",
    "Totalavg_female = purchase_data['Price'].loc[purchase_data['Gender'] == 'Female'].mean()\n",
    "Totalavgall_female = (purchase_data[(purchase_data['Gender'] == 'Female')]['Price'].sum()) / (purchase_data[(purchase_data['Gender'] == 'Female')]['SN'].nunique())\n",
    "# Percent_female2 = ( Total_female / Total_players)\n",
    "# Percent_female = '{:.0%}'.format(Percent_female['Gender'])\n",
    "PerCount_femaledf = pd.DataFrame({\"Purchase Count\" : Total_female,\"Average Purchase Price\": Totalavg_female, \"Total Purchase Value\" : Total_femalePurchase, \"Avg Purchase Total per Person\": Totalavgall_female})           \n",
    "PerCount_femaledf.index.name = 'Female'\n",
    "# print(PerCount_femaledf)\n",
    "\n",
    "# percent and count of other Players\n",
    "# Other / Non-Disclosed\n",
    "Total_other = purchase_data.loc[purchase_data['Gender'] == 'Other / Non-Disclosed',['Gender']].count()\n",
    "# Percent_other = ( Total_other / Total_players)\n",
    "Total_otherPurchase = int(((purchase_data['Price'].sum() * (Total_other / Total_players))))\n",
    "Totalavg_other = purchase_data['Price'].loc[pd.notnull(purchase_data['Gender'] == 'Other / Non-Disclosed')].mean()\n",
    "\n",
    "# Totalavgall_other = (purchase_data['Price'].sum()) / purchase_data[(purchase_data['Gender'] == 'Other / Non-Disclosed')]['SN'].nunique()\n",
    "Totalavgall_other = (purchase_data[(purchase_data['Gender'] == 'Other / Non-Disclosed')]['Price'].sum()) / (purchase_data[(purchase_data['Gender'] == 'Other / Non-Disclosed')]['SN'].nunique())\n",
    "\n",
    "# print(Totalavgall_other)\n",
    "# df.groupby('ID')['domain'].nunique()\n",
    "# print(purchase_data['Price'].sum())\n",
    "# print(purchase_data[(purchase_data['Gender'] == 'Other / Non-Disclosed')].count())\n",
    "\n",
    "# Percent_other2 = ( Total_other / Total_players)\n",
    "# Percent_other = '{:.0%}'.format(Percent_other['Gender'])\n",
    "#PerCount_otherdf = pd.DataFrame({\"Purchase Count\" : Total_other, \"Total Purchase Value\" : Total_otherPurchase})\n",
    "PerCount_otherdf = pd.DataFrame({\"Purchase Count\" : Total_other,\"Average Purchase Price\": Totalavg_other, \"Total Purchase Value\" : Total_otherPurchase, \"Avg Purchase Total per Person\": Totalavgall_other})           \n",
    "PerCount_otherdf.index.name = 'Other'\n",
    "# print(PerCount_otherdf)\n",
    "# print (Percent_other)\n",
    "# merge tables \n",
    "# print(Percent_male2 * int(purchase_data['Price'].sum()))\n",
    "gender_demodf = pd.merge(PerCount_maledf, PerCount_femaledf, how='outer')\n",
    "gender_demodf = pd.merge(gender_demodf, PerCount_otherdf, how='outer')\n",
    "gender = ['Male', 'Female', 'Other']\n",
    "idx = 0\n",
    "gender_demodf.insert(loc=idx, column = 'Gender', value = gender)\n",
    "print(gender_demodf)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Age Demographics"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Establish bins for ages\n",
    "\n",
    "\n",
    "* Categorize the existing players using the age bins. Hint: use pd.cut()\n",
    "\n",
    "\n",
    "* Calculate the numbers and percentages by age group\n",
    "\n",
    "\n",
    "* Create a summary data frame to hold the results\n",
    "\n",
    "\n",
    "* Optional: round the percentage column to two decimal points\n",
    "\n",
    "\n",
    "* Display Age Demographics Table\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Purchase ID</th>\n",
       "      <th>SN</th>\n",
       "      <th>Age</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Item ID</th>\n",
       "      <th>Item Name</th>\n",
       "      <th>Price</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Age Range</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>&lt;10</th>\n",
       "      <td>778</td>\n",
       "      <td>Tyeurith29</td>\n",
       "      <td>9</td>\n",
       "      <td>Male</td>\n",
       "      <td>179</td>\n",
       "      <td>Wolf, Promise of the Moonwalker</td>\n",
       "      <td>4.93</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10-14</th>\n",
       "      <td>774</td>\n",
       "      <td>Zhisrisu83</td>\n",
       "      <td>14</td>\n",
       "      <td>Male</td>\n",
       "      <td>180</td>\n",
       "      <td>Wolf</td>\n",
       "      <td>4.94</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15-19</th>\n",
       "      <td>771</td>\n",
       "      <td>Yoishirrala98</td>\n",
       "      <td>19</td>\n",
       "      <td>Other / Non-Disclosed</td>\n",
       "      <td>183</td>\n",
       "      <td>Yearning Mageblade</td>\n",
       "      <td>4.91</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20-24</th>\n",
       "      <td>779</td>\n",
       "      <td>Zontibe81</td>\n",
       "      <td>24</td>\n",
       "      <td>Other / Non-Disclosed</td>\n",
       "      <td>183</td>\n",
       "      <td>Yearning Mageblade</td>\n",
       "      <td>4.99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25-29</th>\n",
       "      <td>772</td>\n",
       "      <td>Yasur35</td>\n",
       "      <td>29</td>\n",
       "      <td>Other / Non-Disclosed</td>\n",
       "      <td>183</td>\n",
       "      <td>Worldbreaker</td>\n",
       "      <td>4.94</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30-34</th>\n",
       "      <td>770</td>\n",
       "      <td>Yarolwen77</td>\n",
       "      <td>34</td>\n",
       "      <td>Male</td>\n",
       "      <td>178</td>\n",
       "      <td>Yearning Mageblade</td>\n",
       "      <td>4.93</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35-39</th>\n",
       "      <td>768</td>\n",
       "      <td>Tyaerith73</td>\n",
       "      <td>39</td>\n",
       "      <td>Other / Non-Disclosed</td>\n",
       "      <td>179</td>\n",
       "      <td>Wolf, Promise of the Moonwalker</td>\n",
       "      <td>4.91</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40+</th>\n",
       "      <td>761</td>\n",
       "      <td>Salilis27</td>\n",
       "      <td>45</td>\n",
       "      <td>Male</td>\n",
       "      <td>173</td>\n",
       "      <td>Victor Iron Spikes</td>\n",
       "      <td>4.93</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           Purchase ID             SN  Age                 Gender  Item ID  \\\n",
       "Age Range                                                                    \n",
       "<10                778     Tyeurith29    9                   Male      179   \n",
       "10-14              774     Zhisrisu83   14                   Male      180   \n",
       "15-19              771  Yoishirrala98   19  Other / Non-Disclosed      183   \n",
       "20-24              779      Zontibe81   24  Other / Non-Disclosed      183   \n",
       "25-29              772        Yasur35   29  Other / Non-Disclosed      183   \n",
       "30-34              770     Yarolwen77   34                   Male      178   \n",
       "35-39              768     Tyaerith73   39  Other / Non-Disclosed      179   \n",
       "40+                761      Salilis27   45                   Male      173   \n",
       "\n",
       "                                 Item Name  Price  \n",
       "Age Range                                          \n",
       "<10        Wolf, Promise of the Moonwalker   4.93  \n",
       "10-14                                 Wolf   4.94  \n",
       "15-19                   Yearning Mageblade   4.91  \n",
       "20-24                   Yearning Mageblade   4.99  \n",
       "25-29                         Worldbreaker   4.94  \n",
       "30-34                   Yearning Mageblade   4.93  \n",
       "35-39      Wolf, Promise of the Moonwalker   4.91  \n",
       "40+                     Victor Iron Spikes   4.93  "
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Age Range</th>\n",
       "      <th>Percent of Players</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>23</td>\n",
       "      <td>2.95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>28</td>\n",
       "      <td>3.59</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>136</td>\n",
       "      <td>17.44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>365</td>\n",
       "      <td>46.79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>101</td>\n",
       "      <td>12.95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>73</td>\n",
       "      <td>9.36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>41</td>\n",
       "      <td>5.26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>13</td>\n",
       "      <td>1.67</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Age Range Percent of Players\n",
       "0         23               2.95\n",
       "1         28               3.59\n",
       "2        136              17.44\n",
       "3        365              46.79\n",
       "4        101              12.95\n",
       "5         73               9.36\n",
       "6         41               5.26\n",
       "7         13               1.67"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Total Count</th>\n",
       "      <th>Percent of Players</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Age Range</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>&lt;10</th>\n",
       "      <td>23</td>\n",
       "      <td>2.95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10-14</th>\n",
       "      <td>28</td>\n",
       "      <td>3.59</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15-19</th>\n",
       "      <td>136</td>\n",
       "      <td>17.44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20-24</th>\n",
       "      <td>365</td>\n",
       "      <td>46.79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25-29</th>\n",
       "      <td>101</td>\n",
       "      <td>12.95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30-34</th>\n",
       "      <td>73</td>\n",
       "      <td>9.36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35-39</th>\n",
       "      <td>41</td>\n",
       "      <td>5.26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40+</th>\n",
       "      <td>13</td>\n",
       "      <td>1.67</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           Total Count Percent of Players\n",
       "Age Range                                \n",
       "<10                 23               2.95\n",
       "10-14               28               3.59\n",
       "15-19              136              17.44\n",
       "20-24              365              46.79\n",
       "25-29              101              12.95\n",
       "30-34               73               9.36\n",
       "35-39               41               5.26\n",
       "40+                 13               1.67"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "df_age2 = pd.DataFrame(purchase_data)\n",
    "bins = [0, 9.90, 14.90, 19.90, 24.90, 29.90, 34.90, 39.90, 99999]\n",
    "group_names = ['<10', '10-14','15-19', '20-24', '25-29', '30-34', '35-39', '40+']\n",
    "df_age2[\"Age Range\"] = pd.cut(purchase_data[\"Age\"], bins, labels=group_names)\n",
    "df_age2= df_age2.groupby(\"Age Range\")\n",
    "df_age2.max()\n",
    "# df_age2 = df_age2.groupby('Age Range')\n",
    "# df_age2.head(0)\n",
    "age_count = pd.DataFrame((df_age2['Age Range'].count()))\n",
    "# df_age2= pd.DataFrame(\n",
    "\n",
    "age_count[\"Percent of Players\"] = (age_count['Age Range'].divide((purchase_data['SN'].count())))*100\n",
    "\n",
    "\n",
    "age_count['Percent of Players'] = age_count['Percent of Players'].apply('{:.2f}'.format)\n",
    "age_count.reset_index(drop=True)\n",
    "age_count = age_count.rename(columns={'Age Range': 'Total Count'})\n",
    "#age_count[\"Age Range\"] = age_count[\"Percent of Players\"]\n",
    "# ('{:.2f}'.format(age_count['Percent of Players']))\n",
    "\n",
    "# df = df.rename(columns={'oldName1': 'newName1', 'oldName2': 'newName2'})\n",
    "\n",
    "# df['Rate'] = df['Rate'].apply('{:.2f}%'.format)\n",
    "# format(math.pi, '.2f')\n",
    "# df['c'] = df['a'].divide(df['b'], fill_value=1)\n",
    "# (\"{0:.2f}\".format(a))\n",
    "\n",
    "age_count.head(10)\n",
    "\n",
    "\n",
    "# df_age = pd.DataFrame(df_age['Age Range'].count())\n",
    "# df_age[\"Percentage of Players\"] = df_age(age_count[\"Age Range\"] / (purchase_data['SN'].count()))\n",
    "#age_count = ((age_count[\"Age Range\"] / purchase_data['Gender'].count()) * 100)\n",
    "\n",
    "# age_count = ((df_age2['Age Range'].count()))\n",
    "# b = np.insert(a, insert_index, values=a[:,2], axis=1)\n",
    "# df.insert( index,name,value)\n",
    "\n",
    "# df_age[\"Percent of Players\"] = df_age[\"Age Range\"]\n",
    "# df_age2.reset_index()\n",
    "\n",
    "# df_age.set_index(['Age Range', 'Total Count'])\n",
    "# df.set_index(['year', 'month'])\n",
    "# df_age[\"Percentage of Players\"] = df_age[\"Age Range\"] / (purchase_data['SN'].count())\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Purchasing Analysis (Age)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Bin the purchase_data data frame by age\n",
    "\n",
    "\n",
    "* Run basic calculations to obtain purchase count, avg. purchase price, avg. purchase total per person etc. in the table below\n",
    "\n",
    "\n",
    "* Create a summary data frame to hold the results\n",
    "\n",
    "\n",
    "* Optional: give the displayed data cleaner formatting\n",
    "\n",
    "\n",
    "* Display the summary data frame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "            SN    Price\n",
      "Age Range              \n",
      "<10         23    77.13\n",
      "10-14       28    82.78\n",
      "15-19      136   412.89\n",
      "20-24      365  1114.06\n",
      "25-29      101   293.00\n",
      "30-34       73   214.00\n",
      "35-39       41   147.67\n",
      "40+         13    38.24\n"
     ]
    }
   ],
   "source": [
    "\n",
    "df_purchase = pd.DataFrame(purchase_data)\n",
    "bins = [0, 9.90, 14.90, 19.90, 24.90, 29.90, 34.90, 39.90, 99999]\n",
    "group_names = ['<10', '10-14','15-19', '20-24', '25-29', '30-34', '35-39', '40+']\n",
    "df_purchase[\"Age Range\"] = pd.cut(purchase_data[\"Age\"], bins, labels=group_names)\n",
    "\n",
    "#df_purchasedf= df_purchase[[\"Age Range\", \"SN\", \"Price\"]]\n",
    "# print(df_purchasedf)\n",
    "df_purchasedf= df_purchase.groupby(['Age Range']).agg({'SN': \"count\", 'Price': \"sum\"})\n",
    "print(df_purchasedf)\n",
    "#\n",
    "#new_group = df_topspenders.groupby(['SN']).agg({ 'SN': \"count\", 'Price': \"sum\"})\n",
    "#new_group2 = new_group.sort_values(by='SN', ascending=False)\n",
    "#new_group2\n",
    "#new_group2['Average'] =round((new_group2['Price']/new_group2['SN']),2)\n",
    "#\n",
    "\n",
    "\n",
    "#df_purchasedf\n",
    "#df_purchasedf1 = df_purchasedf['Age Range'].count()\n",
    "#df_purchasedf2 = df_purchasedf['Price'].sum() / df_purchasedf['Age Range'].count()\n",
    "#df_purchasedf3 = pd.DataFrame[df_purchasedf['SN'].mean()]\n",
    "# df_purchasedf[ \"Purchase Count\", \"Average Purchase Price\",\t\"Total Purchase Value\",\t\"Average Purchase Total per Person\"] = \n",
    "#            [df_purchasedf['SN'].count(), df_purchasedf[''] \n",
    "# df_purchase.sort_index(by='Age Range',ascending=False)\n",
    "\n",
    "# df_count_purchase = pd.DataFrame((df_purchase['Age Range'].count()))\n",
    "\n",
    "# Averag_price = df_purchase['Price'].sum()/ df_purchase['Price'].count()\n",
    "# Totalg_price = df_purchase['Price'].sum()\n",
    "# df_purchase.head()\n",
    "#df_purchasedf.head()\n",
    "# AverPur_Total = df_purchase.groupby('SN')['Price'].mean()\n",
    "# df.groupby('male')['age'].mean()\n",
    "#df_count_purchase.head()\n",
    "# df.groupby(['reciept','date'])['reciept'].count()\n",
    "# df_age2 = df_age2.groupby('Age Range')\n",
    "# df_age2.head(0)\n",
    "#age_count = pd.DataFrame((df_age2['Age Range'].count()))\n",
    "# df_age2= pd.DataFrame(\n",
    "\n",
    "#age_count[\"Percent of Players\"] = (age_count['Age Range'].divide((purchase_data['SN'].count())))*100\n",
    "\n",
    "\n",
    "#age_count['Percent of Players'] = age_count['Percent of Players'].apply('{:.2f}'.format)\n",
    "#age_count.reset_index(drop=True)\n",
    "#age_count = age_count.rename(columns={'Age Range': 'Total Count'})\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "#Purchase Count\tAverage Purchase Price\tTotal Purchase Value\tAvg Total Purchase per Person\n",
    "#10-14\t28\t$2.96\t$82.78\t$3.76\n",
    "#15-19\t136\t$3.04\t$412.89\t$3.86\n",
    "#20-24\t365\t$3.05\t$1,114.06\t$4.3"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Top Spenders"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Run basic calculations to obtain the results in the table below\n",
    "\n",
    "\n",
    "* Create a summary data frame to hold the results\n",
    "\n",
    "\n",
    "* Sort the total purchase value column in descending order\n",
    "\n",
    "\n",
    "* Optional: give the displayed data cleaner formatting\n",
    "\n",
    "\n",
    "* Display a preview of the summary data frame\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\lcc25\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:3: FutureWarning: 'SN' is both an index level and a column label.\n",
      "Defaulting to column, but this will raise an ambiguity error in a future version\n",
      "  This is separate from the ipykernel package so we can avoid doing imports until\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>SN</th>\n",
       "      <th>Price</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SN</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Lisosia93</th>\n",
       "      <td>5</td>\n",
       "      <td>18.96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Iral74</th>\n",
       "      <td>4</td>\n",
       "      <td>13.62</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Idastidru52</th>\n",
       "      <td>4</td>\n",
       "      <td>15.45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Asur53</th>\n",
       "      <td>3</td>\n",
       "      <td>7.44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Inguron55</th>\n",
       "      <td>3</td>\n",
       "      <td>11.11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Aina42</th>\n",
       "      <td>3</td>\n",
       "      <td>9.22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ilarin91</th>\n",
       "      <td>3</td>\n",
       "      <td>12.70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Idai61</th>\n",
       "      <td>3</td>\n",
       "      <td>8.23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Umolrian85</th>\n",
       "      <td>3</td>\n",
       "      <td>8.13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ialallo29</th>\n",
       "      <td>3</td>\n",
       "      <td>11.84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tyisur83</th>\n",
       "      <td>3</td>\n",
       "      <td>5.36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tyidaim51</th>\n",
       "      <td>3</td>\n",
       "      <td>11.83</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Pheodaisun84</th>\n",
       "      <td>3</td>\n",
       "      <td>8.31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hiaral50</th>\n",
       "      <td>3</td>\n",
       "      <td>4.19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Haillyrgue51</th>\n",
       "      <td>3</td>\n",
       "      <td>9.50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zontibe81</th>\n",
       "      <td>3</td>\n",
       "      <td>8.03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Iri67</th>\n",
       "      <td>3</td>\n",
       "      <td>11.37</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hada39</th>\n",
       "      <td>3</td>\n",
       "      <td>8.57</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Raesty92</th>\n",
       "      <td>3</td>\n",
       "      <td>8.73</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Rarallo90</th>\n",
       "      <td>3</td>\n",
       "      <td>9.05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chadolyla44</th>\n",
       "      <td>3</td>\n",
       "      <td>11.46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Saedaiphos46</th>\n",
       "      <td>3</td>\n",
       "      <td>8.83</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Saistyphos30</th>\n",
       "      <td>3</td>\n",
       "      <td>10.33</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Siallylis44</th>\n",
       "      <td>3</td>\n",
       "      <td>10.37</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chamimla85</th>\n",
       "      <td>3</td>\n",
       "      <td>6.30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Silaera56</th>\n",
       "      <td>3</td>\n",
       "      <td>8.48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chamjask73</th>\n",
       "      <td>3</td>\n",
       "      <td>13.83</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chanastnya43</th>\n",
       "      <td>3</td>\n",
       "      <td>8.82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Strithenu87</th>\n",
       "      <td>3</td>\n",
       "      <td>10.18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sondastsda82</th>\n",
       "      <td>3</td>\n",
       "      <td>7.89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Haerith37</th>\n",
       "      <td>1</td>\n",
       "      <td>1.66</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Iduelis31</th>\n",
       "      <td>1</td>\n",
       "      <td>1.10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hiral75</th>\n",
       "      <td>1</td>\n",
       "      <td>1.98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Idaisuir85</th>\n",
       "      <td>1</td>\n",
       "      <td>3.15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Idacal95</th>\n",
       "      <td>1</td>\n",
       "      <td>2.07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Iathenudil29</th>\n",
       "      <td>1</td>\n",
       "      <td>4.60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Iathem87</th>\n",
       "      <td>1</td>\n",
       "      <td>3.19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Iasursti71</th>\n",
       "      <td>1</td>\n",
       "      <td>1.66</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Iasurriacal29</th>\n",
       "      <td>1</td>\n",
       "      <td>4.07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Iarallo65</th>\n",
       "      <td>1</td>\n",
       "      <td>1.75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Iana95</th>\n",
       "      <td>1</td>\n",
       "      <td>3.10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ialidru40</th>\n",
       "      <td>1</td>\n",
       "      <td>3.16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Iadueria43</th>\n",
       "      <td>1</td>\n",
       "      <td>1.71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hyaduesu61</th>\n",
       "      <td>1</td>\n",
       "      <td>4.23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hisridru55</th>\n",
       "      <td>1</td>\n",
       "      <td>3.08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hilaerin92</th>\n",
       "      <td>1</td>\n",
       "      <td>3.61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Haerithp41</th>\n",
       "      <td>1</td>\n",
       "      <td>4.40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hiasurria41</th>\n",
       "      <td>1</td>\n",
       "      <td>1.61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hiarideu73</th>\n",
       "      <td>1</td>\n",
       "      <td>2.50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Heunadil74</th>\n",
       "      <td>1</td>\n",
       "      <td>1.54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Heudai45</th>\n",
       "      <td>1</td>\n",
       "      <td>3.47</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Heollyriap59</th>\n",
       "      <td>1</td>\n",
       "      <td>3.47</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Heollyra92</th>\n",
       "      <td>1</td>\n",
       "      <td>3.07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hariphos58</th>\n",
       "      <td>1</td>\n",
       "      <td>2.05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hallysucal81</th>\n",
       "      <td>1</td>\n",
       "      <td>1.66</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hala31</th>\n",
       "      <td>1</td>\n",
       "      <td>1.02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Haisurra41</th>\n",
       "      <td>1</td>\n",
       "      <td>4.40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hailaphos89</th>\n",
       "      <td>1</td>\n",
       "      <td>3.81</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Haestyphos66</th>\n",
       "      <td>1</td>\n",
       "      <td>1.97</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Iskosian40</th>\n",
       "      <td>1</td>\n",
       "      <td>3.07</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>576 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "               SN  Price\n",
       "SN                      \n",
       "Lisosia93       5  18.96\n",
       "Iral74          4  13.62\n",
       "Idastidru52     4  15.45\n",
       "Asur53          3   7.44\n",
       "Inguron55       3  11.11\n",
       "Aina42          3   9.22\n",
       "Ilarin91        3  12.70\n",
       "Idai61          3   8.23\n",
       "Umolrian85      3   8.13\n",
       "Ialallo29       3  11.84\n",
       "Tyisur83        3   5.36\n",
       "Tyidaim51       3  11.83\n",
       "Pheodaisun84    3   8.31\n",
       "Hiaral50        3   4.19\n",
       "Haillyrgue51    3   9.50\n",
       "Zontibe81       3   8.03\n",
       "Iri67           3  11.37\n",
       "Hada39          3   8.57\n",
       "Raesty92        3   8.73\n",
       "Rarallo90       3   9.05\n",
       "Chadolyla44     3  11.46\n",
       "Saedaiphos46    3   8.83\n",
       "Saistyphos30    3  10.33\n",
       "Siallylis44     3  10.37\n",
       "Chamimla85      3   6.30\n",
       "Silaera56       3   8.48\n",
       "Chamjask73      3  13.83\n",
       "Chanastnya43    3   8.82\n",
       "Strithenu87     3  10.18\n",
       "Sondastsda82    3   7.89\n",
       "...            ..    ...\n",
       "Haerith37       1   1.66\n",
       "Iduelis31       1   1.10\n",
       "Hiral75         1   1.98\n",
       "Idaisuir85      1   3.15\n",
       "Idacal95        1   2.07\n",
       "Iathenudil29    1   4.60\n",
       "Iathem87        1   3.19\n",
       "Iasursti71      1   1.66\n",
       "Iasurriacal29   1   4.07\n",
       "Iarallo65       1   1.75\n",
       "Iana95          1   3.10\n",
       "Ialidru40       1   3.16\n",
       "Iadueria43      1   1.71\n",
       "Hyaduesu61      1   4.23\n",
       "Hisridru55      1   3.08\n",
       "Hilaerin92      1   3.61\n",
       "Haerithp41      1   4.40\n",
       "Hiasurria41     1   1.61\n",
       "Hiarideu73      1   2.50\n",
       "Heunadil74      1   1.54\n",
       "Heudai45        1   3.47\n",
       "Heollyriap59    1   3.47\n",
       "Heollyra92      1   3.07\n",
       "Hariphos58      1   2.05\n",
       "Hallysucal81    1   1.66\n",
       "Hala31          1   1.02\n",
       "Haisurra41      1   4.40\n",
       "Hailaphos89     1   3.81\n",
       "Haestyphos66    1   1.97\n",
       "Iskosian40      1   3.07\n",
       "\n",
       "[576 rows x 2 columns]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Count</th>\n",
       "      <th>Price</th>\n",
       "      <th>Avg Price</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SN</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Lisosia93</th>\n",
       "      <td>5</td>\n",
       "      <td>18.96</td>\n",
       "      <td>3.79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Iral74</th>\n",
       "      <td>4</td>\n",
       "      <td>13.62</td>\n",
       "      <td>3.40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Idastidru52</th>\n",
       "      <td>4</td>\n",
       "      <td>15.45</td>\n",
       "      <td>3.86</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Asur53</th>\n",
       "      <td>3</td>\n",
       "      <td>7.44</td>\n",
       "      <td>2.48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Inguron55</th>\n",
       "      <td>3</td>\n",
       "      <td>11.11</td>\n",
       "      <td>3.70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Aina42</th>\n",
       "      <td>3</td>\n",
       "      <td>9.22</td>\n",
       "      <td>3.07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ilarin91</th>\n",
       "      <td>3</td>\n",
       "      <td>12.70</td>\n",
       "      <td>4.23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Idai61</th>\n",
       "      <td>3</td>\n",
       "      <td>8.23</td>\n",
       "      <td>2.74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Umolrian85</th>\n",
       "      <td>3</td>\n",
       "      <td>8.13</td>\n",
       "      <td>2.71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ialallo29</th>\n",
       "      <td>3</td>\n",
       "      <td>11.84</td>\n",
       "      <td>3.95</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             Count  Price  Avg Price\n",
       "SN                                  \n",
       "Lisosia93        5  18.96       3.79\n",
       "Iral74           4  13.62       3.40\n",
       "Idastidru52      4  15.45       3.86\n",
       "Asur53           3   7.44       2.48\n",
       "Inguron55        3  11.11       3.70\n",
       "Aina42           3   9.22       3.07\n",
       "Ilarin91         3  12.70       4.23\n",
       "Idai61           3   8.23       2.74\n",
       "Umolrian85       3   8.13       2.71\n",
       "Ialallo29        3  11.84       3.95"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_topspenders = pd.DataFrame(purchase_data)\n",
    "new_group = df_topspenders.groupby(['SN']).agg({ 'SN': \"count\", 'Price': \"sum\"})\n",
    "new_group2 = new_group.sort_values(by='SN', ascending=False)\n",
    "new_group2\n",
    "new_group2['Average'] =round((new_group2['Price']/new_group2['SN']),2)\n",
    "# new_group2 = new_group2.reset_index(drop=False)\n",
    "new_group2.columns=['Count', 'Price', 'Avg Price']\n",
    "new_group2.head(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Purchase ID',\n",
       " 'SN',\n",
       " 'Age',\n",
       " 'Gender',\n",
       " 'Item ID',\n",
       " 'Item Name',\n",
       " 'Price',\n",
       " 'Age Range']"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Item ID</th>\n",
       "      <th>Price</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Item ID</th>\n",
       "      <th>Item Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <th>Splinter</th>\n",
       "      <td>4</td>\n",
       "      <td>5.12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <th>Crucifer</th>\n",
       "      <td>3</td>\n",
       "      <td>9.78</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <th>Verdict</th>\n",
       "      <td>6</td>\n",
       "      <td>14.88</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <th>Phantomlight</th>\n",
       "      <td>6</td>\n",
       "      <td>14.94</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <th>Bloodlord's Fetish</th>\n",
       "      <td>5</td>\n",
       "      <td>8.50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <th>Putrid Fan</th>\n",
       "      <td>4</td>\n",
       "      <td>16.32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <th>Rusty Skull</th>\n",
       "      <td>2</td>\n",
       "      <td>7.40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <th>Thorn, Satchel of Dark Souls</th>\n",
       "      <td>7</td>\n",
       "      <td>9.31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <th>Purgatory, Gem of Regret</th>\n",
       "      <td>3</td>\n",
       "      <td>11.79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <th>Thorn, Conqueror of the Corrupted</th>\n",
       "      <td>4</td>\n",
       "      <td>10.92</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                           Item ID  Price\n",
       "Item ID Item Name                                        \n",
       "0       Splinter                                 4   5.12\n",
       "1       Crucifer                                 3   9.78\n",
       "2       Verdict                                  6  14.88\n",
       "3       Phantomlight                             6  14.94\n",
       "4       Bloodlord's Fetish                       5   8.50\n",
       "5       Putrid Fan                               4  16.32\n",
       "6       Rusty Skull                              2   7.40\n",
       "7       Thorn, Satchel of Dark Souls             7   9.31\n",
       "8       Purgatory, Gem of Regret                 3  11.79\n",
       "9       Thorn, Conqueror of the Corrupted        4  10.92"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\lcc25\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:7: FutureWarning: 'Item ID' is both an index level and a column label.\n",
      "Defaulting to column, but this will raise an ambiguity error in a future version\n",
      "  import sys\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Purchase Count</th>\n",
       "      <th>Item Price</th>\n",
       "      <th>Total Purchase Value</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Item ID</th>\n",
       "      <th>Item Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>178</th>\n",
       "      <th>Oathbreaker, Last Hope of the Breaking Storm</th>\n",
       "      <td>12</td>\n",
       "      <td>4.23</td>\n",
       "      <td>50.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>145</th>\n",
       "      <th>Fiery Glass Crusader</th>\n",
       "      <td>9</td>\n",
       "      <td>4.58</td>\n",
       "      <td>41.22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>108</th>\n",
       "      <th>Extraction, Quickblade Of Trembling Hands</th>\n",
       "      <td>9</td>\n",
       "      <td>3.53</td>\n",
       "      <td>31.77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <th>Nirvana</th>\n",
       "      <td>9</td>\n",
       "      <td>4.90</td>\n",
       "      <td>44.10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <th>Pursuit, Cudgel of Necromancy</th>\n",
       "      <td>8</td>\n",
       "      <td>1.02</td>\n",
       "      <td>8.16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>103</th>\n",
       "      <th>Singed Scalpel</th>\n",
       "      <td>8</td>\n",
       "      <td>4.35</td>\n",
       "      <td>34.80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75</th>\n",
       "      <th>Brutality Ivory Warmace</th>\n",
       "      <td>8</td>\n",
       "      <td>2.42</td>\n",
       "      <td>19.36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>72</th>\n",
       "      <th>Winter's Bite</th>\n",
       "      <td>8</td>\n",
       "      <td>3.77</td>\n",
       "      <td>30.16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>60</th>\n",
       "      <th>Wolf</th>\n",
       "      <td>8</td>\n",
       "      <td>3.54</td>\n",
       "      <td>28.32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>59</th>\n",
       "      <th>Lightning, Etcher of the King</th>\n",
       "      <td>8</td>\n",
       "      <td>4.23</td>\n",
       "      <td>33.84</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                      Purchase Count  \\\n",
       "Item ID Item Name                                                      \n",
       "178     Oathbreaker, Last Hope of the Breaking Storm              12   \n",
       "145     Fiery Glass Crusader                                       9   \n",
       "108     Extraction, Quickblade Of Trembling Hands                  9   \n",
       "82      Nirvana                                                    9   \n",
       "19      Pursuit, Cudgel of Necromancy                              8   \n",
       "103     Singed Scalpel                                             8   \n",
       "75      Brutality Ivory Warmace                                    8   \n",
       "72      Winter's Bite                                              8   \n",
       "60      Wolf                                                       8   \n",
       "59      Lightning, Etcher of the King                              8   \n",
       "\n",
       "                                                      Item Price  \\\n",
       "Item ID Item Name                                                  \n",
       "178     Oathbreaker, Last Hope of the Breaking Storm        4.23   \n",
       "145     Fiery Glass Crusader                                4.58   \n",
       "108     Extraction, Quickblade Of Trembling Hands           3.53   \n",
       "82      Nirvana                                             4.90   \n",
       "19      Pursuit, Cudgel of Necromancy                       1.02   \n",
       "103     Singed Scalpel                                      4.35   \n",
       "75      Brutality Ivory Warmace                             2.42   \n",
       "72      Winter's Bite                                       3.77   \n",
       "60      Wolf                                                3.54   \n",
       "59      Lightning, Etcher of the King                       4.23   \n",
       "\n",
       "                                                      Total Purchase Value  \n",
       "Item ID Item Name                                                           \n",
       "178     Oathbreaker, Last Hope of the Breaking Storm                 50.76  \n",
       "145     Fiery Glass Crusader                                         41.22  \n",
       "108     Extraction, Quickblade Of Trembling Hands                    31.77  \n",
       "82      Nirvana                                                      44.10  \n",
       "19      Pursuit, Cudgel of Necromancy                                 8.16  \n",
       "103     Singed Scalpel                                               34.80  \n",
       "75      Brutality Ivory Warmace                                      19.36  \n",
       "72      Winter's Bite                                                30.16  \n",
       "60      Wolf                                                         28.32  \n",
       "59      Lightning, Etcher of the King                                33.84  "
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_topitem = pd.DataFrame(purchase_data)\n",
    "\n",
    "df_topitem.columns.tolist()\n",
    "df_topitem2 = df_topitem.groupby(['Item ID', 'Item Name']).agg({ 'Item ID': \"count\", 'Price': \"sum\"})\n",
    "df_topitem2.head(10)\n",
    "# new_group = df_topspenders.groupby(['SN']).agg({ 'SN': \"count\", 'Price': \"sum\"})\n",
    "new_group2 = df_topitem2.sort_values(by='Item ID', ascending=False)\n",
    "# new_group2 = new_group2.reset_index(drop=True)\n",
    "new_group2.columns=['Purchase Count', 'Total Purchase Value']\n",
    "new_group2['Item Price'] =round((new_group2['Total Purchase Value']/new_group2['Purchase Count']),2)\n",
    "# new_group2 = new_group2.reset_index(drop=FalsTo\n",
    "new_group2 = pd.DataFrame(new_group2)\n",
    "Top_purchase_item = new_group2[['Purchase Count', 'Item Price', 'Total Purchase Value']]\n",
    "Top_purchase_item.head(10)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Most Popular Items"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Retrieve the Item ID, Item Name, and Item Price columns\n",
    "\n",
    "\n",
    "* Group by Item ID and Item Name. Perform calculations to obtain purchase count, item price, and total purchase value\n",
    "\n",
    "\n",
    "* Create a summary data frame to hold the results\n",
    "\n",
    "\n",
    "* Sort the purchase count column in descending order\n",
    "\n",
    "\n",
    "* Optional: give the displayed data cleaner formatting\n",
    "\n",
    "\n",
    "* Display a preview of the summary data frame\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Purchase Count</th>\n",
       "      <th>Item Price</th>\n",
       "      <th>Total Purchase Value</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Item ID</th>\n",
       "      <th>Item Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>178</th>\n",
       "      <th>Oathbreaker, Last Hope of the Breaking Storm</th>\n",
       "      <td>12</td>\n",
       "      <td>$4.23</td>\n",
       "      <td>$50.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>145</th>\n",
       "      <th>Fiery Glass Crusader</th>\n",
       "      <td>9</td>\n",
       "      <td>$4.58</td>\n",
       "      <td>$41.22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>108</th>\n",
       "      <th>Extraction, Quickblade Of Trembling Hands</th>\n",
       "      <td>9</td>\n",
       "      <td>$3.53</td>\n",
       "      <td>$31.77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <th>Nirvana</th>\n",
       "      <td>9</td>\n",
       "      <td>$4.90</td>\n",
       "      <td>$44.10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <th>Pursuit, Cudgel of Necromancy</th>\n",
       "      <td>8</td>\n",
       "      <td>$1.02</td>\n",
       "      <td>$8.16</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                     Purchase Count  \\\n",
       "Item ID Item Name                                                     \n",
       "178     Oathbreaker, Last Hope of the Breaking Storm             12   \n",
       "145     Fiery Glass Crusader                                      9   \n",
       "108     Extraction, Quickblade Of Trembling Hands                 9   \n",
       "82      Nirvana                                                   9   \n",
       "19      Pursuit, Cudgel of Necromancy                             8   \n",
       "\n",
       "                                                     Item Price  \\\n",
       "Item ID Item Name                                                 \n",
       "178     Oathbreaker, Last Hope of the Breaking Storm      $4.23   \n",
       "145     Fiery Glass Crusader                              $4.58   \n",
       "108     Extraction, Quickblade Of Trembling Hands         $3.53   \n",
       "82      Nirvana                                           $4.90   \n",
       "19      Pursuit, Cudgel of Necromancy                     $1.02   \n",
       "\n",
       "                                                     Total Purchase Value  \n",
       "Item ID Item Name                                                          \n",
       "178     Oathbreaker, Last Hope of the Breaking Storm               $50.76  \n",
       "145     Fiery Glass Crusader                                       $41.22  \n",
       "108     Extraction, Quickblade Of Trembling Hands                  $31.77  \n",
       "82      Nirvana                                                    $44.10  \n",
       "19      Pursuit, Cudgel of Necromancy                               $8.16  "
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Purchase Count</th>\n",
       "      <th>Item Price</th>\n",
       "      <th>Total Purchase Value</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Item ID</th>\n",
       "      <th>Item Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>178</th>\n",
       "      <th>Oathbreaker, Last Hope of the Breaking Storm</th>\n",
       "      <td>12</td>\n",
       "      <td>4.23</td>\n",
       "      <td>50.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <th>Nirvana</th>\n",
       "      <td>9</td>\n",
       "      <td>4.90</td>\n",
       "      <td>44.10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>145</th>\n",
       "      <th>Fiery Glass Crusader</th>\n",
       "      <td>9</td>\n",
       "      <td>4.58</td>\n",
       "      <td>41.22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>92</th>\n",
       "      <th>Final Critic</th>\n",
       "      <td>8</td>\n",
       "      <td>4.88</td>\n",
       "      <td>39.04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>103</th>\n",
       "      <th>Singed Scalpel</th>\n",
       "      <td>8</td>\n",
       "      <td>4.35</td>\n",
       "      <td>34.80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>59</th>\n",
       "      <th>Lightning, Etcher of the King</th>\n",
       "      <td>8</td>\n",
       "      <td>4.23</td>\n",
       "      <td>33.84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>108</th>\n",
       "      <th>Extraction, Quickblade Of Trembling Hands</th>\n",
       "      <td>9</td>\n",
       "      <td>3.53</td>\n",
       "      <td>31.77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>78</th>\n",
       "      <th>Glimmer, Ender of the Moon</th>\n",
       "      <td>7</td>\n",
       "      <td>4.40</td>\n",
       "      <td>30.80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>72</th>\n",
       "      <th>Winter's Bite</th>\n",
       "      <td>8</td>\n",
       "      <td>3.77</td>\n",
       "      <td>30.16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>60</th>\n",
       "      <th>Wolf</th>\n",
       "      <td>8</td>\n",
       "      <td>3.54</td>\n",
       "      <td>28.32</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                      Purchase Count  \\\n",
       "Item ID Item Name                                                      \n",
       "178     Oathbreaker, Last Hope of the Breaking Storm              12   \n",
       "82      Nirvana                                                    9   \n",
       "145     Fiery Glass Crusader                                       9   \n",
       "92      Final Critic                                               8   \n",
       "103     Singed Scalpel                                             8   \n",
       "59      Lightning, Etcher of the King                              8   \n",
       "108     Extraction, Quickblade Of Trembling Hands                  9   \n",
       "78      Glimmer, Ender of the Moon                                 7   \n",
       "72      Winter's Bite                                              8   \n",
       "60      Wolf                                                       8   \n",
       "\n",
       "                                                      Item Price  \\\n",
       "Item ID Item Name                                                  \n",
       "178     Oathbreaker, Last Hope of the Breaking Storm        4.23   \n",
       "82      Nirvana                                             4.90   \n",
       "145     Fiery Glass Crusader                                4.58   \n",
       "92      Final Critic                                        4.88   \n",
       "103     Singed Scalpel                                      4.35   \n",
       "59      Lightning, Etcher of the King                       4.23   \n",
       "108     Extraction, Quickblade Of Trembling Hands           3.53   \n",
       "78      Glimmer, Ender of the Moon                          4.40   \n",
       "72      Winter's Bite                                       3.77   \n",
       "60      Wolf                                                3.54   \n",
       "\n",
       "                                                      Total Purchase Value  \n",
       "Item ID Item Name                                                           \n",
       "178     Oathbreaker, Last Hope of the Breaking Storm                 50.76  \n",
       "82      Nirvana                                                      44.10  \n",
       "145     Fiery Glass Crusader                                         41.22  \n",
       "92      Final Critic                                                 39.04  \n",
       "103     Singed Scalpel                                               34.80  \n",
       "59      Lightning, Etcher of the King                                33.84  \n",
       "108     Extraction, Quickblade Of Trembling Hands                    31.77  \n",
       "78      Glimmer, Ender of the Moon                                   30.80  \n",
       "72      Winter's Bite                                                30.16  \n",
       "60      Wolf                                                         28.32  "
      ]
     },
     "execution_count": 102,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "\n",
    "df_top_profit = pd.DataFrame(Top_purchase_item)\n",
    "\n",
    "df_top_profit.columns.tolist()\n",
    "# df_topitem2 = df_topitem.groupby(['Item ID', 'Item Name']).agg({ 'Item ID': \"count\", 'Price': \"sum\"})\n",
    "# df_topitem2.head(10)\n",
    "# new_group = df_topspenders.groupby(['SN']).agg({ 'SN': \"count\", 'Price': \"sum\"})\n",
    "new_group2 = df_top_profit.sort_values(by='Total Purchase Value', ascending=False)\n",
    "# new_group2 = new_group2.reset_index(drop=True)\n",
    "#new_group2.columns=['Purchase Count', 'Total Purchase Value']\n",
    "#new_group2['Item Price'] =round((new_group2['Total Purchase Value']/new_group2['Purchase Count']),2)\n",
    "# new_group2 = new_group2.reset_index(drop=FalsTo\n",
    "#new_group2 = pd.DataFrame(new_group2)\n",
    "#new_group2 = new_group2[['Purchase Count', 'Item Price', 'Total Purchase Value']]\n",
    "new_group2.head(10)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Most Profitable Items"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Sort the above table by total purchase value in descending order\n",
    "\n",
    "\n",
    "* Optional: give the displayed data cleaner formatting\n",
    "\n",
    "\n",
    "* Display a preview of the data frame\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Purchase Count</th>\n",
       "      <th>Item Price</th>\n",
       "      <th>Total Purchase Value</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Item ID</th>\n",
       "      <th>Item Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>178</th>\n",
       "      <th>Oathbreaker, Last Hope of the Breaking Storm</th>\n",
       "      <td>12</td>\n",
       "      <td>$4.23</td>\n",
       "      <td>$50.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <th>Nirvana</th>\n",
       "      <td>9</td>\n",
       "      <td>$4.90</td>\n",
       "      <td>$44.10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>145</th>\n",
       "      <th>Fiery Glass Crusader</th>\n",
       "      <td>9</td>\n",
       "      <td>$4.58</td>\n",
       "      <td>$41.22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>92</th>\n",
       "      <th>Final Critic</th>\n",
       "      <td>8</td>\n",
       "      <td>$4.88</td>\n",
       "      <td>$39.04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>103</th>\n",
       "      <th>Singed Scalpel</th>\n",
       "      <td>8</td>\n",
       "      <td>$4.35</td>\n",
       "      <td>$34.80</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                     Purchase Count  \\\n",
       "Item ID Item Name                                                     \n",
       "178     Oathbreaker, Last Hope of the Breaking Storm             12   \n",
       "82      Nirvana                                                   9   \n",
       "145     Fiery Glass Crusader                                      9   \n",
       "92      Final Critic                                              8   \n",
       "103     Singed Scalpel                                            8   \n",
       "\n",
       "                                                     Item Price  \\\n",
       "Item ID Item Name                                                 \n",
       "178     Oathbreaker, Last Hope of the Breaking Storm      $4.23   \n",
       "82      Nirvana                                           $4.90   \n",
       "145     Fiery Glass Crusader                              $4.58   \n",
       "92      Final Critic                                      $4.88   \n",
       "103     Singed Scalpel                                    $4.35   \n",
       "\n",
       "                                                     Total Purchase Value  \n",
       "Item ID Item Name                                                          \n",
       "178     Oathbreaker, Last Hope of the Breaking Storm               $50.76  \n",
       "82      Nirvana                                                    $44.10  \n",
       "145     Fiery Glass Crusader                                       $41.22  \n",
       "92      Final Critic                                               $39.04  \n",
       "103     Singed Scalpel                                             $34.80  "
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernel_info": {
   "name": "python3"
  },
  "kernelspec": {
   "display_name": "Python [default]",
   "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.5"
  },
  "nteract": {
   "version": "0.2.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
