{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "8081b262",
   "metadata": {},
   "source": [
    "# Pandas Basics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "bcc864be",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.3.1\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "print(pd.__version__)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f3e44b5e",
   "metadata": {},
   "source": [
    "## Panda Series"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "587e27ee",
   "metadata": {},
   "source": [
    "### A Pandas Series is like a column in a table.\n",
    "\n",
    "*It is a one-dimensional array holding data of any type.*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "568a1fe2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0    1\n",
      "1    7\n",
      "2    2\n",
      "dtype: int64\n"
     ]
    }
   ],
   "source": [
    "a = [1, 7, 2]\n",
    "\n",
    "myvar = pd.Series(a)\n",
    "\n",
    "print(myvar)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "54d42adc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7\n"
     ]
    }
   ],
   "source": [
    "print(myvar[1])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9d594aa3",
   "metadata": {},
   "source": [
    "- **With the index argument, you can name your own labels.**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "ef459cf1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "x    1\n",
      "y    7\n",
      "z    2\n",
      "dtype: int64\n"
     ]
    }
   ],
   "source": [
    "a = [1, 7, 2]\n",
    "\n",
    "myvar = pd.Series(a, index = [\"x\", \"y\", \"z\"])\n",
    "\n",
    "print(myvar)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "24e53440",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7\n"
     ]
    }
   ],
   "source": [
    "print(myvar[\"y\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cf0b2c2d",
   "metadata": {},
   "source": [
    "- **You can also use a key/value object, like a dictionary, when creating a Series.**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "d4129e14",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "day1    420\n",
      "day2    380\n",
      "day3    390\n",
      "dtype: int64\n"
     ]
    }
   ],
   "source": [
    "calories = {\"day1\": 420, \"day2\": 380, \"day3\": 390}\n",
    "\n",
    "myvar = pd.Series(calories)\n",
    "\n",
    "print(myvar)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ccbb94ff",
   "metadata": {},
   "source": [
    "****The keys of the dictionary become the labels.*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "f14d80fb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "420\n"
     ]
    }
   ],
   "source": [
    "print(myvar['day1'])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c5dfcd35",
   "metadata": {},
   "source": [
    "- **To select only some of the items in the dictionary, use the index argument and specify only the items you want to include in the Series.**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "acbdd259",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "day1    420\n",
      "day2    380\n",
      "dtype: int64\n"
     ]
    }
   ],
   "source": [
    "calories = {\"day1\": 420, \"day2\": 380, \"day3\": 390}\n",
    "\n",
    "myvar = pd.Series(calories, index = [\"day1\", \"day2\"])\n",
    "\n",
    "print(myvar)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "db5cf6fb",
   "metadata": {},
   "source": [
    "## Pandas Data Frame"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4bded964",
   "metadata": {},
   "source": [
    "### Data sets in Pandas are usually multi-dimensional tables, called DataFrames.\n",
    "\n",
    "*Series is like a column, a DataFrame is the whole table.*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "6d10de08",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   calories  duration\n",
      "0       420        50\n",
      "1       380        40\n",
      "2       390        45\n"
     ]
    }
   ],
   "source": [
    "data = {\n",
    "  \"calories\": [420, 380, 390],\n",
    "  \"duration\": [50, 40, 45]\n",
    "}\n",
    "\n",
    "df = pd.DataFrame(data)\n",
    "\n",
    "print(df)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ae0ff06c",
   "metadata": {},
   "source": [
    "### Locate Row\n",
    "\n",
    "*Pandas use the loc attribute to return one or more specified row(s)*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "53f2728a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "calories    420\n",
      "duration     50\n",
      "Name: 0, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "print(df.loc[0])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2238aec9",
   "metadata": {},
   "source": [
    "****This example returns a Pandas Series.*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "f75440fe",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   calories  duration\n",
      "0       420        50\n",
      "1       380        40\n"
     ]
    }
   ],
   "source": [
    "print(df.loc[[0, 1]])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dfd0ae45",
   "metadata": {},
   "source": [
    "**** When using [ ], the result is a Pandas DataFrame.*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "38a2e9fb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "      calories  duration\n",
      "day1       420        50\n",
      "day2       380        40\n",
      "day3       390        45\n"
     ]
    }
   ],
   "source": [
    "data = {\n",
    "  \"calories\": [420, 380, 390],\n",
    "  \"duration\": [50, 40, 45]\n",
    "}\n",
    "\n",
    "df = pd.DataFrame(data, index = [\"day1\", \"day2\", \"day3\"])\n",
    "\n",
    "print(df) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "1c5cdb1c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "calories    380\n",
      "duration     40\n",
      "Name: day2, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "print(df.loc[\"day2\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cf478fb2",
   "metadata": {},
   "source": [
    "### Load Files Into a DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "b6ae12e7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "       #                   Name   Type 1  Type 2  HP  Attack  Defense  \\\n",
      "0      1              Bulbasaur    Grass  Poison  45      49       49   \n",
      "1      2                Ivysaur    Grass  Poison  60      62       63   \n",
      "2      3               Venusaur    Grass  Poison  80      82       83   \n",
      "3      3  VenusaurMega Venusaur    Grass  Poison  80     100      123   \n",
      "4      4             Charmander     Fire     NaN  39      52       43   \n",
      "..   ...                    ...      ...     ...  ..     ...      ...   \n",
      "795  719                Diancie     Rock   Fairy  50     100      150   \n",
      "796  719    DiancieMega Diancie     Rock   Fairy  50     160      110   \n",
      "797  720    HoopaHoopa Confined  Psychic   Ghost  80     110       60   \n",
      "798  720     HoopaHoopa Unbound  Psychic    Dark  80     160       60   \n",
      "799  721              Volcanion     Fire   Water  80     110      120   \n",
      "\n",
      "     Sp. Atk  Sp. Def  Speed  Generation  Legendary  \n",
      "0         65       65     45           1      False  \n",
      "1         80       80     60           1      False  \n",
      "2        100      100     80           1      False  \n",
      "3        122      120     80           1      False  \n",
      "4         60       50     65           1      False  \n",
      "..       ...      ...    ...         ...        ...  \n",
      "795      100      150     50           6       True  \n",
      "796      160      110    110           6       True  \n",
      "797      150      130     70           6       True  \n",
      "798      170      130     80           6       True  \n",
      "799      130       90     70           6       True  \n",
      "\n",
      "[800 rows x 12 columns]\n"
     ]
    }
   ],
   "source": [
    "df = pd.read_csv('pokemon_data.csv')\n",
    "\n",
    "print(df) "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.9.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}