{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Import Modules\n",
    "The dwarves!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "import digger, gunner, scout \n",
    "import pandas as pd\n",
    "import numpy as np\n"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Pre-Processing\n",
    "This segment is a demonstration on how the data cleaning process on the acquired datasets was handled"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Game Datasets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   Rank                           Name     Genre ESRB_Rating Platform  \\\n",
      "0   1.0                     Wii Sports    Sports           E      Wii   \n",
      "1   2.0              Super Mario Bros.  Platform         NaN      NES   \n",
      "2   3.0                 Mario Kart Wii    Racing           E      Wii   \n",
      "3   4.0  PlayerUnknown's Battlegrounds   Shooter         NaN       PC   \n",
      "4   5.0              Wii Sports Resort    Sports           E      Wii   \n",
      "\n",
      "          Publisher         Developer  Critic_Score  User_Score  \\\n",
      "0          Nintendo      Nintendo EAD           7.7         NaN   \n",
      "1          Nintendo      Nintendo EAD          10.0         NaN   \n",
      "2          Nintendo      Nintendo EAD           8.2         9.1   \n",
      "3  PUBG Corporation  PUBG Corporation           NaN         NaN   \n",
      "4          Nintendo      Nintendo EAD           8.0         8.8   \n",
      "\n",
      "   Total_Shipped  Global_Sales  NA_Sales  PAL_Sales  JP_Sales  Other_Sales  \\\n",
      "0          82.86           NaN       NaN        NaN       NaN          NaN   \n",
      "1          40.24           NaN       NaN        NaN       NaN          NaN   \n",
      "2          37.14           NaN       NaN        NaN       NaN          NaN   \n",
      "3          36.60           NaN       NaN        NaN       NaN          NaN   \n",
      "4          33.09           NaN       NaN        NaN       NaN          NaN   \n",
      "\n",
      "     Year Console Review  Score GameName  \n",
      "0  2006.0     NaN    NaN    NaN      NaN  \n",
      "1  1985.0     NaN    NaN    NaN      NaN  \n",
      "2  2008.0     NaN    NaN    NaN      NaN  \n",
      "3  2017.0     NaN    NaN    NaN      NaN  \n",
      "4  2009.0     NaN    NaN    NaN      NaN  \n"
     ]
    }
   ],
   "source": [
    "\n",
    "games_review = pd.read_csv(\"../datasets/videogames/Games.xls\")\n",
    "games_sales = pd.read_csv(\"../datasets/videogames/vgsales-12-4-2019-short.csv\")\n",
    "\n",
    "games_review_phase1 = digger.slice_column(games_review, \"GameName\", \"Review\")\n",
    "games_review_final = digger.slice_column(games_review, \"GameName\", \"(Import)\")\n",
    "\n",
    "games_merged_dat = digger.write_joined_df(games_sales, games_review_final)\n",
    "\n",
    "# Acquisition of Merged dataset\n",
    "print(games_merged_dat.head(5))"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Crime Datasets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "crime_CA = pd.read_excel(\"../datasets/crime/clean_crime_canada_dataset.xlsx\")\n",
    "\n",
    "crime_US = pd.read_csv(\"../datasets/crime/report.csv\")\n",
    "\n",
    "NA_col_list = [\n",
    "    \"JP_Sales\",\n",
    "    \"Other_Sales\",\n",
    "    \"Global_Sales\",\n",
    "    \"GameName\",\n",
    "    \"Review\",\n",
    "    \"Console\",\n",
    "    \"Score\",\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "report_year            2828\n",
      "agency_code            2828\n",
      "agency_jurisdiction    2828\n",
      "population             2828\n",
      "violent_crimes         2828\n",
      "homicides              2828\n",
      "rapes                  2828\n",
      "assaults               2828\n",
      "robberies              2828\n",
      "months_reported        2828\n",
      "crimes_percapita       2828\n",
      "homicides_percapita    2828\n",
      "rapes_percapita        2828\n",
      "assaults_percapita     2828\n",
      "robberies_percapita    2828\n",
      "dtype: int64\n",
      "year             4664\n",
      "location         4664\n",
      "type_of_crime    4664\n",
      "incidents        4664\n",
      "rate_per_100k    4664\n",
      "dtype: int64\n"
     ]
    }
   ],
   "source": [
    "\n",
    "print(crime_US.isnull().count())\n",
    "print(crime_CA.isnull().count())\n",
    "\n",
    "year_interval = gunner.year_interval(crime_US, crime_CA, \"report_year\", \"year\")\n",
    "\n",
    "year_max = year_interval[0]\n",
    "year_min = year_interval[1]\n",
    "\n",
    "crime_intersect = gunner.intersect_by_year(crime_US, crime_CA, \"report_year\", \"year\")\n",
    "\n",
    "crime_US_intersect = crime_intersect[0]\n",
    "crime_CA_intersect = crime_intersect[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "games_merged_dat = gunner.drop_kick(NA_col_list, games_merged_dat)\n",
    "games_merged_dat.to_csv(\"../datasets/videogames/games_merged.csv\", index=False)\n",
    "\n",
    "sale_tri_split = gunner.trisect_by_year(games_merged_dat, \"Year\", year_interval)\n",
    "\n",
    "games_sales_split_pre = sale_tri_split[0]\n",
    "games_sales_split_dur = sale_tri_split[1]\n",
    "games_sales_split_pos = sale_tri_split[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Acquired Datasets:\n",
      "\n",
      "    Rank                                Name         Genre ESRB_Rating  \\\n",
      "1    2.0                   Super Mario Bros.      Platform         NaN   \n",
      "5    6.0  Pokemon Red / Green / Blue Version  Role-Playing           E   \n",
      "7    8.0                              Tetris        Puzzle           E   \n",
      "10  11.0                           Duck Hunt       Shooter         NaN   \n",
      "18  19.0                   Super Mario World      Platform           E   \n",
      "\n",
      "   Platform Publisher              Developer  Critic_Score  User_Score  \\\n",
      "1       NES  Nintendo           Nintendo EAD          10.0         NaN   \n",
      "5        GB  Nintendo             Game Freak           9.4         NaN   \n",
      "7        GB  Nintendo  Bullet Proof Software           NaN         NaN   \n",
      "10      NES  Nintendo          Nintendo R&D1           NaN         NaN   \n",
      "18     SNES  Nintendo           Nintendo EAD           8.5         NaN   \n",
      "\n",
      "    Total_Shipped  NA_Sales  PAL_Sales    Year  \n",
      "1           40.24       NaN        NaN  1985.0  \n",
      "5           31.38       NaN        NaN  1998.0  \n",
      "7           30.26       NaN        NaN  1989.0  \n",
      "10          28.31       NaN        NaN  1985.0  \n",
      "18          20.61       NaN        NaN  1991.0      Rank                       Name     Genre ESRB_Rating Platform Publisher  \\\n",
      "0   1.0                 Wii Sports    Sports           E      Wii  Nintendo   \n",
      "2   3.0             Mario Kart Wii    Racing           E      Wii  Nintendo   \n",
      "4   5.0          Wii Sports Resort    Sports           E      Wii  Nintendo   \n",
      "6   7.0      New Super Mario Bros.  Platform           E       DS  Nintendo   \n",
      "8   9.0  New Super Mario Bros. Wii  Platform           E      Wii  Nintendo   \n",
      "\n",
      "      Developer  Critic_Score  User_Score  Total_Shipped  NA_Sales  PAL_Sales  \\\n",
      "0  Nintendo EAD           7.7         NaN          82.86       NaN        NaN   \n",
      "2  Nintendo EAD           8.2         9.1          37.14       NaN        NaN   \n",
      "4  Nintendo EAD           8.0         8.8          33.09       NaN        NaN   \n",
      "6  Nintendo EAD           9.1         8.1          30.80       NaN        NaN   \n",
      "8  Nintendo EAD           8.6         9.2          30.22       NaN        NaN   \n",
      "\n",
      "     Year  \n",
      "0  2006.0  \n",
      "2  2008.0  \n",
      "4  2009.0  \n",
      "6  2006.0  \n",
      "8  2009.0       Rank                           Name             Genre ESRB_Rating  \\\n",
      "3    4.0  PlayerUnknown's Battlegrounds           Shooter         NaN   \n",
      "31  32.0               Pokemon Sun/Moon      Role-Playing           E   \n",
      "35  36.0            Mario Kart 8 Deluxe            Racing           E   \n",
      "45  46.0          Red Dead Redemption 2  Action-Adventure           M   \n",
      "48  49.0            Super Mario Odyssey          Platform         E10   \n",
      "\n",
      "   Platform         Publisher         Developer  Critic_Score  User_Score  \\\n",
      "3        PC  PUBG Corporation  PUBG Corporation           NaN         NaN   \n",
      "31      3DS          Nintendo        Game Freak           9.0         NaN   \n",
      "35       NS          Nintendo      Nintendo EPD           9.3         NaN   \n",
      "45      PS4    Rockstar Games    Rockstar Games           9.8         NaN   \n",
      "48       NS          Nintendo      Nintendo EPD           9.9         NaN   \n",
      "\n",
      "    Total_Shipped  NA_Sales  PAL_Sales    Year  \n",
      "3           36.60       NaN        NaN  2017.0  \n",
      "31          16.14       NaN        NaN  2016.0  \n",
      "35          15.02       NaN        NaN  2017.0  \n",
      "45            NaN      5.26       6.21  2018.0  \n",
      "48          13.76       NaN        NaN  2017.0  \n",
      "Dataset Info:\n",
      "\n",
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 12445 entries, 1 to 55771\n",
      "Data columns (total 13 columns):\n",
      " #   Column         Non-Null Count  Dtype  \n",
      "---  ------         --------------  -----  \n",
      " 0   Rank           12445 non-null  float64\n",
      " 1   Name           12445 non-null  object \n",
      " 2   Genre          12445 non-null  object \n",
      " 3   ESRB_Rating    2704 non-null   object \n",
      " 4   Platform       12445 non-null  object \n",
      " 5   Publisher      12445 non-null  object \n",
      " 6   Developer      12444 non-null  object \n",
      " 7   Critic_Score   493 non-null    float64\n",
      " 8   User_Score     16 non-null     float64\n",
      " 9   Total_Shipped  243 non-null    float64\n",
      " 10  NA_Sales       1047 non-null   float64\n",
      " 11  PAL_Sales      1086 non-null   float64\n",
      " 12  Year           12445 non-null  float64\n",
      "dtypes: float64(7), object(6)\n",
      "memory usage: 1.3+ MB\n",
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 37102 entries, 0 to 55763\n",
      "Data columns (total 13 columns):\n",
      " #   Column         Non-Null Count  Dtype  \n",
      "---  ------         --------------  -----  \n",
      " 0   Rank           37102 non-null  float64\n",
      " 1   Name           37102 non-null  object \n",
      " 2   Genre          37102 non-null  object \n",
      " 3   ESRB_Rating    18606 non-null  object \n",
      " 4   Platform       37102 non-null  object \n",
      " 5   Publisher      37102 non-null  object \n",
      " 6   Developer      37089 non-null  object \n",
      " 7   Critic_Score   5709 non-null   float64\n",
      " 8   User_Score     212 non-null    float64\n",
      " 9   Total_Shipped  1284 non-null   float64\n",
      " 10  NA_Sales       10610 non-null  float64\n",
      " 11  PAL_Sales      11150 non-null  float64\n",
      " 12  Year           37102 non-null  float64\n",
      "dtypes: float64(7), object(6)\n",
      "memory usage: 4.0+ MB\n",
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 5266 entries, 3 to 55790\n",
      "Data columns (total 13 columns):\n",
      " #   Column         Non-Null Count  Dtype  \n",
      "---  ------         --------------  -----  \n",
      " 0   Rank           5266 non-null   float64\n",
      " 1   Name           5266 non-null   object \n",
      " 2   Genre          5266 non-null   object \n",
      " 3   ESRB_Rating    2213 non-null   object \n",
      " 4   Platform       5266 non-null   object \n",
      " 5   Publisher      5266 non-null   object \n",
      " 6   Developer      5266 non-null   object \n",
      " 7   Critic_Score   330 non-null    float64\n",
      " 8   User_Score     100 non-null    float64\n",
      " 9   Total_Shipped  300 non-null    float64\n",
      " 10  NA_Sales       1301 non-null   float64\n",
      " 11  PAL_Sales      929 non-null    float64\n",
      " 12  Year           5266 non-null   float64\n",
      "dtypes: float64(7), object(6)\n",
      "memory usage: 576.0+ KB\n",
      "Dataset Info:\n",
      "\n",
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 12445 entries, 1 to 55771\n",
      "Data columns (total 13 columns):\n",
      " #   Column         Non-Null Count  Dtype  \n",
      "---  ------         --------------  -----  \n",
      " 0   Rank           12445 non-null  float64\n",
      " 1   Name           12445 non-null  object \n",
      " 2   Genre          12445 non-null  object \n",
      " 3   ESRB_Rating    2704 non-null   object \n",
      " 4   Platform       12445 non-null  object \n",
      " 5   Publisher      12445 non-null  object \n",
      " 6   Developer      12444 non-null  object \n",
      " 7   Critic_Score   493 non-null    float64\n",
      " 8   User_Score     16 non-null     float64\n",
      " 9   Total_Shipped  243 non-null    float64\n",
      " 10  NA_Sales       1047 non-null   float64\n",
      " 11  PAL_Sales      1086 non-null   float64\n",
      " 12  Year           12445 non-null  float64\n",
      "dtypes: float64(7), object(6)\n",
      "memory usage: 1.3+ MB\n",
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 37102 entries, 0 to 55763\n",
      "Data columns (total 13 columns):\n",
      " #   Column         Non-Null Count  Dtype  \n",
      "---  ------         --------------  -----  \n",
      " 0   Rank           37102 non-null  float64\n",
      " 1   Name           37102 non-null  object \n",
      " 2   Genre          37102 non-null  object \n",
      " 3   ESRB_Rating    18606 non-null  object \n",
      " 4   Platform       37102 non-null  object \n",
      " 5   Publisher      37102 non-null  object \n",
      " 6   Developer      37089 non-null  object \n",
      " 7   Critic_Score   5709 non-null   float64\n",
      " 8   User_Score     212 non-null    float64\n",
      " 9   Total_Shipped  1284 non-null   float64\n",
      " 10  NA_Sales       10610 non-null  float64\n",
      " 11  PAL_Sales      11150 non-null  float64\n",
      " 12  Year           37102 non-null  float64\n",
      "dtypes: float64(7), object(6)\n",
      "memory usage: 4.0+ MB\n",
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 5266 entries, 3 to 55790\n",
      "Data columns (total 13 columns):\n",
      " #   Column         Non-Null Count  Dtype  \n",
      "---  ------         --------------  -----  \n",
      " 0   Rank           5266 non-null   float64\n",
      " 1   Name           5266 non-null   object \n",
      " 2   Genre          5266 non-null   object \n",
      " 3   ESRB_Rating    2213 non-null   object \n",
      " 4   Platform       5266 non-null   object \n",
      " 5   Publisher      5266 non-null   object \n",
      " 6   Developer      5266 non-null   object \n",
      " 7   Critic_Score   330 non-null    float64\n",
      " 8   User_Score     100 non-null    float64\n",
      " 9   Total_Shipped  300 non-null    float64\n",
      " 10  NA_Sales       1301 non-null   float64\n",
      " 11  PAL_Sales      929 non-null    float64\n",
      " 12  Year           5266 non-null   float64\n",
      "dtypes: float64(7), object(6)\n",
      "memory usage: 576.0+ KB\n",
      "Yer forsaken Statistical Description:\n",
      "                Rank  Critic_Score  User_Score  Total_Shipped      NA_Sales  \\\n",
      "count  37102.000000   5709.000000  212.000000    1284.000000  10610.000000   \n",
      "mean   25036.476282      7.170047    8.369811       1.786597      0.273487   \n",
      "std    15243.705990      1.433885    1.254125       4.209405      0.512590   \n",
      "min        1.000000      1.000000    2.000000       0.030000      0.000000   \n",
      "25%    11755.250000      6.400000    8.000000       0.200000      0.050000   \n",
      "50%    23875.500000      7.400000    8.600000       0.545000      0.120000   \n",
      "75%    38152.750000      8.200000    9.200000       1.680000      0.290000   \n",
      "max    55764.000000     10.000000   10.000000      82.860000      9.760000   \n",
      "\n",
      "          PAL_Sales          Year  \n",
      "count  11150.000000  37102.000000  \n",
      "mean       0.149162   2008.141852  \n",
      "std        0.380365      4.135877  \n",
      "min        0.000000   2000.000000  \n",
      "25%        0.010000   2005.000000  \n",
      "50%        0.040000   2009.000000  \n",
      "75%        0.140000   2011.000000  \n",
      "max        9.850000   2015.000000  \n",
      "    Rank                                Name         Genre ESRB_Rating  \\\n",
      "1    2.0                   Super Mario Bros.      Platform         NaN   \n",
      "5    6.0  Pokemon Red / Green / Blue Version  Role-Playing           E   \n",
      "7    8.0                              Tetris        Puzzle           E   \n",
      "10  11.0                           Duck Hunt       Shooter         NaN   \n",
      "18  19.0                   Super Mario World      Platform           E   \n",
      "\n",
      "   Platform Publisher              Developer  Critic_Score  User_Score  \\\n",
      "1       NES  Nintendo           Nintendo EAD          10.0         NaN   \n",
      "5        GB  Nintendo             Game Freak           9.4         NaN   \n",
      "7        GB  Nintendo  Bullet Proof Software           NaN         NaN   \n",
      "10      NES  Nintendo          Nintendo R&D1           NaN         NaN   \n",
      "18     SNES  Nintendo           Nintendo EAD           8.5         NaN   \n",
      "\n",
      "    Total_Shipped  NA_Sales  PAL_Sales    Year  \n",
      "1           40.24       NaN        NaN  1985.0  \n",
      "5           31.38       NaN        NaN  1998.0  \n",
      "7           30.26       NaN        NaN  1989.0  \n",
      "10          28.31       NaN        NaN  1985.0  \n",
      "18          20.61       NaN        NaN  1991.0      Rank                       Name     Genre ESRB_Rating Platform Publisher  \\\n",
      "0   1.0                 Wii Sports    Sports           E      Wii  Nintendo   \n",
      "2   3.0             Mario Kart Wii    Racing           E      Wii  Nintendo   \n",
      "4   5.0          Wii Sports Resort    Sports           E      Wii  Nintendo   \n",
      "6   7.0      New Super Mario Bros.  Platform           E       DS  Nintendo   \n",
      "8   9.0  New Super Mario Bros. Wii  Platform           E      Wii  Nintendo   \n",
      "\n",
      "      Developer  Critic_Score  User_Score  Total_Shipped  NA_Sales  PAL_Sales  \\\n",
      "0  Nintendo EAD           7.7         NaN          82.86       NaN        NaN   \n",
      "2  Nintendo EAD           8.2         9.1          37.14       NaN        NaN   \n",
      "4  Nintendo EAD           8.0         8.8          33.09       NaN        NaN   \n",
      "6  Nintendo EAD           9.1         8.1          30.80       NaN        NaN   \n",
      "8  Nintendo EAD           8.6         9.2          30.22       NaN        NaN   \n",
      "\n",
      "     Year  \n",
      "0  2006.0  \n",
      "2  2008.0  \n",
      "4  2009.0  \n",
      "6  2006.0  \n",
      "8  2009.0       Rank                           Name             Genre ESRB_Rating  \\\n",
      "3    4.0  PlayerUnknown's Battlegrounds           Shooter         NaN   \n",
      "31  32.0               Pokemon Sun/Moon      Role-Playing           E   \n",
      "35  36.0            Mario Kart 8 Deluxe            Racing           E   \n",
      "45  46.0          Red Dead Redemption 2  Action-Adventure           M   \n",
      "48  49.0            Super Mario Odyssey          Platform         E10   \n",
      "\n",
      "   Platform         Publisher         Developer  Critic_Score  User_Score  \\\n",
      "3        PC  PUBG Corporation  PUBG Corporation           NaN         NaN   \n",
      "31      3DS          Nintendo        Game Freak           9.0         NaN   \n",
      "35       NS          Nintendo      Nintendo EPD           9.3         NaN   \n",
      "45      PS4    Rockstar Games    Rockstar Games           9.8         NaN   \n",
      "48       NS          Nintendo      Nintendo EPD           9.9         NaN   \n",
      "\n",
      "    Total_Shipped  NA_Sales  PAL_Sales    Year  \n",
      "3           36.60       NaN        NaN  2017.0  \n",
      "31          16.14       NaN        NaN  2016.0  \n",
      "35          15.02       NaN        NaN  2017.0  \n",
      "45            NaN      5.26       6.21  2018.0  \n",
      "48          13.76       NaN        NaN  2017.0  \n"
     ]
    }
   ],
   "source": [
    "\n",
    "print(\"Acquired Datasets:\\n\")\n",
    "print(sale_tri_split[0].head(5), sale_tri_split[1].head(5), sale_tri_split[2].head(5))\n",
    "\n",
    "print(\"Dataset Info:\\n\")\n",
    "sale_tri_split[0].info()\n",
    "sale_tri_split[1].info()\n",
    "sale_tri_split[2].info()\n",
    "\n",
    "\n",
    "print(\"Dataset Info:\\n\")\n",
    "games_sales_split_pre.info()\n",
    "games_sales_split_dur.info()\n",
    "games_sales_split_pos.info()\n",
    "\n",
    "print(\"Yer forsaken Statistical Description:\\n\", games_sales_split_dur.describe())\n",
    "\n",
    "print(\n",
    "    games_sales_split_pre.head(5),\n",
    "    games_sales_split_dur.head(5),\n",
    "    games_sales_split_pos.head(5),\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\hellom\\AppData\\Local\\Temp\\ipykernel_16036\\2254464593.py:4: DtypeWarning: Columns (1,2,3,4,5,6) have mixed types. Specify dtype option on import or set low_memory=False.\n",
      "  gammas = pd.read_csv(\"../datasets/videogames/games_merged.csv\")\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "min:  1.0  max:  10.0\n",
      "0    0.399535\n",
      "1    2.335800\n",
      "2    0.820462\n",
      "3    0.736276\n",
      "4    0.652091\n",
      "5    1.830687\n",
      "6    1.578131\n",
      "7    1.367667\n",
      "8    1.157204\n",
      "9    2.335800\n",
      "Name: Critic_Score_Norm, dtype: float64\n",
      "          Rank                                Name         Genre ESRB_Rating  \\\n",
      "23952  23953.0          Basha Card Game Collection          Misc         NaN   \n",
      "41756  41757.0                     Project Phoenix          Misc         NaN   \n",
      "29167  29168.0  Dragon Scroll: Yomigaerishi Maryuu  Role-Playing         NaN   \n",
      "10152  10153.0                    Super Sanctum TD      Strategy         NaN   \n",
      "27228  27229.0                       Crazy Pinball          Misc           E   \n",
      "\n",
      "      Platform          Publisher             Developer  Critic_Score  \\\n",
      "23952      PSN            Unknown               Quirkat      6.671642   \n",
      "41756      PSV            Unknown               Unknown      7.734043   \n",
      "29167      NES             Konami                Konami      8.147059   \n",
      "10152       PC            Unknown  Coffee Stain Studios      5.223529   \n",
      "27228     DSiW  DTP Entertainment  dtp entertainment AG      5.000000   \n",
      "\n",
      "       User_Score  Total_Shipped  NA_Sales  PAL_Sales    Year  \\\n",
      "23952    9.747917           0.03     0.000        0.0  2011.0   \n",
      "41756    9.000278           0.03     0.000        0.0  2020.0   \n",
      "29167    7.332155           0.03     0.000        0.0  1987.0   \n",
      "10152    7.558887           0.15     0.125        0.0  2007.0   \n",
      "27228    8.129441           0.03     0.000        0.0  2010.0   \n",
      "\n",
      "      bin_Critic_Score  bin_value  Critic_Score_Norm  \n",
      "23952              NaN        5.5          -0.466193  \n",
      "41756              NaN        8.5           0.428194  \n",
      "29167              NaN        8.5           0.775893  \n",
      "10152              NaN        5.5          -1.685293  \n",
      "27228              NaN        5.5          -1.873472  \n",
      "          |  Entry 1 | Entry 2 | Entry 3 | Entry 4 | Entry 5 |\n",
      "Entry  1  |  0.00000 | 9.61705 | 24.3835 | 4.94015 | 2.89729 |\n",
      "\n",
      "Entry  2  |  9.61705 | 0.00000 | 33.0465 | 13.8158 | 11.0694 |\n",
      "\n",
      "Entry  3  |  24.3835 | 33.0465 | 0.00000 | 20.5836 | 23.5703 |\n",
      "\n",
      "Entry  4  |  4.94015 | 13.8158 | 20.5836 | 0.00000 | 3.07261 |\n",
      "\n",
      "Entry  5  |  2.89729 | 11.0694 | 23.5703 | 3.07261 | 0.00000 |\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# Load merged gammas\n",
    "\n",
    "# Required to use binning for cleaning\n",
    "gammas = pd.read_csv(\"../datasets/videogames/games_merged.csv\")\n",
    "labels = [\"smol\", \"epik\", \"larg\"]\n",
    "gammas = digger.slam_dunk(gammas, \"Critic_Score\", labels=labels)\n",
    "\n",
    "# Also need to transform using Z-score (normal distr go brrrr lmao), or min-max\n",
    "# ah, scheiße\n",
    "gammas['Critic_Score_Norm'] = scout.scaling_zscore(gammas, 'Critic_Score')\n",
    "print(gammas['Critic_Score_Norm'].head(10))\n",
    "\n",
    "# Saving all into a file\n",
    "gammas.to_csv(\"../datasets/videogames/games_cleanish.csv\", index=False)\n",
    "\n",
    "# Need similarity and dissimialrity, scipy time\n",
    "# Selecting 5 random rows\n",
    "chosen_idx = np.random.choice(len(gammas), replace = False, size = 5)\n",
    "sample_rows = gammas.iloc[chosen_idx]\n",
    "print(sample_rows.head())\n",
    "\n",
    "scout.dissimilarity(sample_rows)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Plotting\n",
    "Engineer.py steps up to the job"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Importing and setting up environment"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "import pandas as pd\n",
    "from numpy import count_nonzero\n",
    "\n",
    "games_pre = games_sales_split_pre\n",
    "games_dur = games_sales_split_dur\n",
    "games_pos = games_sales_split_pos\n",
    "\n",
    "crime_US = crime_US_intersect\n",
    "crime_CA = crime_CA_intersect\n",
    "\n",
    "custom_params = {\"axes.spines.right\": False, \"axes.spines.top\": False}\n",
    "\n",
    "sns.set_theme(style = 'ticks', rc = custom_params)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Game Sales pre 2000s"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### General Plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\hellom\\AppData\\Local\\Temp\\ipykernel_16036\\2832375763.py:2: UserWarning: Ignoring `palette` because no `hue` variable has been assigned.\n",
      "  games_fig_pre = sns.histplot(data = games_pre, x = \"Year\", palette = sns.color_palette(\"flare\"), kde = True)\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 28276 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "plt.xticks(rotation = 90)\n",
    "games_fig_pre = sns.histplot(data = games_pre, x = \"Year\", palette = sns.color_palette(\"flare\"), kde = True)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### According to Genre"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 101192 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "plt.xticks(rotation = 90)\n",
    "games_fig2_pre = sns.histplot(data = games_pre, x = \"Year\", hue = \"Genre\", multiple = \"stack\", kde = True)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Game Sales during 2000s"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### General Plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 24776 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "plt.xticks(rotation = 90)\n",
    "games_fig_dur = sns.histplot(data = games_dur, x = \"Year\", kde = True)\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### According to Genre"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 110920 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "plt.xticks(rotation = 90)\n",
    "games_fig2_dur = sns.histplot(data = games_dur, x = \"Year\", hue = \"Genre\", multiple = \"stack\", kde = True)\n",
    "plt.show()"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Crime in Canada and US"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 14664 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "plt.xticks(rotation = 90)\n",
    "crime_CA_fig = sns.histplot(data = crime_CA, x = \"year\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 17444 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "plt.xticks(rotation = 90)\n",
    "crime_US_fig = sns.histplot(data = crime_US, x = \"report_year\")\n",
    "plt.show()"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Integrating violence crimes column into Game sales  \n",
    "- Note: multiplying sales by 1000 because they're reduced by default\n",
    "- to plot later"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\hellom\\AppData\\Local\\Temp\\ipykernel_16036\\2268265722.py:1: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  games_dur['Violent_US'] = crime_US['violent_crimes']\n",
      "C:\\Users\\hellom\\AppData\\Local\\Temp\\ipykernel_16036\\2268265722.py:2: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  games_dur['NA_Sales'] = games_dur['NA_Sales'].multiply(1000)\n"
     ]
    }
   ],
   "source": [
    "games_dur['Violent_US'] = crime_US['violent_crimes']\n",
    "games_dur['NA_Sales'] = games_dur['NA_Sales'].multiply(1000)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Plotting Sales against Crime with Relplot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 46356 characters]",
      "text/plain": [
       "<Figure size 500x500 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.xticks(rotation = 90)\n",
    "games_violence_US = sns.relplot(data = games_dur, x = 'NA_Sales', y = 'Violent_US')\n",
    "plt.close(1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Joined Plot and Histograms"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 40908 characters]",
      "text/plain": [
       "<Figure size 600x600 with 3 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.xticks(rotation = 90)\n",
    "games_crime_dur = sns.jointplot(data = games_dur, x = \"Year\", y = 'Violent_US')\n",
    "plt.close(1)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.0"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "c261aea317cc0286b3b3261fbba9abdec21eaa57589985bb7a274bf54d6cc0a7"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
