diff --git a/README.md b/README.md
deleted file mode 100644
index b0ef389..0000000
--- a/README.md
+++ /dev/null
@@ -1,92 +0,0 @@
-
-
-# LAB | Connecting Python to SQL
-
-
-
- Learning Goals
-
-
- This lab allows you to practice and apply the concepts and techniques taught in class.
-
- Upon completion of this lab, you will be able to:
-
-- Write a Python script to connect to a relational database using the appropriate Python library and query it using SQL commands.
-
-
-
-
-
-
-
-
- Prerequisites
-
-
-Before this starting this lab, you should have learnt about:
-
-- Basic SQL queries
-- Python and Pandas
-- Data Wrangling, which involves tasks such as grouping, aggregating, dealing with indexes, renaming columns, merging data and performing calculations.
-
-
-
-
-
-
-
-## Introduction
-
-Welcome to the Connecting Python to SQL lab!
-
-In this lab, you will be working with the [Sakila](https://dev.mysql.com/doc/sakila/en/) database on movie rentals. Specifically, you will be practicing how to do basic SQL queries using Python. By connecting Python to SQL, you can leverage the power of both languages to efficiently manipulate and analyze large datasets. Throughout this lab, you will practice how to use Python to retrieve and manipulate data stored in the Sakila database using SQL queries. Let's get started!
-
-## Challenge
-
-In this lab, the objective is to identify the customers who were active in both May and June, and how did their activity differ between months. To achieve this, follow these steps:
-
-1. Establish a connection between Python and the Sakila database.
-
-2. Write a Python function called `rentals_month` that retrieves rental data for a given month and year (passed as parameters) from the Sakila database as a Pandas DataFrame. The function should take in three parameters:
-
- - `engine`: an object representing the database connection engine to be used to establish a connection to the Sakila database.
- - `month`: an integer representing the month for which rental data is to be retrieved.
- - `year`: an integer representing the year for which rental data is to be retrieved.
-
- The function should execute a SQL query to retrieve the rental data for the specified month and year from the rental table in the Sakila database, and return it as a pandas DataFrame.
-
-3. Develop a Python function called `rental_count_month` that takes the DataFrame provided by `rentals_month` as input along with the month and year and returns a new DataFrame containing the number of rentals made by each customer_id during the selected month and year.
-
- The function should also include the month and year as parameters and use them to name the new column according to the month and year, for example, if the input month is 05 and the year is 2005, the column name should be "rentals_05_2005".
-
-
- *Hint: Consider making use of pandas [groupby()](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.groupby.html)*
-
-4. Create a Python function called `compare_rentals` that takes two DataFrames as input containing the number of rentals made by each customer in different months and years.
-The function should return a combined DataFrame with a new 'difference' column, which is the difference between the number of rentals in the two months.
-
-## Requirements
-
-- Fork this repo
-- Clone it to your machine
-
-
-
-## Getting Started
-
-Complete the challenges. Follow the instructions and add your code and explanations as necessary.
-
-## Submission
-
-- Upon completion, run the following commands:
-
-```bash
-git add .
-git commit -m "Solved lab"
-git push origin master
-```
-
-- Paste the link of your lab in Student Portal.
-
-
-
diff --git a/lab-sql-python-connection.ipynb b/lab-sql-python-connection.ipynb
new file mode 100644
index 0000000..68e90fd
--- /dev/null
+++ b/lab-sql-python-connection.ipynb
@@ -0,0 +1,1905 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "id": "5a68bf75-3912-4bc3-8404-0a0448fc0d99",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "###STEP 1 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "id": "91aa457a-ede9-460c-8e44-68e9a2cfec68",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#1\n",
+ "import mysql.connector\n",
+ "import pandas as pd\n",
+ "from getpass import getpass"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "id": "cf60a89c-267b-45fa-8fe9-e8bc0eeb827b",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdin",
+ "output_type": "stream",
+ "text": [
+ "Enter your MySQL password: ········\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Connection successful!\n"
+ ]
+ }
+ ],
+ "source": [
+ "#2\n",
+ "password = getpass(\"Enter your MySQL password: \")\n",
+ "\n",
+ "connection = mysql.connector.connect(\n",
+ " host='127.0.0.1',\n",
+ " port=3306,\n",
+ " user='root',\n",
+ " password=password,\n",
+ " database='sakila'\n",
+ ")\n",
+ "\n",
+ "cursor = connection.cursor()\n",
+ "\n",
+ "print(\"Connection successful!\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "id": "aff22e60-487a-4d84-9490-5d305ec7f3a8",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "C:\\Users\\manda\\AppData\\Local\\Temp\\ipykernel_27804\\4283134436.py:2: UserWarning: pandas only supports SQLAlchemy connectable (engine/connection) or database string URI or sqlite3 DBAPI2 connection. Other DBAPI2 objects are not tested. Please consider using SQLAlchemy.\n",
+ " pd.read_sql(\"SHOW TABLES;\", connection)\n"
+ ]
+ },
+ {
+ "data": {
+ "text/html": [
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Tables_in_sakila | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " actor | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " actor_info | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " address | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " category | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " city | \n",
+ "
\n",
+ " \n",
+ " | 5 | \n",
+ " country | \n",
+ "
\n",
+ " \n",
+ " | 6 | \n",
+ " customer | \n",
+ "
\n",
+ " \n",
+ " | 7 | \n",
+ " customer_list | \n",
+ "
\n",
+ " \n",
+ " | 8 | \n",
+ " customer_rental_summary | \n",
+ "
\n",
+ " \n",
+ " | 9 | \n",
+ " film | \n",
+ "
\n",
+ " \n",
+ " | 10 | \n",
+ " film_actor | \n",
+ "
\n",
+ " \n",
+ " | 11 | \n",
+ " film_category | \n",
+ "
\n",
+ " \n",
+ " | 12 | \n",
+ " film_list | \n",
+ "
\n",
+ " \n",
+ " | 13 | \n",
+ " film_text | \n",
+ "
\n",
+ " \n",
+ " | 14 | \n",
+ " inventory | \n",
+ "
\n",
+ " \n",
+ " | 15 | \n",
+ " language | \n",
+ "
\n",
+ " \n",
+ " | 16 | \n",
+ " nicer_but_slower_film_list | \n",
+ "
\n",
+ " \n",
+ " | 17 | \n",
+ " payment | \n",
+ "
\n",
+ " \n",
+ " | 18 | \n",
+ " rental | \n",
+ "
\n",
+ " \n",
+ " | 19 | \n",
+ " sales_by_film_category | \n",
+ "
\n",
+ " \n",
+ " | 20 | \n",
+ " sales_by_store | \n",
+ "
\n",
+ " \n",
+ " | 21 | \n",
+ " staff | \n",
+ "
\n",
+ " \n",
+ " | 22 | \n",
+ " staff_list | \n",
+ "
\n",
+ " \n",
+ " | 23 | \n",
+ " store | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Tables_in_sakila\n",
+ "0 actor\n",
+ "1 actor_info\n",
+ "2 address\n",
+ "3 category\n",
+ "4 city\n",
+ "5 country\n",
+ "6 customer\n",
+ "7 customer_list\n",
+ "8 customer_rental_summary\n",
+ "9 film\n",
+ "10 film_actor\n",
+ "11 film_category\n",
+ "12 film_list\n",
+ "13 film_text\n",
+ "14 inventory\n",
+ "15 language\n",
+ "16 nicer_but_slower_film_list\n",
+ "17 payment\n",
+ "18 rental\n",
+ "19 sales_by_film_category\n",
+ "20 sales_by_store\n",
+ "21 staff\n",
+ "22 staff_list\n",
+ "23 store"
+ ]
+ },
+ "execution_count": 4,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# 3 \n",
+ "pd.read_sql(\"SHOW TABLES;\", connection)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "id": "bfffc12f-c952-4df1-bad2-89d1011123bb",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "###STEP 2"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "id": "c8c82c37-052e-47bb-b7e3-dd41be7747c2",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#1 Function to retrieve rentals for a specific month and year\n",
+ "\n",
+ "def rentals_month(engine, month, year):\n",
+ " query = f\"\"\"\n",
+ " SELECT *\n",
+ " FROM rental\n",
+ " WHERE MONTH(rental_date) = {month}\n",
+ " AND YEAR(rental_date) = {year};\n",
+ " \"\"\"\n",
+ " rentals_df = pd.read_sql(query, engine)\n",
+ " return rentals_df"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "id": "78fb9654-451e-4e3b-a344-a72a0b10a709",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "C:\\Users\\manda\\AppData\\Local\\Temp\\ipykernel_27804\\1474216370.py:10: UserWarning: pandas only supports SQLAlchemy connectable (engine/connection) or database string URI or sqlite3 DBAPI2 connection. Other DBAPI2 objects are not tested. Please consider using SQLAlchemy.\n",
+ " rentals_df = pd.read_sql(query, engine)\n"
+ ]
+ },
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " rental_id | \n",
+ " rental_date | \n",
+ " inventory_id | \n",
+ " customer_id | \n",
+ " return_date | \n",
+ " staff_id | \n",
+ " last_update | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 1 | \n",
+ " 2005-05-24 22:53:30 | \n",
+ " 367 | \n",
+ " 130 | \n",
+ " 2005-05-26 22:04:30 | \n",
+ " 1 | \n",
+ " 2006-02-15 21:30:53 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 2 | \n",
+ " 2005-05-24 22:54:33 | \n",
+ " 1525 | \n",
+ " 459 | \n",
+ " 2005-05-28 19:40:33 | \n",
+ " 1 | \n",
+ " 2006-02-15 21:30:53 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 3 | \n",
+ " 2005-05-24 23:03:39 | \n",
+ " 1711 | \n",
+ " 408 | \n",
+ " 2005-06-01 22:12:39 | \n",
+ " 1 | \n",
+ " 2006-02-15 21:30:53 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 4 | \n",
+ " 2005-05-24 23:04:41 | \n",
+ " 2452 | \n",
+ " 333 | \n",
+ " 2005-06-03 01:43:41 | \n",
+ " 2 | \n",
+ " 2006-02-15 21:30:53 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 5 | \n",
+ " 2005-05-24 23:05:21 | \n",
+ " 2079 | \n",
+ " 222 | \n",
+ " 2005-06-02 04:33:21 | \n",
+ " 1 | \n",
+ " 2006-02-15 21:30:53 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " rental_id rental_date inventory_id customer_id \\\n",
+ "0 1 2005-05-24 22:53:30 367 130 \n",
+ "1 2 2005-05-24 22:54:33 1525 459 \n",
+ "2 3 2005-05-24 23:03:39 1711 408 \n",
+ "3 4 2005-05-24 23:04:41 2452 333 \n",
+ "4 5 2005-05-24 23:05:21 2079 222 \n",
+ "\n",
+ " return_date staff_id last_update \n",
+ "0 2005-05-26 22:04:30 1 2006-02-15 21:30:53 \n",
+ "1 2005-05-28 19:40:33 1 2006-02-15 21:30:53 \n",
+ "2 2005-06-01 22:12:39 1 2006-02-15 21:30:53 \n",
+ "3 2005-06-03 01:43:41 2 2006-02-15 21:30:53 \n",
+ "4 2005-06-02 04:33:21 1 2006-02-15 21:30:53 "
+ ]
+ },
+ "execution_count": 7,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "#2 Retrieve May 2005 rentals\n",
+ "may_rentals = rentals_month(connection, 5, 2005)\n",
+ "may_rentals.head()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "id": "2cab297c-1f86-4abb-aeee-4f82843b6d9b",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "C:\\Users\\manda\\AppData\\Local\\Temp\\ipykernel_27804\\1474216370.py:10: UserWarning: pandas only supports SQLAlchemy connectable (engine/connection) or database string URI or sqlite3 DBAPI2 connection. Other DBAPI2 objects are not tested. Please consider using SQLAlchemy.\n",
+ " rentals_df = pd.read_sql(query, engine)\n"
+ ]
+ },
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " rental_id | \n",
+ " rental_date | \n",
+ " inventory_id | \n",
+ " customer_id | \n",
+ " return_date | \n",
+ " staff_id | \n",
+ " last_update | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 1158 | \n",
+ " 2005-06-14 22:53:33 | \n",
+ " 1632 | \n",
+ " 416 | \n",
+ " 2005-06-18 21:37:33 | \n",
+ " 2 | \n",
+ " 2006-02-15 21:30:53 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 1159 | \n",
+ " 2005-06-14 22:55:13 | \n",
+ " 4395 | \n",
+ " 516 | \n",
+ " 2005-06-17 02:11:13 | \n",
+ " 1 | \n",
+ " 2006-02-15 21:30:53 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 1160 | \n",
+ " 2005-06-14 23:00:34 | \n",
+ " 2795 | \n",
+ " 239 | \n",
+ " 2005-06-18 01:58:34 | \n",
+ " 2 | \n",
+ " 2006-02-15 21:30:53 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 1161 | \n",
+ " 2005-06-14 23:07:08 | \n",
+ " 1690 | \n",
+ " 285 | \n",
+ " 2005-06-21 17:12:08 | \n",
+ " 1 | \n",
+ " 2006-02-15 21:30:53 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 1162 | \n",
+ " 2005-06-14 23:09:38 | \n",
+ " 987 | \n",
+ " 310 | \n",
+ " 2005-06-23 22:00:38 | \n",
+ " 1 | \n",
+ " 2006-02-15 21:30:53 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " rental_id rental_date inventory_id customer_id \\\n",
+ "0 1158 2005-06-14 22:53:33 1632 416 \n",
+ "1 1159 2005-06-14 22:55:13 4395 516 \n",
+ "2 1160 2005-06-14 23:00:34 2795 239 \n",
+ "3 1161 2005-06-14 23:07:08 1690 285 \n",
+ "4 1162 2005-06-14 23:09:38 987 310 \n",
+ "\n",
+ " return_date staff_id last_update \n",
+ "0 2005-06-18 21:37:33 2 2006-02-15 21:30:53 \n",
+ "1 2005-06-17 02:11:13 1 2006-02-15 21:30:53 \n",
+ "2 2005-06-18 01:58:34 2 2006-02-15 21:30:53 \n",
+ "3 2005-06-21 17:12:08 1 2006-02-15 21:30:53 \n",
+ "4 2005-06-23 22:00:38 1 2006-02-15 21:30:53 "
+ ]
+ },
+ "execution_count": 8,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# 3 Retrieve June 2005 rentals\n",
+ "june_rentals = rentals_month(connection, 6, 2005)\n",
+ "june_rentals.head()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "id": "fe7874e1-ec44-41e2-9687-aea7ff4b05fd",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "May rentals: (1156, 7)\n",
+ "June rentals: (2311, 7)\n"
+ ]
+ }
+ ],
+ "source": [
+ "#4 Check the shape of both DataFrames\n",
+ "print(\"May rentals:\", may_rentals.shape)\n",
+ "print(\"June rentals:\", june_rentals.shape)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "id": "0ceb15e6-4efd-49f9-bbc4-ff771b49e2c2",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " customer_id | \n",
+ " may_rentals | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 1 | \n",
+ " 2 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 2 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 3 | \n",
+ " 2 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 5 | \n",
+ " 3 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 6 | \n",
+ " 3 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " customer_id may_rentals\n",
+ "0 1 2\n",
+ "1 2 1\n",
+ "2 3 2\n",
+ "3 5 3\n",
+ "4 6 3"
+ ]
+ },
+ "execution_count": 10,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "#5 Count rentals per customer in May\n",
+ "may_customer_activity = (\n",
+ " may_rentals\n",
+ " .groupby(\"customer_id\")\n",
+ " .size()\n",
+ " .reset_index(name=\"may_rentals\")\n",
+ ")\n",
+ "may_customer_activity.head()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "id": "8687b6d3-19c7-4926-8eb1-f65ba1ac945c",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " customer_id | \n",
+ " june_rentals | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 1 | \n",
+ " 7 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 2 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 3 | \n",
+ " 4 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 4 | \n",
+ " 6 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 5 | \n",
+ " 5 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " customer_id june_rentals\n",
+ "0 1 7\n",
+ "1 2 1\n",
+ "2 3 4\n",
+ "3 4 6\n",
+ "4 5 5"
+ ]
+ },
+ "execution_count": 11,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "#6 Count rentals per customer in June\n",
+ "\n",
+ "june_customer_activity = (\n",
+ " june_rentals\n",
+ " .groupby(\"customer_id\")\n",
+ " .size()\n",
+ " .reset_index(name=\"june_rentals\")\n",
+ ")\n",
+ "june_customer_activity.head()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 12,
+ "id": "a5ef88d3-a63e-4ea3-84e8-b6b1092c60f2",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " customer_id | \n",
+ " may_rentals | \n",
+ " june_rentals | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 1 | \n",
+ " 2 | \n",
+ " 7 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 2 | \n",
+ " 1 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 3 | \n",
+ " 2 | \n",
+ " 4 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 5 | \n",
+ " 3 | \n",
+ " 5 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 6 | \n",
+ " 3 | \n",
+ " 4 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " customer_id may_rentals june_rentals\n",
+ "0 1 2 7\n",
+ "1 2 1 1\n",
+ "2 3 2 4\n",
+ "3 5 3 5\n",
+ "4 6 3 4"
+ ]
+ },
+ "execution_count": 12,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "#7 Find customers active in both May and June\n",
+ "\n",
+ "active_both_months = pd.merge(\n",
+ " may_customer_activity,\n",
+ " june_customer_activity,\n",
+ " on=\"customer_id\",\n",
+ " how=\"inner\"\n",
+ ")\n",
+ "active_both_months.head()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "id": "f54a9815-8c38-4d66-ad33-824c479c4697",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " customer_id | \n",
+ " may_rentals | \n",
+ " june_rentals | \n",
+ " difference | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 1 | \n",
+ " 2 | \n",
+ " 7 | \n",
+ " 5 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 2 | \n",
+ " 1 | \n",
+ " 1 | \n",
+ " 0 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 3 | \n",
+ " 2 | \n",
+ " 4 | \n",
+ " 2 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 5 | \n",
+ " 3 | \n",
+ " 5 | \n",
+ " 2 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 6 | \n",
+ " 3 | \n",
+ " 4 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " customer_id may_rentals june_rentals difference\n",
+ "0 1 2 7 5\n",
+ "1 2 1 1 0\n",
+ "2 3 2 4 2\n",
+ "3 5 3 5 2\n",
+ "4 6 3 4 1"
+ ]
+ },
+ "execution_count": 13,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "#8 Compare customer activity between June and May\n",
+ "\n",
+ "active_both_months[\"difference\"] = (\n",
+ " active_both_months[\"june_rentals\"] \n",
+ " - active_both_months[\"may_rentals\"]\n",
+ ")\n",
+ "\n",
+ "active_both_months.head()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
+ "id": "239afbe1-0784-4f21-ad96-40b5c7f2daf9",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "C:\\Users\\manda\\AppData\\Local\\Temp\\ipykernel_27804\\1945799371.py:3: UserWarning: pandas only supports SQLAlchemy connectable (engine/connection) or database string URI or sqlite3 DBAPI2 connection. Other DBAPI2 objects are not tested. Please consider using SQLAlchemy.\n",
+ " customer_df = pd.read_sql(\n"
+ ]
+ },
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " customer_id | \n",
+ " may_rentals | \n",
+ " june_rentals | \n",
+ " difference | \n",
+ " first_name | \n",
+ " last_name | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 1 | \n",
+ " 2 | \n",
+ " 7 | \n",
+ " 5 | \n",
+ " MARY | \n",
+ " SMITH | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 2 | \n",
+ " 1 | \n",
+ " 1 | \n",
+ " 0 | \n",
+ " PATRICIA | \n",
+ " JOHNSON | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 3 | \n",
+ " 2 | \n",
+ " 4 | \n",
+ " 2 | \n",
+ " LINDA | \n",
+ " WILLIAMS | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 5 | \n",
+ " 3 | \n",
+ " 5 | \n",
+ " 2 | \n",
+ " ELIZABETH | \n",
+ " BROWN | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 6 | \n",
+ " 3 | \n",
+ " 4 | \n",
+ " 1 | \n",
+ " JENNIFER | \n",
+ " DAVIS | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " customer_id may_rentals june_rentals difference first_name last_name\n",
+ "0 1 2 7 5 MARY SMITH\n",
+ "1 2 1 1 0 PATRICIA JOHNSON\n",
+ "2 3 2 4 2 LINDA WILLIAMS\n",
+ "3 5 3 5 2 ELIZABETH BROWN\n",
+ "4 6 3 4 1 JENNIFER DAVIS"
+ ]
+ },
+ "execution_count": 14,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "#9 Add customer names\n",
+ "\n",
+ "customer_df = pd.read_sql(\n",
+ " \"\"\"\n",
+ " SELECT \n",
+ " customer_id,\n",
+ " first_name,\n",
+ " last_name\n",
+ " FROM customer;\n",
+ " \"\"\",\n",
+ " connection\n",
+ ")\n",
+ "\n",
+ "final_df = pd.merge(\n",
+ " active_both_months,\n",
+ " customer_df,\n",
+ " on=\"customer_id\",\n",
+ " how=\"left\"\n",
+ ")\n",
+ "\n",
+ "final_df.head()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 15,
+ "id": "9bd72030-7668-4740-ab48-11fc05a4141b",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " customer_id | \n",
+ " first_name | \n",
+ " last_name | \n",
+ " may_rentals | \n",
+ " june_rentals | \n",
+ " difference | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 1 | \n",
+ " MARY | \n",
+ " SMITH | \n",
+ " 2 | \n",
+ " 7 | \n",
+ " 5 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 2 | \n",
+ " PATRICIA | \n",
+ " JOHNSON | \n",
+ " 1 | \n",
+ " 1 | \n",
+ " 0 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 3 | \n",
+ " LINDA | \n",
+ " WILLIAMS | \n",
+ " 2 | \n",
+ " 4 | \n",
+ " 2 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 5 | \n",
+ " ELIZABETH | \n",
+ " BROWN | \n",
+ " 3 | \n",
+ " 5 | \n",
+ " 2 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 6 | \n",
+ " JENNIFER | \n",
+ " DAVIS | \n",
+ " 3 | \n",
+ " 4 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " customer_id first_name last_name may_rentals june_rentals difference\n",
+ "0 1 MARY SMITH 2 7 5\n",
+ "1 2 PATRICIA JOHNSON 1 1 0\n",
+ "2 3 LINDA WILLIAMS 2 4 2\n",
+ "3 5 ELIZABETH BROWN 3 5 2\n",
+ "4 6 JENNIFER DAVIS 3 4 1"
+ ]
+ },
+ "execution_count": 15,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "#10 Reorder columns\n",
+ "\n",
+ "final_df = final_df[\n",
+ " [\n",
+ " \"customer_id\",\n",
+ " \"first_name\",\n",
+ " \"last_name\",\n",
+ " \"may_rentals\",\n",
+ " \"june_rentals\",\n",
+ " \"difference\"\n",
+ " ]\n",
+ "]\n",
+ "\n",
+ "final_df.head()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 16,
+ "id": "d83ad443-381d-4b3e-9b20-fc99f418aaa7",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " customer_id | \n",
+ " first_name | \n",
+ " last_name | \n",
+ " may_rentals | \n",
+ " june_rentals | \n",
+ " difference | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 386 | \n",
+ " 454 | \n",
+ " ALEX | \n",
+ " GRESHAM | \n",
+ " 1 | \n",
+ " 10 | \n",
+ " 9 | \n",
+ "
\n",
+ " \n",
+ " | 178 | \n",
+ " 213 | \n",
+ " GINA | \n",
+ " WILLIAMSON | \n",
+ " 1 | \n",
+ " 9 | \n",
+ " 8 | \n",
+ "
\n",
+ " \n",
+ " | 248 | \n",
+ " 295 | \n",
+ " DAISY | \n",
+ " BATES | \n",
+ " 1 | \n",
+ " 9 | \n",
+ " 8 | \n",
+ "
\n",
+ " \n",
+ " | 389 | \n",
+ " 457 | \n",
+ " BILL | \n",
+ " GAVIN | \n",
+ " 1 | \n",
+ " 9 | \n",
+ " 8 | \n",
+ "
\n",
+ " \n",
+ " | 322 | \n",
+ " 380 | \n",
+ " RUSSELL | \n",
+ " BRINSON | \n",
+ " 1 | \n",
+ " 8 | \n",
+ " 7 | \n",
+ "
\n",
+ " \n",
+ " | 194 | \n",
+ " 234 | \n",
+ " CLAUDIA | \n",
+ " FULLER | \n",
+ " 1 | \n",
+ " 8 | \n",
+ " 7 | \n",
+ "
\n",
+ " \n",
+ " | 218 | \n",
+ " 260 | \n",
+ " CHRISTY | \n",
+ " VARGAS | \n",
+ " 1 | \n",
+ " 8 | \n",
+ " 7 | \n",
+ "
\n",
+ " \n",
+ " | 481 | \n",
+ " 561 | \n",
+ " IAN | \n",
+ " STILL | \n",
+ " 2 | \n",
+ " 9 | \n",
+ " 7 | \n",
+ "
\n",
+ " \n",
+ " | 23 | \n",
+ " 27 | \n",
+ " SHIRLEY | \n",
+ " ALLEN | \n",
+ " 1 | \n",
+ " 8 | \n",
+ " 7 | \n",
+ "
\n",
+ " \n",
+ " | 224 | \n",
+ " 267 | \n",
+ " MARGIE | \n",
+ " WADE | \n",
+ " 3 | \n",
+ " 9 | \n",
+ " 6 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " customer_id first_name last_name may_rentals june_rentals difference\n",
+ "386 454 ALEX GRESHAM 1 10 9\n",
+ "178 213 GINA WILLIAMSON 1 9 8\n",
+ "248 295 DAISY BATES 1 9 8\n",
+ "389 457 BILL GAVIN 1 9 8\n",
+ "322 380 RUSSELL BRINSON 1 8 7\n",
+ "194 234 CLAUDIA FULLER 1 8 7\n",
+ "218 260 CHRISTY VARGAS 1 8 7\n",
+ "481 561 IAN STILL 2 9 7\n",
+ "23 27 SHIRLEY ALLEN 1 8 7\n",
+ "224 267 MARGIE WADE 3 9 6"
+ ]
+ },
+ "execution_count": 16,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# 11 Sort by biggest increase in activity\n",
+ "final_df.sort_values(by=\"difference\", ascending=False).head(10)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 17,
+ "id": "b920ac0b-30a9-4303-b80c-dd4c3303497b",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "###STEP 3"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 18,
+ "id": "d1365b11-f43a-4c71-acba-6d292fb96269",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# 1 Function: rental_count_month\n",
+ "\n",
+ "def rental_count_month(df, month, year):\n",
+ " \n",
+ " # Create dynamic column name\n",
+ " column_name = f\"rentals_{month:02d}_{year}\"\n",
+ " \n",
+ " # Count rentals by customer_id\n",
+ " rental_count_df = (\n",
+ " df.groupby(\"customer_id\")\n",
+ " .size()\n",
+ " .reset_index(name=column_name)\n",
+ " )\n",
+ " \n",
+ " return rental_count_df"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 19,
+ "id": "33b3f0e1-3625-4a46-8906-399c63f00683",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " customer_id | \n",
+ " rentals_05_2005 | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 1 | \n",
+ " 2 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 2 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 3 | \n",
+ " 2 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 5 | \n",
+ " 3 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 6 | \n",
+ " 3 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " customer_id rentals_05_2005\n",
+ "0 1 2\n",
+ "1 2 1\n",
+ "2 3 2\n",
+ "3 5 3\n",
+ "4 6 3"
+ ]
+ },
+ "execution_count": 19,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "#2 function for May 2005\n",
+ "may_rental_counts = rental_count_month(\n",
+ " may_rentals,\n",
+ " 5,\n",
+ " 2005\n",
+ ")\n",
+ "may_rental_counts.head()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 20,
+ "id": "b2ff114f-e961-438c-a203-5161297d349b",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " customer_id | \n",
+ " rentals_06_2005 | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 1 | \n",
+ " 7 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 2 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 3 | \n",
+ " 4 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 4 | \n",
+ " 6 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 5 | \n",
+ " 5 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " customer_id rentals_06_2005\n",
+ "0 1 7\n",
+ "1 2 1\n",
+ "2 3 4\n",
+ "3 4 6\n",
+ "4 5 5"
+ ]
+ },
+ "execution_count": 20,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "#3 function for June 2005\n",
+ "june_rental_counts = rental_count_month(\n",
+ " june_rentals,\n",
+ " 6,\n",
+ " 2005\n",
+ ")\n",
+ "june_rental_counts.head()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 21,
+ "id": "85e80cf0-b588-43c4-8fbd-9a8304f500dc",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " customer_id | \n",
+ " rentals_05_2005 | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 1 | \n",
+ " 2 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 2 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 3 | \n",
+ " 2 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 5 | \n",
+ " 3 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 6 | \n",
+ " 3 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " customer_id rentals_05_2005\n",
+ "0 1 2\n",
+ "1 2 1\n",
+ "2 3 2\n",
+ "3 5 3\n",
+ "4 6 3"
+ ]
+ },
+ "execution_count": 21,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "#4\n",
+ "may_rental_counts = rental_count_month(may_rentals, 5, 2005)\n",
+ "may_rental_counts.head()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 22,
+ "id": "f1b58354-0285-4360-890d-d6bd308103fc",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "### STEP 4"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 23,
+ "id": "3ee23b04-f683-4c24-b1a8-691da8c0ece3",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#1 Function compare_rentals\n",
+ "\n",
+ "def compare_rentals(df1, df2):\n",
+ " \n",
+ "# Merge both DataFrames using customer_id\n",
+ " comparison_df = pd.merge(\n",
+ " df1,\n",
+ " df2,\n",
+ " on=\"customer_id\",\n",
+ " how=\"inner\"\n",
+ " )\n",
+ " \n",
+ "# Get rental column names automatically\n",
+ " rental_col_1 = comparison_df.columns[1]\n",
+ " rental_col_2 = comparison_df.columns[2]\n",
+ " \n",
+ "# Create difference column\n",
+ " comparison_df[\"difference\"] = (\n",
+ " comparison_df[rental_col_2]\n",
+ " - comparison_df[rental_col_1]\n",
+ " )\n",
+ " return comparison_df"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 24,
+ "id": "972eeafd-0fb5-40ec-884a-c338973461bb",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " customer_id | \n",
+ " rentals_05_2005 | \n",
+ " rentals_06_2005 | \n",
+ " difference | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 1 | \n",
+ " 2 | \n",
+ " 7 | \n",
+ " 5 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 2 | \n",
+ " 1 | \n",
+ " 1 | \n",
+ " 0 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 3 | \n",
+ " 2 | \n",
+ " 4 | \n",
+ " 2 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 5 | \n",
+ " 3 | \n",
+ " 5 | \n",
+ " 2 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 6 | \n",
+ " 3 | \n",
+ " 4 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " customer_id rentals_05_2005 rentals_06_2005 difference\n",
+ "0 1 2 7 5\n",
+ "1 2 1 1 0\n",
+ "2 3 2 4 2\n",
+ "3 5 3 5 2\n",
+ "4 6 3 4 1"
+ ]
+ },
+ "execution_count": 24,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "#2 Compare May and June rentals\n",
+ "\n",
+ "comparison = compare_rentals(\n",
+ " may_rental_counts,\n",
+ " june_rental_counts\n",
+ ")\n",
+ "comparison.head()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 25,
+ "id": "a59d3248-8f0c-4bb9-b3ad-f1cd2bbb3550",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " customer_id | \n",
+ " rentals_05_2005 | \n",
+ " rentals_06_2005 | \n",
+ " difference | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 386 | \n",
+ " 454 | \n",
+ " 1 | \n",
+ " 10 | \n",
+ " 9 | \n",
+ "
\n",
+ " \n",
+ " | 178 | \n",
+ " 213 | \n",
+ " 1 | \n",
+ " 9 | \n",
+ " 8 | \n",
+ "
\n",
+ " \n",
+ " | 248 | \n",
+ " 295 | \n",
+ " 1 | \n",
+ " 9 | \n",
+ " 8 | \n",
+ "
\n",
+ " \n",
+ " | 389 | \n",
+ " 457 | \n",
+ " 1 | \n",
+ " 9 | \n",
+ " 8 | \n",
+ "
\n",
+ " \n",
+ " | 322 | \n",
+ " 380 | \n",
+ " 1 | \n",
+ " 8 | \n",
+ " 7 | \n",
+ "
\n",
+ " \n",
+ " | ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ "
\n",
+ " \n",
+ " | 11 | \n",
+ " 14 | \n",
+ " 5 | \n",
+ " 1 | \n",
+ " -4 | \n",
+ "
\n",
+ " \n",
+ " | 509 | \n",
+ " 596 | \n",
+ " 6 | \n",
+ " 2 | \n",
+ " -4 | \n",
+ "
\n",
+ " \n",
+ " | 210 | \n",
+ " 250 | \n",
+ " 5 | \n",
+ " 1 | \n",
+ " -4 | \n",
+ "
\n",
+ " \n",
+ " | 136 | \n",
+ " 161 | \n",
+ " 6 | \n",
+ " 2 | \n",
+ " -4 | \n",
+ "
\n",
+ " \n",
+ " | 173 | \n",
+ " 207 | \n",
+ " 6 | \n",
+ " 1 | \n",
+ " -5 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
512 rows × 4 columns
\n",
+ "
"
+ ],
+ "text/plain": [
+ " customer_id rentals_05_2005 rentals_06_2005 difference\n",
+ "386 454 1 10 9\n",
+ "178 213 1 9 8\n",
+ "248 295 1 9 8\n",
+ "389 457 1 9 8\n",
+ "322 380 1 8 7\n",
+ ".. ... ... ... ...\n",
+ "11 14 5 1 -4\n",
+ "509 596 6 2 -4\n",
+ "210 250 5 1 -4\n",
+ "136 161 6 2 -4\n",
+ "173 207 6 1 -5\n",
+ "\n",
+ "[512 rows x 4 columns]"
+ ]
+ },
+ "execution_count": 25,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "#3\n",
+ "comparison.sort_values(by=\"difference\", ascending=False)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "bc44a35f-3cef-47f8-9d6b-0f08e0a30d64",
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "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.13.5"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 5
+}