{ "cells": [ { "cell_type": "markdown", "id": "98ebab25-3712-4f2e-b831-da7df8b60c79", "metadata": {}, "source": [ "# Chapter 1 Practice - Solutions\n", "\n", "[Click here](https://neuronjolt.com/data/downloads/pandas_1_practice_completed.ipynb) to download this chapter as a Jupyter (.ipynb) file.\n", "\n", "These are suggested solutions to the practice exercises for the *Pandas Fundamentals* chapter. For some of the exercises alternative solutions are presented." ] }, { "cell_type": "code", "execution_count": 1, "id": "246558e4-1b61-46ed-98ac-0c2c57b5ca5b", "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import numpy as np" ] }, { "cell_type": "markdown", "id": "101bf2d1-1902-4677-814d-8f049d3f807f", "metadata": {}, "source": [ "The code below loads the `superstore.csv` dataset from an online server into a DataFrame named `store`. This data describes retail sales for a business. Each row of the dataset represents one product on one order. An order that included multiple products will have multiple rows, each with the same order ID but a different product ID." ] }, { "cell_type": "code", "execution_count": 2, "id": "d0c1f7f1-a330-43f7-b2e2-fd7f556a9d88", "metadata": {}, "outputs": [], "source": [ "store = pd.read_csv(\"https://neuronjolt.com/data/superstore.csv\")" ] }, { "cell_type": "markdown", "id": "88e4fa7f-231b-4452-8759-8ca5bd559ce3", "metadata": {}, "source": [ "## Practice Exercise 1-1\n", "\n", "Use the `.info()` method to learn more about the `store` DataFrame" ] }, { "cell_type": "code", "execution_count": 3, "id": "b281bc24-1b58-465d-9405-d11726dba5f5", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "RangeIndex: 9994 entries, 0 to 9993\n", "Data columns (total 20 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 Order ID 9994 non-null object \n", " 1 Order Date 9994 non-null object \n", " 2 Ship Date 9994 non-null object \n", " 3 Ship Mode 9994 non-null object \n", " 4 Customer ID 9994 non-null object \n", " 5 Customer Name 9994 non-null object \n", " 6 Segment 9994 non-null object \n", " 7 Country 9994 non-null object \n", " 8 City 9994 non-null object \n", " 9 State 9994 non-null object \n", " 10 Postal Code 9994 non-null int64 \n", " 11 Region 9994 non-null object \n", " 12 Product ID 9994 non-null object \n", " 13 Category 9994 non-null object \n", " 14 Sub-Category 9994 non-null object \n", " 15 Product Name 9994 non-null object \n", " 16 Sales 9994 non-null float64\n", " 17 Quantity 9994 non-null int64 \n", " 18 Discount 9994 non-null float64\n", " 19 Profit 9994 non-null float64\n", "dtypes: float64(3), int64(2), object(15)\n", "memory usage: 1.5+ MB\n" ] } ], "source": [ "store.info()" ] }, { "cell_type": "markdown", "id": "bb94609d-ddcb-488e-b165-ea38dd1a7a23", "metadata": {}, "source": [ "## Practice Exercise 1-2\n", "\n", "Use the `.sample()` method to examine 3 randomly-selected rows of data from the `store` DataFrame" ] }, { "cell_type": "code", "execution_count": 4, "id": "59e7165c-18e7-457e-bc0c-6eba9e57d359", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Order IDOrder DateShip DateShip ModeCustomer IDCustomer NameSegmentCountryCityStatePostal CodeRegionProduct IDCategorySub-CategoryProduct NameSalesQuantityDiscountProfit
5053CA-2015-1412431/3/20151/8/2015Second ClassAH-10465Amy HuntConsumerUnited StatesDallasTexas75217CentralTEC-AC-10003198TechnologyAccessoriesEnermax Acrylux Wireless Keyboard398.40050.284.6600
4774CA-2017-11974611/23/201711/27/2017Standard ClassCM-12385Christopher MartinezConsumerUnited StatesChicagoIllinois60610CentralTEC-PH-10004447TechnologyPhonesToshiba IPT2010-SD IP Telephone222.38420.216.6788
4204CA-2014-14538710/31/201411/2/2014Second ClassAM-10705Anne McFarlandConsumerUnited StatesCranstonRhode Island2920EastOFF-PA-10002195Office SuppliesPaperRSVP Cards & Envelopes, Blank White, 8-1/2\" X ...10.16020.04.7752
\n", "
" ], "text/plain": [ " Order ID Order Date Ship Date Ship Mode Customer ID \\\n", "5053 CA-2015-141243 1/3/2015 1/8/2015 Second Class AH-10465 \n", "4774 CA-2017-119746 11/23/2017 11/27/2017 Standard Class CM-12385 \n", "4204 CA-2014-145387 10/31/2014 11/2/2014 Second Class AM-10705 \n", "\n", " Customer Name Segment Country City State \\\n", "5053 Amy Hunt Consumer United States Dallas Texas \n", "4774 Christopher Martinez Consumer United States Chicago Illinois \n", "4204 Anne McFarland Consumer United States Cranston Rhode Island \n", "\n", " Postal Code Region Product ID Category Sub-Category \\\n", "5053 75217 Central TEC-AC-10003198 Technology Accessories \n", "4774 60610 Central TEC-PH-10004447 Technology Phones \n", "4204 2920 East OFF-PA-10002195 Office Supplies Paper \n", "\n", " Product Name Sales Quantity \\\n", "5053 Enermax Acrylux Wireless Keyboard 398.400 5 \n", "4774 Toshiba IPT2010-SD IP Telephone 222.384 2 \n", "4204 RSVP Cards & Envelopes, Blank White, 8-1/2\" X ... 10.160 2 \n", "\n", " Discount Profit \n", "5053 0.2 84.6600 \n", "4774 0.2 16.6788 \n", "4204 0.0 4.7752 " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "store.sample(3)" ] }, { "cell_type": "markdown", "id": "41878956-e8cc-42c8-bd02-d2c584e812b7", "metadata": {}, "source": [ "## Practice Exercise 1-3\n", "\n", "Display the names of the columns in the `store` DataFrame." ] }, { "cell_type": "code", "execution_count": 5, "id": "12ce2805-a1e0-4ca4-a1e3-a51791c60536", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Index(['Order ID', 'Order Date', 'Ship Date', 'Ship Mode', 'Customer ID',\n", " 'Customer Name', 'Segment', 'Country', 'City', 'State', 'Postal Code',\n", " 'Region', 'Product ID', 'Category', 'Sub-Category', 'Product Name',\n", " 'Sales', 'Quantity', 'Discount', 'Profit'],\n", " dtype='object')" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "store.columns" ] }, { "cell_type": "markdown", "id": "b5fcc73c-4277-41e4-9d65-b9fa8b8509ef", "metadata": {}, "source": [ "## Practice Exercise 1-4\n", "\n", "Display the count of unique orders (unique Order IDs) in the `store` DataFrame." ] }, { "cell_type": "code", "execution_count": 6, "id": "49fd99d6-7895-47df-8c2f-0ac1364a1ac2", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "5009" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "store['Order ID'].nunique()" ] }, { "cell_type": "markdown", "id": "b6baa032-2fbc-4267-b040-c8c5cfa95dd9", "metadata": {}, "source": [ "## Practice Exercise 1-5\n", "\n", "Display the counts of rows in the `store` DataFrame for each unique product ID. Your result should show the unique product IDs with an integer beside each one that represents the count of rows in the dataset that have that product ID." ] }, { "cell_type": "code", "execution_count": 7, "id": "a0a5a6a4-3125-48f9-8fdf-cf4e246404e4", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Product ID\n", "OFF-PA-10001970 19\n", "TEC-AC-10003832 18\n", "FUR-FU-10004270 16\n", "FUR-CH-10002647 15\n", "FUR-CH-10001146 15\n", " ..\n", "TEC-MA-10004552 1\n", "TEC-MA-10003589 1\n", "OFF-AP-10003099 1\n", "TEC-PH-10002645 1\n", "OFF-ST-10001627 1\n", "Name: count, Length: 1862, dtype: int64" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "store['Product ID'].value_counts()" ] }, { "cell_type": "markdown", "id": "eb52037c-923b-4815-a405-337120f3ac00", "metadata": {}, "source": [ "## Practice Exercise 1-6\n", "\n", "Using just one pandas method, display descriptive statistics (including count, mean, std deviation, minimum, 25th percentile, median, 75th percentile, and maximum) for the sales amount of the order lines." ] }, { "cell_type": "code", "execution_count": 8, "id": "2dd4daf7-237f-412c-8c08-f4190d159ad1", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "count 9994.000000\n", "mean 229.858001\n", "std 623.245101\n", "min 0.444000\n", "25% 17.280000\n", "50% 54.490000\n", "75% 209.940000\n", "max 22638.480000\n", "Name: Sales, dtype: float64" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "store['Sales'].describe()" ] }, { "cell_type": "markdown", "id": "2f1bd498-e212-4dde-8fe4-2f6f3bf95ed4", "metadata": {}, "source": [ "The next exercises makes use of the `quiz_df` DataFrame, which shows quiz scores for several students. The DataFrame is created and displayed in the code cell below." ] }, { "cell_type": "code", "execution_count": 9, "id": "0bb86df1-4027-452d-b344-df968426873e", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
quiz_1quiz_2quiz_3quiz_4
name
Hannah897392100
Sam74758890
Anjali79788588
Erin90889592
Latasha958610098
\n", "
" ], "text/plain": [ " quiz_1 quiz_2 quiz_3 quiz_4\n", "name \n", "Hannah 89 73 92 100\n", "Sam 74 75 88 90\n", "Anjali 79 78 85 88\n", "Erin 90 88 95 92\n", "Latasha 95 86 100 98" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "quizzes = {\n", " 'name': [\"Hannah\", \"Sam\", \"Anjali\", \"Erin\", \"Latasha\"], \n", " 'quiz_1': [89, 74, 79, 90, 95],\n", " 'quiz_2': [73, 75, 78, 88, 86],\n", " 'quiz_3': [92, 88, 85, 95, 100],\n", " 'quiz_4': [100, 90, 88, 92, 98]\n", "}\n", "\n", "quiz_df = pd.DataFrame(quizzes).set_index('name')\n", "\n", "quiz_df" ] }, { "cell_type": "markdown", "id": "88ecdf58-7df8-4b2b-ad24-760918cf2728", "metadata": {}, "source": [ "## Practice Exercise 1-7\n", "\n", "Using one pandas method, calculate and display the median quiz score for each student in the `quiz_df` DataFrame" ] }, { "cell_type": "code", "execution_count": 10, "id": "7e6d3465-951b-4247-97aa-544ef7b08dce", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "name\n", "Hannah 90.5\n", "Sam 81.5\n", "Anjali 82.0\n", "Erin 91.0\n", "Latasha 96.5\n", "dtype: float64" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "quiz_df.median(axis = 1)" ] }, { "cell_type": "markdown", "id": "8af369c4-7146-4a06-b07d-b8d9dd4dc747", "metadata": {}, "source": [ "## Practice Exercise 1-8\n", "\n", "Calculate and display the minimum quiz score for each quiz in the `quiz_df` DataFrame" ] }, { "cell_type": "code", "execution_count": 11, "id": "2d0da397-1081-4cac-943c-b99dba36e820", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "quiz_1 74\n", "quiz_2 73\n", "quiz_3 85\n", "quiz_4 88\n", "dtype: int64" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "quiz_df.min(axis = 0)" ] }, { "cell_type": "markdown", "id": "6467a8b7-652c-45bb-9978-2e34846192e7", "metadata": {}, "source": [ "## Practice Exercise 1-9\n", "\n", "Show the quiz scores for just Anjali. **Hint:** In `quiz_df` the names are the row index, so they cannot be accessed as a column." ] }, { "cell_type": "code", "execution_count": 12, "id": "bf7b86ea-14af-47bc-bebd-4f0b7f057807", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "quiz_1 79\n", "quiz_2 78\n", "quiz_3 85\n", "quiz_4 88\n", "Name: Anjali, dtype: int64" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "quiz_df.loc['Anjali']" ] }, { "cell_type": "markdown", "id": "8fe0d658-0b92-4fef-aeb1-5813b6935482", "metadata": {}, "source": [ "## Practice Exercise 1-10\n", "\n", "Show the scores on quizzes 1 through 3 for Sam and Erin." ] }, { "cell_type": "code", "execution_count": 13, "id": "e5d529f9-ff19-4ae1-af2a-0e32da19d66c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
quiz_1quiz_2quiz_3
name
Sam747588
Erin908895
\n", "
" ], "text/plain": [ " quiz_1 quiz_2 quiz_3\n", "name \n", "Sam 74 75 88\n", "Erin 90 88 95" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "quiz_df.loc[['Sam', 'Erin'], 'quiz_1':'quiz_3']" ] }, { "cell_type": "markdown", "id": "47412d23-10a8-410b-9f59-3c26da462ea3", "metadata": {}, "source": [ "Now, let's load the NBA boxscore data from the 2023-24 season so that we can use it in some of the exercises below. Recall that in this dataset each row represents the statistics for one player in one game." ] }, { "cell_type": "code", "execution_count": 14, "id": "78b1f95a-9e7a-4d2d-a3d5-023d3a9f47c1", "metadata": {}, "outputs": [], "source": [ "url = \"https://neuronjolt.com/data/nba_bs_2023-24_season_cleaned.csv\"\n", "boxscores = pd.read_csv(url)" ] }, { "cell_type": "markdown", "id": "474f088c", "metadata": {}, "source": [ "## Practice Exercise 1-11\n", "\n", "Show counts by player of games in which the player scored 50+ points during the season. **Hint:** Remember that each row represents a player-game, so you should limit the data to rows in which 50 or more points were scored and then count the rows for each player." ] }, { "cell_type": "code", "execution_count": 15, "id": "1cd57d80", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "player\n", "T. Maxey 3\n", "D. Booker 3\n", "J. Embiid 3\n", "J. Brunson 2\n", "G. Antetokounmpo 2\n", "L. Doncic 2\n", "Z. LaVine 1\n", "K. Towns 1\n", "Steph Curry 1\n", "M. Flynn 1\n", "A. Edwards 1\n", "Name: count, dtype: int64" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "boxscores.loc[boxscores['pts'] >= 50, 'player'].value_counts()" ] }, { "cell_type": "code", "execution_count": 16, "id": "925f6132-bcff-4db9-a853-c0e86d533b90", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "player\n", "T. Maxey 3\n", "D. Booker 3\n", "J. Embiid 3\n", "J. Brunson 2\n", "G. Antetokounmpo 2\n", "L. Doncic 2\n", "Z. LaVine 1\n", "K. Towns 1\n", "Steph Curry 1\n", "M. Flynn 1\n", "A. Edwards 1\n", "Name: count, dtype: int64" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Alternative solution using .query()\n", "boxscores.query('pts >= 50')['player'].value_counts()" ] }, { "cell_type": "markdown", "id": "add22b50", "metadata": {}, "source": [ "## Practice Exercise 1-12\n", "\n", "Let's look for some amazing guard play. Display `player`, `ast` and `stl`, and `pts` for player-games in which a player had 20 or more assists *or* 7 or more steals." ] }, { "cell_type": "code", "execution_count": 17, "id": "678a5080", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
playeraststlpts
3282S. Gilgeous-Alexander5728
9726T. Haliburton20221
10128T. Haliburton23222
17842H. Jones4717
20672A. Davis5727
25572Tre Mann7716
\n", "
" ], "text/plain": [ " player ast stl pts\n", "3282 S. Gilgeous-Alexander 5 7 28\n", "9726 T. Haliburton 20 2 21\n", "10128 T. Haliburton 23 2 22\n", "17842 H. Jones 4 7 17\n", "20672 A. Davis 5 7 27\n", "25572 Tre Mann 7 7 16" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "boxscores.loc[(boxscores['ast'] >= 20) | (boxscores['stl'] >= 7),\n", " ['player', 'ast', 'stl', 'pts']]" ] }, { "cell_type": "code", "execution_count": 18, "id": "ae532185-ab1c-405c-90d6-d26b1d1fc400", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
playeraststlpts
3282S. Gilgeous-Alexander5728
9726T. Haliburton20221
10128T. Haliburton23222
17842H. Jones4717
20672A. Davis5727
25572Tre Mann7716
\n", "
" ], "text/plain": [ " player ast stl pts\n", "3282 S. Gilgeous-Alexander 5 7 28\n", "9726 T. Haliburton 20 2 21\n", "10128 T. Haliburton 23 2 22\n", "17842 H. Jones 4 7 17\n", "20672 A. Davis 5 7 27\n", "25572 Tre Mann 7 7 16" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Alternative solution using .query()\n", "boxscores.query('ast >= 20 or stl >=7').loc[:, ['player', 'ast', 'stl', 'pts']]" ] }, { "cell_type": "markdown", "id": "43ca4578", "metadata": {}, "source": [ "## Practice Exercise 1-13\n", "\n", "Show player name and count of games (rows) in which the player had 10 or more assists. Use the `head()` method to limit the result to 10 rows. In other words, create a top-10 list of players according to how many games in which they had 10 or more assists." ] }, { "cell_type": "code", "execution_count": 19, "id": "3f767128", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "player\n", "T. Haliburton 47\n", "L. Doncic 37\n", "Trae Young 37\n", "N. Jokic 31\n", "D. Sabonis 29\n", "J. Harden 27\n", "F. VanVleet 24\n", "L. James 18\n", "D. Murray 16\n", "C. Cunningham 16\n", "Name: count, dtype: int64" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "boxscores.loc[boxscores['ast'] >= 10, 'player'].value_counts().head(10)" ] }, { "cell_type": "code", "execution_count": 20, "id": "68e55ed6-4153-4124-83bd-0e92d4d4a36d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "player\n", "T. Haliburton 47\n", "L. Doncic 37\n", "Trae Young 37\n", "N. Jokic 31\n", "D. Sabonis 29\n", "J. Harden 27\n", "F. VanVleet 24\n", "L. James 18\n", "D. Murray 16\n", "C. Cunningham 16\n", "Name: count, dtype: int64" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Alternative solution using .query()\n", "boxscores.query('ast >= 10')['player'].value_counts().head(10)" ] }, { "cell_type": "markdown", "id": "536e6f42", "metadata": {}, "source": [ "## Practice Exercise 1-14\n", "\n", "Show player name, points, rebounds, and assists for all the player-games in which the player had at least ten points, ten rebounds, and ten assists (\"triple double\"). Sort in decreasing order of points." ] }, { "cell_type": "code", "execution_count": 21, "id": "9579cc1a", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
playerptsrebast
7964L. Doncic401210
6523L. Doncic401011
20389L. Doncic391010
9208L. Doncic391210
25233L. Doncic391210
...............
22777K. Middleton111010
22886J. Hart111410
15081J. Hart101010
21858J. Hart101111
24225Tre Jones101211
\n", "

136 rows × 4 columns

\n", "
" ], "text/plain": [ " player pts reb ast\n", "7964 L. Doncic 40 12 10\n", "6523 L. Doncic 40 10 11\n", "20389 L. Doncic 39 10 10\n", "9208 L. Doncic 39 12 10\n", "25233 L. Doncic 39 12 10\n", "... ... ... ... ...\n", "22777 K. Middleton 11 10 10\n", "22886 J. Hart 11 14 10\n", "15081 J. Hart 10 10 10\n", "21858 J. Hart 10 11 11\n", "24225 Tre Jones 10 12 11\n", "\n", "[136 rows x 4 columns]" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(boxscores\n", " .loc[(boxscores['pts'] >=10) & \n", " (boxscores['reb'] >= 10) &\n", " (boxscores['ast'] >= 10), \n", " ['player', 'pts', 'reb', 'ast']]\n", " .sort_values(by = 'pts', ascending = False)\n", ")" ] }, { "cell_type": "code", "execution_count": 22, "id": "627b16da-8fb8-4763-b733-7a2f53f67c09", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
playerptsrebast
7964L. Doncic401210
6523L. Doncic401011
20389L. Doncic391010
9208L. Doncic391210
25233L. Doncic391210
...............
22777K. Middleton111010
22886J. Hart111410
15081J. Hart101010
21858J. Hart101111
24225Tre Jones101211
\n", "

136 rows × 4 columns

\n", "
" ], "text/plain": [ " player pts reb ast\n", "7964 L. Doncic 40 12 10\n", "6523 L. Doncic 40 10 11\n", "20389 L. Doncic 39 10 10\n", "9208 L. Doncic 39 12 10\n", "25233 L. Doncic 39 12 10\n", "... ... ... ... ...\n", "22777 K. Middleton 11 10 10\n", "22886 J. Hart 11 14 10\n", "15081 J. Hart 10 10 10\n", "21858 J. Hart 10 11 11\n", "24225 Tre Jones 10 12 11\n", "\n", "[136 rows x 4 columns]" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Alternative solution using .query()\n", "(boxscores\n", " .query('pts >= 10 & reb >= 10 & ast >= 10')\n", " .loc[:, ['player', 'pts', 'reb', 'ast']]\n", " .sort_values(by = 'pts', ascending = False)\n", ")" ] }, { "cell_type": "markdown", "id": "414598db", "metadata": {}, "source": [ "## Practice Exercise 1-15\n", "\n", "Display the entire stat line for any player who scored 40 or more points and 10 or more rebounds in a game while playing for the Lakers ('LAL' in the `team` column)." ] }, { "cell_type": "code", "execution_count": 23, "id": "9b49f5a9", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
dateteamopponentplayerpositionminorebdrebrebast...topfplus_mptsfg_mfg_atres_mtres_aft_mft_a
931220231225LALBOSA. DavisPF3958134...22-640152624810
1177920240109LALTORA. DavisPF40110116...340411317221314
1908620240229LALWSHA. DavisPF41312154...126401422001213
\n", "

3 rows × 22 columns

\n", "
" ], "text/plain": [ " date team opponent player position min oreb dreb reb ast \\\n", "9312 20231225 LAL BOS A. Davis PF 39 5 8 13 4 \n", "11779 20240109 LAL TOR A. Davis PF 40 1 10 11 6 \n", "19086 20240229 LAL WSH A. Davis PF 41 3 12 15 4 \n", "\n", " ... to pf plus_m pts fg_m fg_a tres_m tres_a ft_m ft_a \n", "9312 ... 2 2 -6 40 15 26 2 4 8 10 \n", "11779 ... 3 4 0 41 13 17 2 2 13 14 \n", "19086 ... 1 2 6 40 14 22 0 0 12 13 \n", "\n", "[3 rows x 22 columns]" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(boxscores\n", " .loc[(boxscores['team'] == 'LAL') &\n", " (boxscores['pts'] >= 40) &\n", " (boxscores['reb'] >= 10)]\n", ")" ] }, { "cell_type": "code", "execution_count": 24, "id": "d1f2e7ff-426f-442f-a1dd-8878b386dcf8", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
dateteamopponentplayerpositionminorebdrebrebast...topfplus_mptsfg_mfg_atres_mtres_aft_mft_a
931220231225LALBOSA. DavisPF3958134...22-640152624810
1177920240109LALTORA. DavisPF40110116...340411317221314
1908620240229LALWSHA. DavisPF41312154...126401422001213
\n", "

3 rows × 22 columns

\n", "
" ], "text/plain": [ " date team opponent player position min oreb dreb reb ast \\\n", "9312 20231225 LAL BOS A. Davis PF 39 5 8 13 4 \n", "11779 20240109 LAL TOR A. Davis PF 40 1 10 11 6 \n", "19086 20240229 LAL WSH A. Davis PF 41 3 12 15 4 \n", "\n", " ... to pf plus_m pts fg_m fg_a tres_m tres_a ft_m ft_a \n", "9312 ... 2 2 -6 40 15 26 2 4 8 10 \n", "11779 ... 3 4 0 41 13 17 2 2 13 14 \n", "19086 ... 1 2 6 40 14 22 0 0 12 13 \n", "\n", "[3 rows x 22 columns]" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Alternative solution using .query()\n", "boxscores.query('team == \"LAL\" & pts >= 40 & reb >= 10')" ] }, { "cell_type": "markdown", "id": "b9569687", "metadata": {}, "source": [ "## Practice Exercise 1-16\n", "\n", "How many players are in the `boxscores` data?" ] }, { "cell_type": "code", "execution_count": 25, "id": "dc22f839", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "584" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "boxscores['player'].nunique()" ] }, { "cell_type": "markdown", "id": "112e75d9-8600-4a28-b58d-e89e219b82b6", "metadata": {}, "source": [ "## Practice Exercise 1-17\n", "\n", "Convert the date column in the boxscore data to a datetime type." ] }, { "cell_type": "code", "execution_count": 26, "id": "5652c341-72f4-44e7-b3fe-a6bf2c954732", "metadata": {}, "outputs": [], "source": [ "boxscores['date'] = pd.to_datetime(boxscores['date'], format = \"%Y%m%d\")" ] }, { "cell_type": "markdown", "id": "acf4affd", "metadata": {}, "source": [ "## Practice Exercise 1-18\n", "\n", "Show the date, player, and points for the top 5 games (top 5 points scored by a player in a game) that occurred in January, 2024." ] }, { "cell_type": "code", "execution_count": 27, "id": "2d0a41d3", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
dateplayerpts
142802024-01-26L. Doncic73
137262024-01-22J. Embiid70
137682024-01-22K. Towns62
143272024-01-26D. Booker62
133072024-01-19D. Booker52
\n", "
" ], "text/plain": [ " date player pts\n", "14280 2024-01-26 L. Doncic 73\n", "13726 2024-01-22 J. Embiid 70\n", "13768 2024-01-22 K. Towns 62\n", "14327 2024-01-26 D. Booker 62\n", "13307 2024-01-19 D. Booker 52" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(boxscores\n", " .loc[boxscores['date'].dt.month == 1,['date', 'player', 'pts']]\n", " .sort_values(by = 'pts', ascending = False)\n", " .head(5)\n", ")" ] }, { "cell_type": "markdown", "id": "f9cd963c", "metadata": {}, "source": [ "## Practice Exercise 1-19\n", "\n", "Show all the unique player names that include the string \"James\". Make the test case-sensitive." ] }, { "cell_type": "code", "execution_count": 28, "id": "ae0e95e3", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array(['L. James', 'James Johnson'], dtype=object)" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(boxscores\n", " .loc[boxscores['player'].str.contains('James'), 'player']\n", " .unique()\n", ")" ] }, { "cell_type": "markdown", "id": "d233f845", "metadata": {}, "source": [ "## Practice Exercise 1-20\n", "From the sales data, show descriptive statistics for quantity ordered for product ID 'FUR-CH-10001146'." ] }, { "cell_type": "code", "execution_count": 29, "id": "1af98de1", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "count 15.000000\n", "mean 3.400000\n", "std 1.723783\n", "min 1.000000\n", "25% 2.000000\n", "50% 3.000000\n", "75% 4.500000\n", "max 7.000000\n", "Name: Quantity, dtype: float64" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "store.loc[store['Product ID'] == 'FUR-CH-10001146', 'Quantity'].describe()" ] }, { "cell_type": "markdown", "id": "24eca3f2-2404-4534-85d6-2c9107098a58", "metadata": {}, "source": [ "The code below creates the `scores_df` DataFrame, which has some missing values. It shows course section and quiz scores for some students." ] }, { "cell_type": "code", "execution_count": 30, "id": "455699b0-636b-47e1-97c6-7b81f9c39903", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
sectionstudentq1q2q3
0A199.095NaN
1B287.090NaN
2A355.078NaN
3A4100.09475.0
4B575.08593.0
5B6NaN90NaN
6A788.09085.0
7A890.08988.0
8B992.09990.0
9A10NaN10092.0
\n", "
" ], "text/plain": [ " section student q1 q2 q3\n", "0 A 1 99.0 95 NaN\n", "1 B 2 87.0 90 NaN\n", "2 A 3 55.0 78 NaN\n", "3 A 4 100.0 94 75.0\n", "4 B 5 75.0 85 93.0\n", "5 B 6 NaN 90 NaN\n", "6 A 7 88.0 90 85.0\n", "7 A 8 90.0 89 88.0\n", "8 B 9 92.0 99 90.0\n", "9 A 10 NaN 100 92.0" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "scores_df = pd.DataFrame(\n", " {\n", " 'section': ['A', 'B', 'A', 'A', 'B', 'B', 'A', 'A', 'B', 'A'],\n", " 'student': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],\n", " 'q1': [99, 87, 55, 100, 75, None, 88, 90, 92, np.nan],\n", " 'q2': [95, 90, 78, 94, 85, 90, 90, 89, 99, 100],\n", " 'q3': [None, np.nan, None, 75, 93, None, 85, 88, 90, 92]\n", " }\n", ")\n", "\n", "scores_df" ] }, { "cell_type": "markdown", "id": "00fb6cd6", "metadata": {}, "source": [ "## Practice Exercise 1-21\n", "\n", "Show all rows in the scores DataFrame for which the quiz 3 score is missing." ] }, { "cell_type": "code", "execution_count": 31, "id": "899440d7", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
sectionstudentq1q2q3
0A199.095NaN
1B287.090NaN
2A355.078NaN
5B6NaN90NaN
\n", "
" ], "text/plain": [ " section student q1 q2 q3\n", "0 A 1 99.0 95 NaN\n", "1 B 2 87.0 90 NaN\n", "2 A 3 55.0 78 NaN\n", "5 B 6 NaN 90 NaN" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "scores_df.loc[scores_df['q3'].isna()]" ] }, { "cell_type": "markdown", "id": "0566a750", "metadata": {}, "source": [ "## Practice Exercise 1-22\n", "\n", "Show all rows in the scores DataFrame for which the quiz 3 score is NOT missing." ] }, { "cell_type": "code", "execution_count": 32, "id": "6bc3c9e4", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
sectionstudentq1q2q3
3A4100.09475.0
4B575.08593.0
6A788.09085.0
7A890.08988.0
8B992.09990.0
9A10NaN10092.0
\n", "
" ], "text/plain": [ " section student q1 q2 q3\n", "3 A 4 100.0 94 75.0\n", "4 B 5 75.0 85 93.0\n", "6 A 7 88.0 90 85.0\n", "7 A 8 90.0 89 88.0\n", "8 B 9 92.0 99 90.0\n", "9 A 10 NaN 100 92.0" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "scores_df.loc[scores_df['q3'].notna()]" ] }, { "cell_type": "markdown", "id": "070a3cce-a947-4bd4-bf6e-579f389764de", "metadata": {}, "source": [ "## Practice Exercise 1-23\n", "\n", "Display the `q1` column of the `scores_df` DataFrame with the missing values in that column replaced by zeros." ] }, { "cell_type": "code", "execution_count": 33, "id": "9b88e1bb-2caf-4d8a-bb2c-043231205720", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0 99.0\n", "1 87.0\n", "2 55.0\n", "3 100.0\n", "4 75.0\n", "5 0.0\n", "6 88.0\n", "7 90.0\n", "8 92.0\n", "9 0.0\n", "Name: q1, dtype: float64" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "scores_df['q1'].fillna(0)" ] }, { "cell_type": "markdown", "id": "61940334", "metadata": {}, "source": [ "## Practice Exercise 1-24\n", "\n", "Display the `quiz_df`, then add a new column to the DataFrame that has the quiz average for each student. Display the DataFrame again after adding the new column." ] }, { "cell_type": "code", "execution_count": 34, "id": "1b30911c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
quiz_1quiz_2quiz_3quiz_4
name
Hannah897392100
Sam74758890
Anjali79788588
Erin90889592
Latasha958610098
\n", "
" ], "text/plain": [ " quiz_1 quiz_2 quiz_3 quiz_4\n", "name \n", "Hannah 89 73 92 100\n", "Sam 74 75 88 90\n", "Anjali 79 78 85 88\n", "Erin 90 88 95 92\n", "Latasha 95 86 100 98" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "quiz_df" ] }, { "cell_type": "code", "execution_count": 35, "id": "0f8e2cd3", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
quiz_1quiz_2quiz_3quiz_4quiz_avg
name
Hannah89739210088.50
Sam7475889081.75
Anjali7978858882.50
Erin9088959291.25
Latasha95861009894.75
\n", "
" ], "text/plain": [ " quiz_1 quiz_2 quiz_3 quiz_4 quiz_avg\n", "name \n", "Hannah 89 73 92 100 88.50\n", "Sam 74 75 88 90 81.75\n", "Anjali 79 78 85 88 82.50\n", "Erin 90 88 95 92 91.25\n", "Latasha 95 86 100 98 94.75" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "quiz_df['quiz_avg'] = (quiz_df['quiz_1'] + \n", " quiz_df['quiz_2'] + \n", " quiz_df['quiz_3'] + \n", " quiz_df['quiz_4']) / 4\n", "\n", "quiz_df" ] }, { "cell_type": "markdown", "id": "8379e423-db5d-4c7e-908f-01423fd09818", "metadata": {}, "source": [ "## Practice Exercise 1-25\n", "\n", "Delete the new column you created for the quiz average from the `quiz_df` DataFrame and then display the DataFrame to verify that the column is gone." ] }, { "cell_type": "code", "execution_count": 36, "id": "ca00cce3-ed09-4f89-b71e-ecb155526fd3", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
quiz_1quiz_2quiz_3quiz_4
name
Hannah897392100
Sam74758890
Anjali79788588
Erin90889592
Latasha958610098
\n", "
" ], "text/plain": [ " quiz_1 quiz_2 quiz_3 quiz_4\n", "name \n", "Hannah 89 73 92 100\n", "Sam 74 75 88 90\n", "Anjali 79 78 85 88\n", "Erin 90 88 95 92\n", "Latasha 95 86 100 98" ] }, "execution_count": 36, "metadata": {}, "output_type": "execute_result" } ], "source": [ "quiz_df.drop('quiz_avg', axis = 1, inplace = True)\n", "\n", "quiz_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.12.4" } }, "nbformat": 4, "nbformat_minor": 5 }