{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "8d43d901-0563-41aa-af00-334c5874e41f",
   "metadata": {},
   "source": [
    "### Slicing Quiz"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "7e176875-d8ed-4fb9-8506-c41825ae2c07",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 1, 2],\n",
       "       [3, 4, 5],\n",
       "       [6, 7, 8]])"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "a = np.arange(9).reshape(3,3)\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "2f6de83e-e9b2-4fde-bba3-96fede96a542",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2],\n",
       "       [4, 5]])"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# [[1,2],[4,5]]\n",
    "a[0:2,1:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "cbba4172-0690-425f-a22c-06084eacdbc9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2],\n",
       "       [4, 5]])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a[:2,1:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "64c5c287-7a02-44b0-9140-e59d7cfae559",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  2,  3,  4],\n",
       "       [ 5,  6,  7,  8,  9],\n",
       "       [10, 11, 12, 13, 14],\n",
       "       [15, 16, 17, 18, 19],\n",
       "       [20, 21, 22, 23, 24]])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b = np.arange(25).reshape(5,5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "b75eda4f-6139-4ffb-adf1-6beaafb121d4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[4, 3],\n",
       "       [9, 8]])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b[:2,-1:-3:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "d33ecf94-6a41-40a2-a7cd-48e3468ca276",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[3, 4],\n",
       "       [8, 9]])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b[:2,-2:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "445c9812-ff11-4eef-8eec-f2b67dc5d4ff",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2],\n",
       "       [4, 5]])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a[:2,-2:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "3c5390f9-28bf-42c8-b2d0-807fdd136774",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 1, 2],\n",
       "       [3, 4, 5],\n",
       "       [6, 7, 8]])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "6f407044-07e7-4888-affa-b51e4ee655b7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([6, 7, 8])"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# [6,7,8]\n",
    "a[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "9e590af6-dc7d-4aee-bd4a-365c6d80b065",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([6, 7, 8])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "dc0312ed-fe61-46ec-a046-bdc1cbc984dc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([6, 7, 8])"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a[2,:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "3474680e-4e3e-464e-aaa6-aa9ffb650167",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[6, 7, 8]])"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 2-D\n",
    "a[-1:,:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "6c1f5b2f-b855-4ada-9b40-b7ffb1636d9e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1, 3)"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a[-1:,:].shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "1e10c352-62c2-45f9-9590-6c9fd22722b9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 1, 2],\n",
       "       [3, 4, 5],\n",
       "       [6, 7, 8]])"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "814659bc-8eac-4995-8284-66d2fb58379d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.int64(6)"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a[2,0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "4ec69f0c-b5ab-4d13-b033-e418688149cd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[6]])"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a[-1:,0:1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "dc8f5d47-d518-48e2-a6e1-8c6552670045",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1, 1)"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a[-1:,0:1].shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "7dd250f8-7ab9-43d7-817a-3275637af9fe",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 1, 2],\n",
       "       [3, 4, 5],\n",
       "       [6, 7, 8]])"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "466917e5-c86f-48e8-b7e8-3a1e2c84e417",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 1],\n",
       "       [3, 4],\n",
       "       [6, 7]])"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a[:,:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "3628d82e-fc6e-4ceb-8223-c045d5bebfac",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 1, 2],\n",
       "       [3, 4, 5]])"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a[:][:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "db6dc9a8-4a09-46be-8d5e-0e4cd2ea7dd8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 1, 2],\n",
       "       [3, 4, 5],\n",
       "       [6, 7, 8]])"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a[:]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4d77953f-7c06-492e-bddc-ba9d8fb89d24",
   "metadata": {},
   "source": [
    "### Array Transformations"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "8e765e91-9c14-4c8f-9227-fa5b40c87460",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "c439325e-ab4e-48c2-aacf-0b8915db02f1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  2,  3],\n",
       "       [ 4,  5,  6,  7],\n",
       "       [ 8,  9, 10, 11],\n",
       "       [12, 13, 14, 15]])"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr = np.arange(16).reshape(4,4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "0a49d51d-0587-47d6-85a1-8a46d3c33780",
   "metadata": {},
   "outputs": [],
   "source": [
    "arr.resize(8,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "ec1038a8-4507-4e98-a96f-236616ab0c6d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1],\n",
       "       [ 2,  3],\n",
       "       [ 4,  5],\n",
       "       [ 6,  7],\n",
       "       [ 8,  9],\n",
       "       [10, 11],\n",
       "       [12, 13],\n",
       "       [14, 15]])"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "5e5ef011-3680-4d4d-98be-df90a8027516",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  2,  3],\n",
       "       [ 4,  5,  6,  7],\n",
       "       [ 8,  9, 10, 11],\n",
       "       [12, 13, 14, 15]])"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr = np.arange(16).reshape(4,4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "03df9838-f3dc-4f9d-b16c-84adc89ce230",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1],\n",
       "       [ 2,  3],\n",
       "       [ 4,  5],\n",
       "       [ 6,  7],\n",
       "       [ 8,  9],\n",
       "       [10, 11],\n",
       "       [12, 13],\n",
       "       [14, 15]])"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "barr = arr.reshape(8,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "07590e83-ee1f-4a34-9031-476bd961bb2b",
   "metadata": {},
   "outputs": [],
   "source": [
    "barr[:3,:] = -1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "1db1b1cf-a6e4-4527-b33a-ecc9d6d4b382",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-1, -1],\n",
       "       [-1, -1],\n",
       "       [-1, -1],\n",
       "       [ 6,  7],\n",
       "       [ 8,  9],\n",
       "       [10, 11],\n",
       "       [12, 13],\n",
       "       [14, 15]])"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "barr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "d0087056-e8cc-45e5-a8dc-adcf8bd8b16c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-1, -1, -1, -1],\n",
       "       [-1, -1,  6,  7],\n",
       "       [ 8,  9, 10, 11],\n",
       "       [12, 13, 14, 15]])"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "5e2ba7d6-a918-4494-8de0-f4dddd0db9c1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  2,  3],\n",
       "       [ 4,  5,  6,  7],\n",
       "       [ 8,  9, 10, 11],\n",
       "       [12, 13, 14, 15]])"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr = np.arange(16).reshape(4,4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "ff754871-e06b-4ab8-a126-965d40078c49",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15])"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "flat_arr = arr.flatten()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "4c108c87-4d51-4693-8a81-acf8eb63fc4f",
   "metadata": {},
   "outputs": [],
   "source": [
    "flat_arr[:4] = -1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "b7a1cbbc-5c34-4dc4-af76-24679f64d910",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([-1, -1, -1, -1,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15])"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "flat_arr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "eb57e5ff-39f2-4215-a00e-05ba4c15220b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  2,  3],\n",
       "       [ 4,  5,  6,  7],\n",
       "       [ 8,  9, 10, 11],\n",
       "       [12, 13, 14, 15]])"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "c40f8211-bec7-42c5-b1a0-ca72af9679be",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15])"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "carr = arr.ravel()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "b057693c-e223-4326-adee-96adff396ba1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([-1, -1, -1, -1,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15])"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "carr[:4] = -1\n",
    "carr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "3333ef87-5350-4675-9f20-59339f2ea2ae",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-1, -1, -1, -1],\n",
       "       [ 4,  5,  6,  7],\n",
       "       [ 8,  9, 10, 11],\n",
       "       [12, 13, 14, 15]])"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4ad5a073-61d5-466e-98ea-bb56872cd556",
   "metadata": {},
   "source": [
    "### Stacking"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "648fc2f5-b152-43e2-97ab-4e4a47b20dec",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([3, 4, 5])"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.arange(0,3)\n",
    "b = np.arange(3,6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "ca52c740-139a-4bc5-a6ea-0f1508febd11",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 1, 2])"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "54a833ac-2ad7-40d5-a388-35edfe38d26c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 1, 2],\n",
       "       [3, 4, 5]])"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.vstack([a,b])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "eb7e0aa4-6f05-4c03-9079-5cc6d010576e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 1, 2, 3, 4, 5])"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.hstack([a.T, b.T])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "5d4eb0bd-8db0-4cfe-af7e-3768c8e8fcc6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(3,)"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "350f9406-1ab5-4663-bfa7-c62615bf2c9a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 1, 2])"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "f959f38b-0cfd-4f97-ab48-7be7f1b67dc8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0],\n",
       "       [1],\n",
       "       [2]])"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.reshape(3,-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "241fc2cb-6dee-40b0-9a5a-d7d1142f59d1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 3],\n",
       "       [1, 4],\n",
       "       [2, 5]])"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.hstack([a.reshape(3,-1), b.reshape(3,-1)])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "84efd530-17a7-43f9-8de8-b9b7b847ccc1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 3],\n",
       "       [1, 4],\n",
       "       [2, 5]])"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.vstack([a,b]).T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "08e62241-cd7d-4e0b-803b-5a09e0f9eed4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 3],\n",
       "       [1, 4],\n",
       "       [2, 5]])"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.hstack([a.reshape(-1,3).T, b.reshape(-1,3).T])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "41a3a3c0-b60d-4f51-abf7-87bc3fc3e3bc",
   "metadata": {},
   "source": [
    "### Boolean Indexing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "9f16db99-dc26-460b-a63a-423d8572a6d4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 1,  2, -1,  3, -3])"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d = np.array([1,2,-1,3,-3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "7a141131-d7cc-4fd7-9ce8-db854897caa1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ True, False, False,  True, False])"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mask = np.array([True, False, False, True, False])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "d07b1b4a-47be-4c95-ac39-ca066648963e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 3])"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d[mask]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "bbba5816-00f7-4db9-b881-c0fbb9f6a252",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([False, False,  True, False,  True])"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(d < 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "27ed2780-13ad-4bc0-9656-447b25a16225",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([-1, -3])"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d[d < 0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "65e6f705-8a9c-41e2-b475-c5a6e52d9ba5",
   "metadata": {},
   "outputs": [],
   "source": [
    "d[d < 0] = 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "9fd1f6ee-4130-42fd-bbf8-6e98dbb0edc4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 2, 0, 3, 0])"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "558aa4bd-369b-4ba9-adb8-9fc5cc1259fe",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 2, 1, 3, 3])"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d = np.array([1,2,-1,3,-3])\n",
    "d[d < 0] *= -1\n",
    "d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "8044443f-0c38-4879-ad49-52bf7a40b805",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 3, 3])"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d[[0,3,4]]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6d07d4ff-08df-466e-9818-8834957facb2",
   "metadata": {},
   "source": [
    "### Series"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3125c791-4ae0-4b13-83a9-c842ba1d3a58",
   "metadata": {},
   "source": [
    "##### polars"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "dcd83294-70ef-4011-8928-f31beb09dc0d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (3,)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th></th></tr><tr><td>i64</td></tr></thead><tbody><tr><td>1</td></tr><tr><td>2</td></tr><tr><td>3</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (3,)\n",
       "Series: '' [i64]\n",
       "[\n",
       "\t1\n",
       "\t2\n",
       "\t3\n",
       "]"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import polars as pl\n",
    "\n",
    "s = pl.Series([1,2,3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "855533b9-07d7-45d9-9001-69a08c4b30cd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (3,)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>num</th></tr><tr><td>i64</td></tr></thead><tbody><tr><td>1</td></tr><tr><td>2</td></tr><tr><td>3</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (3,)\n",
       "Series: 'num' [i64]\n",
       "[\n",
       "\t1\n",
       "\t2\n",
       "\t3\n",
       "]"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = pl.Series('num', [1,2,3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "40ae1ef8-f2b0-4cf9-9c52-501daa85f32d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (3,)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>num</th></tr><tr><td>f64</td></tr></thead><tbody><tr><td>1.0</td></tr><tr><td>2.0</td></tr><tr><td>3.0</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (3,)\n",
       "Series: 'num' [f64]\n",
       "[\n",
       "\t1.0\n",
       "\t2.0\n",
       "\t3.0\n",
       "]"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = pl.Series('num', [1,2,3], dtype=pl.Float64)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "5871f552-2b36-4259-b069-65629c563b5c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.0"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s[0]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d4ea64c9-9085-49e2-89a6-2d15f2d17f22",
   "metadata": {},
   "source": [
    "##### pandas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "c428cbf3-074a-4564-89b9-26dfe1f87312",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    1\n",
       "1    2\n",
       "2    3\n",
       "dtype: int64"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "t = pd.Series([1,2,3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "d474b082-5a61-493c-8620-586511472a8e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    1\n",
       "1    2\n",
       "2    3\n",
       "Name: num, dtype: int64"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t = pd.Series([1,2,3], name='num')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "a4a56699-bea3-4dec-b1bf-14cd838a3d3e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    1.0\n",
       "1    2.0\n",
       "2    3.0\n",
       "Name: num, dtype: float64"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t = pd.Series([1,2,3], name='num', dtype='float')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "aaa1c59a-bcb4-42f8-9c59-f185c9f7b4bd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    1.0\n",
       "1    2.0\n",
       "2    3.0\n",
       "Name: num, dtype: float64"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t = pd.Series([1,2,3], name='num', dtype='float64')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "9b494850-522a-40bd-9a0d-ed11fc0346ab",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.float64(1.0)"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "id": "9b00ece6-d9ed-4ec9-8099-fffbf01661d2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RangeIndex(start=0, stop=3, step=1)"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "id": "9893efb0-de23-4960-87de-952efa237fc5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 1, 2]"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(t.index)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "0deb3878-152f-4dec-ad42-7e8c6547fa0e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "a    1\n",
       "b    2\n",
       "c    3\n",
       "dtype: int64"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t = pd.Series([1,2,3],['a','b','c'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "id": "38d05fce-4e9d-4bc0-a36c-f902c1b38b24",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "a    1\n",
       "b    2\n",
       "c    3\n",
       "dtype: int64"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t = pd.Series([1,2,3],index=['a','b','c'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "id": "98e8986b-c56a-43f9-b250-29fe4153cc4b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "a    1\n",
       "b    2\n",
       "c    3\n",
       "dtype: int64"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t = pd.Series({'a': 1, 'b': 2, 'c': 3})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "id": "a9977d4e-885b-4faa-ab1d-3a321567aa8d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.int64(1)"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t['a']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "id": "f989fbca-2d59-4211-bfea-d0ac7f2a816f",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/var/folders/wh/31nq3r6s42jgshq2j9skw_vw0000gn/T/ipykernel_23373/1759991249.py:1: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`\n",
      "  t[0]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "np.int64(1)"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "id": "889262c4-9bfe-4451-bce6-a210d48dc1da",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.int64(1)"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t.iloc[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "id": "1cc706f3-361d-45be-8de5-05798d1af69d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2    1\n",
       "1    2\n",
       "0    3\n",
       "dtype: int64"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t2 = pd.Series([1,2,3],[2,1,0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "id": "63b50820-fb1f-4a56-b12a-a0956af2a349",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.int64(3)"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t2[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "id": "5d87f431-da31-4361-99ae-adc47290258f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.int64(1)"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t2.iloc[0]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "98cb200d-552f-4d8b-a122-2271fa34d0cf",
   "metadata": {},
   "source": [
    "#### Operations"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ae7f7523-2f02-462e-9eb9-ff4270286060",
   "metadata": {},
   "source": [
    "##### polars"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "id": "b82e61d5-3976-4a60-9b6c-46b003996073",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (3,)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>num</th></tr><tr><td>f64</td></tr></thead><tbody><tr><td>2.0</td></tr><tr><td>4.0</td></tr><tr><td>6.0</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (3,)\n",
       "Series: 'num' [f64]\n",
       "[\n",
       "\t2.0\n",
       "\t4.0\n",
       "\t6.0\n",
       "]"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s + pl.Series([1,2,3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "id": "fdf380ed-3dbb-4bb7-8ec6-93690649288a",
   "metadata": {},
   "outputs": [
    {
     "ename": "InvalidOperationError",
     "evalue": "cannot do arithmetic operation on series of different lengths: got 3 and 4",
     "output_type": "error",
     "traceback": [
      "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
      "\u001b[31mInvalidOperationError\u001b[39m                     Traceback (most recent call last)",
      "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[85]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[43ms\u001b[49m\u001b[43m \u001b[49m\u001b[43m+\u001b[49m\u001b[43m \u001b[49m\u001b[43mpl\u001b[49m\u001b[43m.\u001b[49m\u001b[43mSeries\u001b[49m\u001b[43m(\u001b[49m\u001b[43m[\u001b[49m\u001b[32;43m1\u001b[39;49m\u001b[43m,\u001b[49m\u001b[32;43m2\u001b[39;49m\u001b[43m,\u001b[49m\u001b[32;43m3\u001b[39;49m\u001b[43m,\u001b[49m\u001b[32;43m4\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m)\u001b[49m\n",
      "\u001b[36mFile \u001b[39m\u001b[32m~/Dropbox/Documents/Teaching/cs503-2026sp/.pixi/envs/default/lib/python3.14/site-packages/polars/series/series.py:1127\u001b[39m, in \u001b[36mSeries.__add__\u001b[39m\u001b[34m(self, other)\u001b[39m\n\u001b[32m   1125\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m.dtype.is_decimal() \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(other, (\u001b[38;5;28mfloat\u001b[39m, \u001b[38;5;28mint\u001b[39m)):\n\u001b[32m   1126\u001b[39m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m.to_frame().select(F.col(\u001b[38;5;28mself\u001b[39m.name) + other).to_series()\n\u001b[32m-> \u001b[39m\u001b[32m1127\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_arithmetic\u001b[49m\u001b[43m(\u001b[49m\u001b[43mother\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43madd\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43madd_<>\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n",
      "\u001b[36mFile \u001b[39m\u001b[32m~/Dropbox/Documents/Teaching/cs503-2026sp/.pixi/envs/default/lib/python3.14/site-packages/polars/series/series.py:1074\u001b[39m, in \u001b[36mSeries._arithmetic\u001b[39m\u001b[34m(self, other, op_s, op_ffi)\u001b[39m\n\u001b[32m   1071\u001b[39m     other = pl.Series(\u001b[33m\"\u001b[39m\u001b[33m\"\u001b[39m, [\u001b[38;5;28;01mNone\u001b[39;00m])\n\u001b[32m   1073\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(other, Series):\n\u001b[32m-> \u001b[39m\u001b[32m1074\u001b[39m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m._from_pyseries(\u001b[38;5;28;43mgetattr\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_s\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mop_s\u001b[49m\u001b[43m)\u001b[49m\u001b[43m(\u001b[49m\u001b[43mother\u001b[49m\u001b[43m.\u001b[49m\u001b[43m_s\u001b[49m\u001b[43m)\u001b[49m)\n\u001b[32m   1075\u001b[39m \u001b[38;5;28;01melif\u001b[39;00m _check_for_numpy(other) \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(other, np.ndarray):\n\u001b[32m   1076\u001b[39m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m._from_pyseries(\u001b[38;5;28mgetattr\u001b[39m(\u001b[38;5;28mself\u001b[39m._s, op_s)(Series(other)._s))\n",
      "\u001b[31mInvalidOperationError\u001b[39m: cannot do arithmetic operation on series of different lengths: got 3 and 4"
     ]
    }
   ],
   "source": [
    "s + pl.Series([1,2,3,4])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "id": "32986b98-c15b-4859-a416-73152150c248",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (3,)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>num</th></tr><tr><td>f64</td></tr></thead><tbody><tr><td>5.0</td></tr><tr><td>6.0</td></tr><tr><td>7.0</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (3,)\n",
       "Series: 'num' [f64]\n",
       "[\n",
       "\t5.0\n",
       "\t6.0\n",
       "\t7.0\n",
       "]"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s + 4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "id": "02f881cc-7735-42a0-8288-a04256ad3cc2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (2,)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th></th></tr><tr><td>str</td></tr></thead><tbody><tr><td>&quot;ac&quot;</td></tr><tr><td>&quot;bd&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (2,)\n",
       "Series: '' [str]\n",
       "[\n",
       "\t\"ac\"\n",
       "\t\"bd\"\n",
       "]"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pl.Series(['a','b']) + pl.Series(['c','d'])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "75797179-b850-4f82-8607-08b17611da23",
   "metadata": {},
   "source": [
    "##### pandas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "id": "563b11c2-274a-410a-9b36-5754df7858e9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    2\n",
       "1    4\n",
       "2    6\n",
       "dtype: int64"
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.Series([1,2,3]) + pd.Series([1,2,3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "id": "2e754b68-52f9-4795-bf50-542485ea0709",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "a    1\n",
       "b    2\n",
       "c    3\n",
       "dtype: int64"
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "id": "9df3b651-9545-4fda-bcb2-9a1b6ea142c3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "a   NaN\n",
       "b   NaN\n",
       "c   NaN\n",
       "0   NaN\n",
       "1   NaN\n",
       "2   NaN\n",
       "dtype: float64"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t + pd.Series([1,2,3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "id": "7a754d3b-5ba1-4618-a788-3fc691c72165",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "c    1\n",
       "b    2\n",
       "a    3\n",
       "dtype: int64"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.Series([1,2,3],index=list('cba'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "id": "f7fd70a1-5a9a-4f7e-aa1d-426e5afc74d0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "a    1\n",
       "b    2\n",
       "c    3\n",
       "dtype: int64"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "id": "0728667e-c885-4150-aa82-250faa57b2d2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "a    4\n",
       "b    4\n",
       "c    4\n",
       "dtype: int64"
      ]
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t + pd.Series([1,2,3],index=list('cba'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "id": "a5a1c566-3d58-4109-b520-0743477022c9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    ac\n",
       "1    bd\n",
       "dtype: object"
      ]
     },
     "execution_count": 94,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.Series(['a','b']) + pd.Series(['c','d'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8727c904-ba68-4f3c-87ef-81a6504071d1",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "1fb0e0af-87c1-40dd-bb6d-a3dff0efe666",
   "metadata": {},
   "source": [
    "### Data Frames"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "id": "99bdf96c-f3ef-4b62-bc8c-914436acfc94",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (4, 3)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>state</th><th>year</th><th>pop</th></tr><tr><td>str</td><td>i64</td><td>f64</td></tr></thead><tbody><tr><td>&quot;Ohio&quot;</td><td>2000</td><td>1.5</td></tr><tr><td>&quot;Ohio&quot;</td><td>2001</td><td>1.7</td></tr><tr><td>&quot;Ohio&quot;</td><td>2002</td><td>3.6</td></tr><tr><td>&quot;Nevada&quot;</td><td>2001</td><td>2.4</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (4, 3)\n",
       "┌────────┬──────┬─────┐\n",
       "│ state  ┆ year ┆ pop │\n",
       "│ ---    ┆ ---  ┆ --- │\n",
       "│ str    ┆ i64  ┆ f64 │\n",
       "╞════════╪══════╪═════╡\n",
       "│ Ohio   ┆ 2000 ┆ 1.5 │\n",
       "│ Ohio   ┆ 2001 ┆ 1.7 │\n",
       "│ Ohio   ┆ 2002 ┆ 3.6 │\n",
       "│ Nevada ┆ 2001 ┆ 2.4 │\n",
       "└────────┴──────┴─────┘"
      ]
     },
     "execution_count": 95,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pl.DataFrame({'state': ['Ohio', 'Ohio', 'Ohio', 'Nevada'],\n",
    "                'year': [2000, 2001, 2002, 2001],\n",
    "                'pop': [1.5, 1.7, 3.6, 2.4]})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "id": "4308c8ef-de66-4c65-b520-bd1a069d5997",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (4, 3)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>state</th><th>year</th><th>pop</th></tr><tr><td>str</td><td>i64</td><td>f64</td></tr></thead><tbody><tr><td>&quot;Ohio&quot;</td><td>2000</td><td>1.5</td></tr><tr><td>&quot;Ohio&quot;</td><td>2001</td><td>1.7</td></tr><tr><td>&quot;Ohio&quot;</td><td>2002</td><td>3.6</td></tr><tr><td>&quot;Nevada&quot;</td><td>2001</td><td>2.4</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (4, 3)\n",
       "┌────────┬──────┬─────┐\n",
       "│ state  ┆ year ┆ pop │\n",
       "│ ---    ┆ ---  ┆ --- │\n",
       "│ str    ┆ i64  ┆ f64 │\n",
       "╞════════╪══════╪═════╡\n",
       "│ Ohio   ┆ 2000 ┆ 1.5 │\n",
       "│ Ohio   ┆ 2001 ┆ 1.7 │\n",
       "│ Ohio   ┆ 2002 ┆ 3.6 │\n",
       "│ Nevada ┆ 2001 ┆ 2.4 │\n",
       "└────────┴──────┴─────┘"
      ]
     },
     "execution_count": 96,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pl.DataFrame([pl.Series('state', ['Ohio', 'Ohio', 'Ohio', 'Nevada']),\n",
    "                pl.Series('year', [2000, 2001, 2002, 2001]),\n",
    "                pl.Series('pop', [1.5, 1.7, 3.6, 2.4])])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "id": "0fe72d29-0780-40ff-9964-0403437e2d74",
   "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>state</th>\n",
       "      <th>year</th>\n",
       "      <th>pop</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Ohio</td>\n",
       "      <td>2000</td>\n",
       "      <td>1.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Ohio</td>\n",
       "      <td>2001</td>\n",
       "      <td>1.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Ohio</td>\n",
       "      <td>2002</td>\n",
       "      <td>3.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Nevada</td>\n",
       "      <td>2001</td>\n",
       "      <td>2.4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    state  year  pop\n",
       "0    Ohio  2000  1.5\n",
       "1    Ohio  2001  1.7\n",
       "2    Ohio  2002  3.6\n",
       "3  Nevada  2001  2.4"
      ]
     },
     "execution_count": 97,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dfa = pd.DataFrame({'state': ['Ohio', 'Ohio', 'Ohio', 'Nevada'],\n",
    "                  'year': [2000, 2001, 2002, 2001],\n",
    "                  'pop': [1.5, 1.7, 3.6, 2.4]})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "id": "d2f1f44c-caa9-46d2-bcbb-b61aa0fd216d",
   "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>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>state</th>\n",
       "      <td>Ohio</td>\n",
       "      <td>Ohio</td>\n",
       "      <td>Ohio</td>\n",
       "      <td>Nevada</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>year</th>\n",
       "      <td>2000</td>\n",
       "      <td>2001</td>\n",
       "      <td>2002</td>\n",
       "      <td>2001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>pop</th>\n",
       "      <td>1.5</td>\n",
       "      <td>1.7</td>\n",
       "      <td>3.6</td>\n",
       "      <td>2.4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          0     1     2       3\n",
       "state  Ohio  Ohio  Ohio  Nevada\n",
       "year   2000  2001  2002    2001\n",
       "pop     1.5   1.7   3.6     2.4"
      ]
     },
     "execution_count": 98,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dfa = pd.DataFrame([pd.Series(['Ohio', 'Ohio', 'Ohio', 'Nevada'], name='state'),\n",
    "                pd.Series([2000, 2001, 2002, 2001], name='year'),\n",
    "                pd.Series([1.5, 1.7, 3.6, 2.4], name='pop')])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "id": "bc67cd84-604e-4a8b-8370-d68018aa3cdd",
   "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>state</th>\n",
       "      <th>year</th>\n",
       "      <th>pop</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Ohio</td>\n",
       "      <td>2000</td>\n",
       "      <td>1.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Ohio</td>\n",
       "      <td>2001</td>\n",
       "      <td>1.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Ohio</td>\n",
       "      <td>2002</td>\n",
       "      <td>3.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Nevada</td>\n",
       "      <td>2001</td>\n",
       "      <td>2.4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    state  year  pop\n",
       "0    Ohio  2000  1.5\n",
       "1    Ohio  2001  1.7\n",
       "2    Ohio  2002  3.6\n",
       "3  Nevada  2001  2.4"
      ]
     },
     "execution_count": 99,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dfa.T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "id": "066c62aa-cda7-4af5-83d9-c4fdf0fa784a",
   "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>state</th>\n",
       "      <th>year</th>\n",
       "      <th>pop</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Ohio</td>\n",
       "      <td>2000</td>\n",
       "      <td>1.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Ohio</td>\n",
       "      <td>2001</td>\n",
       "      <td>1.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Ohio</td>\n",
       "      <td>2002</td>\n",
       "      <td>3.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Nevada</td>\n",
       "      <td>2001</td>\n",
       "      <td>2.4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    state  year  pop\n",
       "0    Ohio  2000  1.5\n",
       "1    Ohio  2001  1.7\n",
       "2    Ohio  2002  3.6\n",
       "3  Nevada  2001  2.4"
      ]
     },
     "execution_count": 100,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dfa = pd.DataFrame({'state': pd.Series(['Ohio', 'Ohio', 'Ohio', 'Nevada']),\n",
    "                'year': pd.Series([2000, 2001, 2002, 2001]),\n",
    "                'pop': pd.Series([1.5, 1.7, 3.6, 2.4])})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "id": "3869375c-8e50-4e28-97f8-2f7c56effe1f",
   "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>year</th>\n",
       "      <th>pop</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>state</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Ohio</th>\n",
       "      <td>2000</td>\n",
       "      <td>1.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ohio</th>\n",
       "      <td>2001</td>\n",
       "      <td>1.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ohio</th>\n",
       "      <td>2002</td>\n",
       "      <td>3.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Nevada</th>\n",
       "      <td>2001</td>\n",
       "      <td>2.4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        year  pop\n",
       "state            \n",
       "Ohio    2000  1.5\n",
       "Ohio    2001  1.7\n",
       "Ohio    2002  3.6\n",
       "Nevada  2001  2.4"
      ]
     },
     "execution_count": 101,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dfa = pd.DataFrame({'state': pd.Series(['Ohio', 'Ohio', 'Ohio', 'Nevada']),\n",
    "                'year': pd.Series([2000, 2001, 2002, 2001]),\n",
    "                'pop': pd.Series([1.5, 1.7, 3.6, 2.4])})\n",
    "dfa = dfa.set_index('state')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "id": "4d3d122d-809a-4df3-bcdc-801fa3b5864a",
   "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>year</th>\n",
       "      <th>pop</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>state</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Ohio</th>\n",
       "      <td>2000</td>\n",
       "      <td>1.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ohio</th>\n",
       "      <td>2001</td>\n",
       "      <td>1.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ohio</th>\n",
       "      <td>2002</td>\n",
       "      <td>3.6</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       year  pop\n",
       "state           \n",
       "Ohio   2000  1.5\n",
       "Ohio   2001  1.7\n",
       "Ohio   2002  3.6"
      ]
     },
     "execution_count": 102,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dfa.loc['Ohio']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "id": "7923f024-6fb3-49ff-97ac-9f275a75c647",
   "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>state</th>\n",
       "      <th>year</th>\n",
       "      <th>pop</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Ohio</td>\n",
       "      <td>2000</td>\n",
       "      <td>1.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Ohio</td>\n",
       "      <td>2001</td>\n",
       "      <td>1.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Ohio</td>\n",
       "      <td>2002</td>\n",
       "      <td>3.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Nevada</td>\n",
       "      <td>2001</td>\n",
       "      <td>2.4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    state  year  pop\n",
       "0    Ohio  2000  1.5\n",
       "1    Ohio  2001  1.7\n",
       "2    Ohio  2002  3.6\n",
       "3  Nevada  2001  2.4"
      ]
     },
     "execution_count": 103,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dfa = pd.DataFrame({'state': pd.Series(['Ohio', 'Ohio', 'Ohio', 'Nevada']),\n",
    "                'year': pd.Series([2000, 2001, 2002, 2001]),\n",
    "                'pop': pd.Series([1.5, 1.7, 3.6, 2.4])})"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d9841caa-ab68-4575-87d1-696e1f1b0c31",
   "metadata": {},
   "source": [
    "#### Accessing a Column"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5c80b51d-6b20-411e-924f-fd6653a6caa1",
   "metadata": {},
   "source": [
    "##### polars"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "id": "8fe58002-37eb-43a1-8942-f8e744fe4eca",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (4,)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>state</th></tr><tr><td>str</td></tr></thead><tbody><tr><td>&quot;Ohio&quot;</td></tr><tr><td>&quot;Ohio&quot;</td></tr><tr><td>&quot;Ohio&quot;</td></tr><tr><td>&quot;Nevada&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (4,)\n",
       "Series: 'state' [str]\n",
       "[\n",
       "\t\"Ohio\"\n",
       "\t\"Ohio\"\n",
       "\t\"Ohio\"\n",
       "\t\"Nevada\"\n",
       "]"
      ]
     },
     "execution_count": 104,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['state']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "id": "1b924ea7-5410-459f-8be0-66fff5588057",
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'DataFrame' object has no attribute 'state'",
     "output_type": "error",
     "traceback": [
      "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
      "\u001b[31mAttributeError\u001b[39m                            Traceback (most recent call last)",
      "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[105]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[43mdf\u001b[49m\u001b[43m.\u001b[49m\u001b[43mstate\u001b[49m\n",
      "\u001b[31mAttributeError\u001b[39m: 'DataFrame' object has no attribute 'state'"
     ]
    }
   ],
   "source": [
    "df.state"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d06a221d-9fe2-4c36-a770-ddb82f57a0a6",
   "metadata": {},
   "source": [
    "##### pandas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "id": "0a29b6af-545e-46fe-bb44-978ad6b93359",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0      Ohio\n",
       "1      Ohio\n",
       "2      Ohio\n",
       "3    Nevada\n",
       "Name: state, dtype: object"
      ]
     },
     "execution_count": 106,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dfa['state']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "id": "e6200b18-db0a-4042-afc1-68b3d753849f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0      Ohio\n",
       "1      Ohio\n",
       "2      Ohio\n",
       "3    Nevada\n",
       "Name: state, dtype: object"
      ]
     },
     "execution_count": 107,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dfa.state"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "id": "ac792909-6159-4756-9240-ad2017ba6f65",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RangeIndex(start=0, stop=4, step=1)"
      ]
     },
     "execution_count": 108,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dfa.index"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cff879ea-a641-482f-b665-9ba2167a08a0",
   "metadata": {},
   "source": [
    "#### Assigning to a Column"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "520f4d59-2206-482d-9553-581371610639",
   "metadata": {},
   "source": [
    "##### polars"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "id": "fcf63fe2-deae-4c74-8361-3d63ae9f708b",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "DataFrame object does not support `Series` assignment by index\n\nUse `DataFrame.with_columns`.",
     "output_type": "error",
     "traceback": [
      "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
      "\u001b[31mTypeError\u001b[39m                                 Traceback (most recent call last)",
      "\u001b[32m/var/folders/wh/31nq3r6s42jgshq2j9skw_vw0000gn/T/ipykernel_23373/3895720980.py\u001b[39m in \u001b[36m?\u001b[39m\u001b[34m()\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m df[\u001b[33m'state'\u001b[39m] = [\u001b[33m'Ohio'\u001b[39m, \u001b[33m'Ohio'\u001b[39m, \u001b[33m'Texas'\u001b[39m,\u001b[33m'Nevada'\u001b[39m]\n",
      "\u001b[32m~/Dropbox/Documents/Teaching/cs503-2026sp/.pixi/envs/default/lib/python3.14/site-packages/polars/dataframe/frame.py\u001b[39m in \u001b[36m?\u001b[39m\u001b[34m(self, key, value)\u001b[39m\n\u001b[32m   1505\u001b[39m             msg = (\n\u001b[32m   1506\u001b[39m                 \u001b[33m\"DataFrame object does not support `Series` assignment by index\"\u001b[39m\n\u001b[32m   1507\u001b[39m                 \u001b[33m\"\\n\\nUse `DataFrame.with_columns`.\"\u001b[39m\n\u001b[32m   1508\u001b[39m             )\n\u001b[32m-> \u001b[39m\u001b[32m1509\u001b[39m             \u001b[38;5;28;01mraise\u001b[39;00m TypeError(msg)\n\u001b[32m   1510\u001b[39m \n\u001b[32m   1511\u001b[39m         \u001b[38;5;66;03m# df[[\"C\", \"D\"]]\u001b[39;00m\n\u001b[32m   1512\u001b[39m         \u001b[38;5;28;01melif\u001b[39;00m isinstance(key, list):\n",
      "\u001b[31mTypeError\u001b[39m: DataFrame object does not support `Series` assignment by index\n\nUse `DataFrame.with_columns`."
     ]
    }
   ],
   "source": [
    "df['state'] = ['Ohio', 'Ohio', 'Texas','Nevada']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "id": "2e01d9ca-571f-4c99-8a16-36dc5166e785",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (4, 3)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>state</th><th>year</th><th>pop</th></tr><tr><td>str</td><td>i64</td><td>f64</td></tr></thead><tbody><tr><td>&quot;Ohio&quot;</td><td>2000</td><td>1.5</td></tr><tr><td>&quot;Ohio&quot;</td><td>2001</td><td>1.7</td></tr><tr><td>&quot;Texas&quot;</td><td>2002</td><td>3.6</td></tr><tr><td>&quot;Nevada&quot;</td><td>2001</td><td>2.4</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (4, 3)\n",
       "┌────────┬──────┬─────┐\n",
       "│ state  ┆ year ┆ pop │\n",
       "│ ---    ┆ ---  ┆ --- │\n",
       "│ str    ┆ i64  ┆ f64 │\n",
       "╞════════╪══════╪═════╡\n",
       "│ Ohio   ┆ 2000 ┆ 1.5 │\n",
       "│ Ohio   ┆ 2001 ┆ 1.7 │\n",
       "│ Texas  ┆ 2002 ┆ 3.6 │\n",
       "│ Nevada ┆ 2001 ┆ 2.4 │\n",
       "└────────┴──────┴─────┘"
      ]
     },
     "execution_count": 110,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.with_columns(pl.Series('state',['Ohio', 'Ohio', 'Texas','Nevada']))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "id": "787fbfca-a81a-4582-823a-1a7268844c89",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (4, 3)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>state</th><th>year</th><th>pop</th></tr><tr><td>str</td><td>i64</td><td>f64</td></tr></thead><tbody><tr><td>&quot;Ohio&quot;</td><td>2000</td><td>1.5</td></tr><tr><td>&quot;Ohio&quot;</td><td>2001</td><td>1.7</td></tr><tr><td>&quot;Ohio&quot;</td><td>2002</td><td>3.6</td></tr><tr><td>&quot;Nevada&quot;</td><td>2001</td><td>2.4</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (4, 3)\n",
       "┌────────┬──────┬─────┐\n",
       "│ state  ┆ year ┆ pop │\n",
       "│ ---    ┆ ---  ┆ --- │\n",
       "│ str    ┆ i64  ┆ f64 │\n",
       "╞════════╪══════╪═════╡\n",
       "│ Ohio   ┆ 2000 ┆ 1.5 │\n",
       "│ Ohio   ┆ 2001 ┆ 1.7 │\n",
       "│ Ohio   ┆ 2002 ┆ 3.6 │\n",
       "│ Nevada ┆ 2001 ┆ 2.4 │\n",
       "└────────┴──────┴─────┘"
      ]
     },
     "execution_count": 111,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df # does not change!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "id": "8905a933-98d4-4545-858d-62b17de24171",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (4, 2)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>state</th><th>year</th></tr><tr><td>str</td><td>i64</td></tr></thead><tbody><tr><td>&quot;Ohio&quot;</td><td>2000</td></tr><tr><td>&quot;Ohio&quot;</td><td>2001</td></tr><tr><td>&quot;Ohio&quot;</td><td>2002</td></tr><tr><td>&quot;Nevada&quot;</td><td>2001</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (4, 2)\n",
       "┌────────┬──────┐\n",
       "│ state  ┆ year │\n",
       "│ ---    ┆ ---  │\n",
       "│ str    ┆ i64  │\n",
       "╞════════╪══════╡\n",
       "│ Ohio   ┆ 2000 │\n",
       "│ Ohio   ┆ 2001 │\n",
       "│ Ohio   ┆ 2002 │\n",
       "│ Nevada ┆ 2001 │\n",
       "└────────┴──────┘"
      ]
     },
     "execution_count": 112,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.select('state','year')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "id": "b77851bb-4cb7-44a3-a84e-75c1d5d3b7a2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (4, 2)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>state</th><th>year</th></tr><tr><td>str</td><td>i64</td></tr></thead><tbody><tr><td>&quot;Ohio&quot;</td><td>2000</td></tr><tr><td>&quot;Ohio&quot;</td><td>2001</td></tr><tr><td>&quot;Ohio&quot;</td><td>2002</td></tr><tr><td>&quot;Nevada&quot;</td><td>2001</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (4, 2)\n",
       "┌────────┬──────┐\n",
       "│ state  ┆ year │\n",
       "│ ---    ┆ ---  │\n",
       "│ str    ┆ i64  │\n",
       "╞════════╪══════╡\n",
       "│ Ohio   ┆ 2000 │\n",
       "│ Ohio   ┆ 2001 │\n",
       "│ Ohio   ┆ 2002 │\n",
       "│ Nevada ┆ 2001 │\n",
       "└────────┴──────┘"
      ]
     },
     "execution_count": 113,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[['state','year']]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c7a61e29-473a-4c3b-a3e7-0d1ea9af9bdb",
   "metadata": {},
   "source": [
    "##### pandas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "id": "decd3620-0ff7-422b-ac10-ccebc7dff716",
   "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>state</th>\n",
       "      <th>year</th>\n",
       "      <th>pop</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Ohio</td>\n",
       "      <td>2000</td>\n",
       "      <td>1.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Ohio</td>\n",
       "      <td>2001</td>\n",
       "      <td>1.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Texas</td>\n",
       "      <td>2002</td>\n",
       "      <td>3.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Nevada</td>\n",
       "      <td>2001</td>\n",
       "      <td>2.4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    state  year  pop\n",
       "0    Ohio  2000  1.5\n",
       "1    Ohio  2001  1.7\n",
       "2   Texas  2002  3.6\n",
       "3  Nevada  2001  2.4"
      ]
     },
     "execution_count": 114,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dfa = pd.DataFrame({'state': pd.Series(['Ohio', 'Ohio', 'Ohio', 'Nevada']),\n",
    "                'year': pd.Series([2000, 2001, 2002, 2001]),\n",
    "                'pop': pd.Series([1.5, 1.7, 3.6, 2.4])})\n",
    "dfa['state'] = ['Ohio', 'Ohio', 'Texas','Nevada'] # not recommended!\n",
    "dfa"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "id": "d9f268d7-11ca-42a3-90a9-518dcf79acd0",
   "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>state</th>\n",
       "      <th>year</th>\n",
       "      <th>pop</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Ohio</td>\n",
       "      <td>2000</td>\n",
       "      <td>1.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Ohio</td>\n",
       "      <td>2001</td>\n",
       "      <td>1.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Illinois</td>\n",
       "      <td>2002</td>\n",
       "      <td>3.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Nevada</td>\n",
       "      <td>2001</td>\n",
       "      <td>2.4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      state  year  pop\n",
       "0      Ohio  2000  1.5\n",
       "1      Ohio  2001  1.7\n",
       "2  Illinois  2002  3.6\n",
       "3    Nevada  2001  2.4"
      ]
     },
     "execution_count": 115,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dfa = pd.DataFrame({'state': pd.Series(['Ohio', 'Ohio', 'Ohio', 'Nevada']),\n",
    "                'year': pd.Series([2000, 2001, 2002, 2001]),\n",
    "                'pop': pd.Series([1.5, 1.7, 3.6, 2.4])})\n",
    "dfa2 = dfa.assign(state=['Ohio','Ohio','Illinois','Nevada'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "id": "3c469d6e-4d4c-4b9a-acba-d340e00a38c1",
   "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>state</th>\n",
       "      <th>year</th>\n",
       "      <th>pop</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Ohio</td>\n",
       "      <td>2000</td>\n",
       "      <td>1.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Ohio</td>\n",
       "      <td>2001</td>\n",
       "      <td>1.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Ohio</td>\n",
       "      <td>2002</td>\n",
       "      <td>3.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Nevada</td>\n",
       "      <td>2001</td>\n",
       "      <td>2.4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    state  year  pop\n",
       "0    Ohio  2000  1.5\n",
       "1    Ohio  2001  1.7\n",
       "2    Ohio  2002  3.6\n",
       "3  Nevada  2001  2.4"
      ]
     },
     "execution_count": 116,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dfa # does not change!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "id": "8afa65bc-4822-4c25-a6f7-e3621566dd9e",
   "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>state</th>\n",
       "      <th>year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Ohio</td>\n",
       "      <td>2000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Ohio</td>\n",
       "      <td>2001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Ohio</td>\n",
       "      <td>2002</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Nevada</td>\n",
       "      <td>2001</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    state  year\n",
       "0    Ohio  2000\n",
       "1    Ohio  2001\n",
       "2    Ohio  2002\n",
       "3  Nevada  2001"
      ]
     },
     "execution_count": 117,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dfa[['state','year']]"
   ]
  }
 ],
 "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.14.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
