diff --git a/.ipynb_checkpoints/SQL_9_python-checkpoint.ipynb b/.ipynb_checkpoints/SQL_9_python-checkpoint.ipynb
new file mode 100644
index 0000000..b246213
--- /dev/null
+++ b/.ipynb_checkpoints/SQL_9_python-checkpoint.ipynb
@@ -0,0 +1,660 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "id": "0cac804b",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Requirement already satisfied: mysql.connector in c:\\users\\pedro gomes\\anaconda3\\lib\\site-packages (2.2.9)\n",
+ "Requirement already satisfied: mysql.connector.python in c:\\users\\pedro gomes\\anaconda3\\lib\\site-packages (8.2.0)\n",
+ "Requirement already satisfied: protobuf<=4.21.12,>=4.21.1 in c:\\users\\pedro gomes\\anaconda3\\lib\\site-packages (from mysql.connector.python) (4.21.12)\n",
+ "Requirement already satisfied: sqlalchemy in c:\\users\\pedro gomes\\anaconda3\\lib\\site-packages (1.4.22)\n",
+ "Requirement already satisfied: greenlet!=0.4.17 in c:\\users\\pedro gomes\\anaconda3\\lib\\site-packages (from sqlalchemy) (1.1.1)\n",
+ "Requirement already satisfied: pymysql in c:\\users\\pedro gomes\\anaconda3\\lib\\site-packages (1.1.0)\n"
+ ]
+ }
+ ],
+ "source": [
+ "\n",
+ "!pip install mysql.connector\n",
+ "!pip install mysql.connector.python\n",
+ "!pip install sqlalchemy\n",
+ "!pip install pymysql\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "id": "a78c4743",
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [],
+ "source": [
+ "import pymysql\n",
+ "from sqlalchemy import create_engine\n",
+ "import pandas as pd"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "id": "89e210be",
+ "metadata": {
+ "scrolled": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "········\n"
+ ]
+ }
+ ],
+ "source": [
+ "import getpass # To get the password without showing the input\n",
+ "password = getpass.getpass()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "id": "2d9e5c65",
+ "metadata": {
+ "scrolled": false
+ },
+ "outputs": [],
+ "source": [
+ "connection_string = 'mysql+pymysql://root:' + password + '@localhost/sakila'\n",
+ "engine = create_engine(connection_string)\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "id": "9c8a66a8",
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " customer_full_name | \n",
+ " June_rentals | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " BRENDA WRIGHT | \n",
+ " 11 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " ALEX GRESHAM | \n",
+ " 10 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " FRANK WAGGONER | \n",
+ " 9 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " DAISY BATES | \n",
+ " 9 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " IAN STILL | \n",
+ " 9 | \n",
+ "
\n",
+ " \n",
+ " | ... | \n",
+ " ... | \n",
+ " ... | \n",
+ "
\n",
+ " \n",
+ " | 585 | \n",
+ " FRANCIS SIKES | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " | 586 | \n",
+ " ALLEN BUTTERFIELD | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " | 587 | \n",
+ " GREGORY MAULDIN | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " | 588 | \n",
+ " LAURA RODRIGUEZ | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " | 589 | \n",
+ " ELLEN SIMPSON | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
590 rows × 2 columns
\n",
+ "
"
+ ],
+ "text/plain": [
+ " customer_full_name June_rentals\n",
+ "0 BRENDA WRIGHT 11\n",
+ "1 ALEX GRESHAM 10\n",
+ "2 FRANK WAGGONER 9\n",
+ "3 DAISY BATES 9\n",
+ "4 IAN STILL 9\n",
+ ".. ... ...\n",
+ "585 FRANCIS SIKES 1\n",
+ "586 ALLEN BUTTERFIELD 1\n",
+ "587 GREGORY MAULDIN 1\n",
+ "588 LAURA RODRIGUEZ 1\n",
+ "589 ELLEN SIMPSON 1\n",
+ "\n",
+ "[590 rows x 2 columns]"
+ ]
+ },
+ "execution_count": 4,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "rentals_june = pd.read_sql_query('select * from sakila.customer_rentals_june', engine)\n",
+ "rentals_june"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "id": "1ad03830",
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " customer_full_name | \n",
+ " May_rentals | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " SUE PETERS | \n",
+ " 8 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " LESLIE SEWARD | \n",
+ " 7 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " EDNA WEST | \n",
+ " 7 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " CASSANDRA WALTERS | \n",
+ " 6 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " MINNIE ROMERO | \n",
+ " 6 | \n",
+ "
\n",
+ " \n",
+ " | ... | \n",
+ " ... | \n",
+ " ... | \n",
+ "
\n",
+ " \n",
+ " | 515 | \n",
+ " JOEL FRANCISCO | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " | 516 | \n",
+ " JACK FOUST | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " | 517 | \n",
+ " DOROTHY TAYLOR | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " | 518 | \n",
+ " ANITA MORALES | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " | 519 | \n",
+ " KATHERINE RIVERA | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
520 rows × 2 columns
\n",
+ "
"
+ ],
+ "text/plain": [
+ " customer_full_name May_rentals\n",
+ "0 SUE PETERS 8\n",
+ "1 LESLIE SEWARD 7\n",
+ "2 EDNA WEST 7\n",
+ "3 CASSANDRA WALTERS 6\n",
+ "4 MINNIE ROMERO 6\n",
+ ".. ... ...\n",
+ "515 JOEL FRANCISCO 1\n",
+ "516 JACK FOUST 1\n",
+ "517 DOROTHY TAYLOR 1\n",
+ "518 ANITA MORALES 1\n",
+ "519 KATHERINE RIVERA 1\n",
+ "\n",
+ "[520 rows x 2 columns]"
+ ]
+ },
+ "execution_count": 5,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "rentals_may = pd.read_sql_query('select * from sakila.customer_rentals_may', engine)\n",
+ "rentals_may"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "id": "d18008e9",
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " customer_full_name | \n",
+ " May_rentals | \n",
+ " June_rentals | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " SUE PETERS | \n",
+ " 8 | \n",
+ " 8 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " LESLIE SEWARD | \n",
+ " 7 | \n",
+ " 5 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " EDNA WEST | \n",
+ " 7 | \n",
+ " 5 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " CASSANDRA WALTERS | \n",
+ " 6 | \n",
+ " 3 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " MINNIE ROMERO | \n",
+ " 6 | \n",
+ " 5 | \n",
+ "
\n",
+ " \n",
+ " | ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ "
\n",
+ " \n",
+ " | 507 | \n",
+ " CLAUDIA FULLER | \n",
+ " 1 | \n",
+ " 8 | \n",
+ "
\n",
+ " \n",
+ " | 508 | \n",
+ " JOEL FRANCISCO | \n",
+ " 1 | \n",
+ " 7 | \n",
+ "
\n",
+ " \n",
+ " | 509 | \n",
+ " JACK FOUST | \n",
+ " 1 | \n",
+ " 3 | \n",
+ "
\n",
+ " \n",
+ " | 510 | \n",
+ " DOROTHY TAYLOR | \n",
+ " 1 | \n",
+ " 5 | \n",
+ "
\n",
+ " \n",
+ " | 511 | \n",
+ " ANITA MORALES | \n",
+ " 1 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
512 rows × 3 columns
\n",
+ "
"
+ ],
+ "text/plain": [
+ " customer_full_name May_rentals June_rentals\n",
+ "0 SUE PETERS 8 8\n",
+ "1 LESLIE SEWARD 7 5\n",
+ "2 EDNA WEST 7 5\n",
+ "3 CASSANDRA WALTERS 6 3\n",
+ "4 MINNIE ROMERO 6 5\n",
+ ".. ... ... ...\n",
+ "507 CLAUDIA FULLER 1 8\n",
+ "508 JOEL FRANCISCO 1 7\n",
+ "509 JACK FOUST 1 3\n",
+ "510 DOROTHY TAYLOR 1 5\n",
+ "511 ANITA MORALES 1 1\n",
+ "\n",
+ "[512 rows x 3 columns]"
+ ]
+ },
+ "execution_count": 6,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "rentals_may_june = pd.merge(rentals_may, rentals_june, on='customer_full_name')\n",
+ "rentals_may_june\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "b3a6f3d0",
+ "metadata": {},
+ "source": [
+ "-- 6.Write a function that checks if customer borrowed more or less films in the month of June as compared to May."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "id": "96323349",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def compare_rentals(df, column1, column2):\n",
+ " result = []\n",
+ "\n",
+ " for index, row in df.iterrows():\n",
+ " if row[column1] > row[column2]:\n",
+ " result.append(f\"{column1} is higher\")\n",
+ " elif row[column1] < row[column2]:\n",
+ " result.append(f\"{column2} is higher\")\n",
+ " else:\n",
+ " result.append(\"Rentals in May and June are the same\")\n",
+ "\n",
+ " df['rentals_dif'] = result\n",
+ " return df"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "id": "fc4f7a94",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " customer_full_name | \n",
+ " May_rentals | \n",
+ " June_rentals | \n",
+ " rentals_dif | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " SUE PETERS | \n",
+ " 8 | \n",
+ " 8 | \n",
+ " Rentals in May and June are the same | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " LESLIE SEWARD | \n",
+ " 7 | \n",
+ " 5 | \n",
+ " May_rentals is higher | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " EDNA WEST | \n",
+ " 7 | \n",
+ " 5 | \n",
+ " May_rentals is higher | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " CASSANDRA WALTERS | \n",
+ " 6 | \n",
+ " 3 | \n",
+ " May_rentals is higher | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " MINNIE ROMERO | \n",
+ " 6 | \n",
+ " 5 | \n",
+ " May_rentals is higher | \n",
+ "
\n",
+ " \n",
+ " | ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ "
\n",
+ " \n",
+ " | 507 | \n",
+ " CLAUDIA FULLER | \n",
+ " 1 | \n",
+ " 8 | \n",
+ " June_rentals is higher | \n",
+ "
\n",
+ " \n",
+ " | 508 | \n",
+ " JOEL FRANCISCO | \n",
+ " 1 | \n",
+ " 7 | \n",
+ " June_rentals is higher | \n",
+ "
\n",
+ " \n",
+ " | 509 | \n",
+ " JACK FOUST | \n",
+ " 1 | \n",
+ " 3 | \n",
+ " June_rentals is higher | \n",
+ "
\n",
+ " \n",
+ " | 510 | \n",
+ " DOROTHY TAYLOR | \n",
+ " 1 | \n",
+ " 5 | \n",
+ " June_rentals is higher | \n",
+ "
\n",
+ " \n",
+ " | 511 | \n",
+ " ANITA MORALES | \n",
+ " 1 | \n",
+ " 1 | \n",
+ " Rentals in May and June are the same | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
512 rows × 4 columns
\n",
+ "
"
+ ],
+ "text/plain": [
+ " customer_full_name May_rentals June_rentals \\\n",
+ "0 SUE PETERS 8 8 \n",
+ "1 LESLIE SEWARD 7 5 \n",
+ "2 EDNA WEST 7 5 \n",
+ "3 CASSANDRA WALTERS 6 3 \n",
+ "4 MINNIE ROMERO 6 5 \n",
+ ".. ... ... ... \n",
+ "507 CLAUDIA FULLER 1 8 \n",
+ "508 JOEL FRANCISCO 1 7 \n",
+ "509 JACK FOUST 1 3 \n",
+ "510 DOROTHY TAYLOR 1 5 \n",
+ "511 ANITA MORALES 1 1 \n",
+ "\n",
+ " rentals_dif \n",
+ "0 Rentals in May and June are the same \n",
+ "1 May_rentals is higher \n",
+ "2 May_rentals is higher \n",
+ "3 May_rentals is higher \n",
+ "4 May_rentals is higher \n",
+ ".. ... \n",
+ "507 June_rentals is higher \n",
+ "508 June_rentals is higher \n",
+ "509 June_rentals is higher \n",
+ "510 June_rentals is higher \n",
+ "511 Rentals in May and June are the same \n",
+ "\n",
+ "[512 rows x 4 columns]"
+ ]
+ },
+ "execution_count": 11,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "compare_rentals (rentals_may_june, 'May_rentals', 'June_rentals')"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3 (ipykernel)",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.9.7"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 5
+}
diff --git a/SQL_9_F.sql b/SQL_9_F.sql
new file mode 100644
index 0000000..931534a
--- /dev/null
+++ b/SQL_9_F.sql
@@ -0,0 +1,70 @@
+
+-- In this lab we will find the customers who were active in consecutive months of May and June. Follow the steps to complete the analysis.
+
+-- 1.Create a table `rentals_may` to store the data from rental table with information for the month of May.
+create temporary table sakila.rental_may
+select *, date_format(rental_date, "%M") as month
+from sakila.rental
+where date_format(rental_date, "%M") = 'May';
+
+
+-- to make sure we only have the month of May
+select distinct month
+from sakila.rental_may;
+
+-- 2.Create a table `rentals_june` to store the data from rental table with information for the month of June.
+create temporary table sakila.rental_june
+select *, date_format(rental_date, "%M") as month
+from sakila.rental
+where date_format(rental_date, "%M") = 'June';
+
+select distinct month from sakila.rental_june;
+
+-- 3.Check the number of rentals for each customer for May.
+select * from sakila.rental_may;
+select concat(first_name, ' ', last_name) customer_full_name, count(rental_id) as rental_per_costumer
+from sakila.rental_may rm
+left join sakila.customer c
+on rm.customer_id = c.customer_id
+group by rm.customer_id
+order by count(rental_id) desc;
+
+-- 4. Check the number of rentals for each customer for June.
+select * from sakila.rental_june;
+select concat(first_name, ' ', last_name) customer_full_name, count(rental_id) as rental_per_costumer
+from sakila.rental_june rm
+left join sakila.customer c
+on rm.customer_id = c.customer_id
+group by rm.customer_id
+order by count(rental_id) desc;
+
+
+-- 5. Create a Python connection with SQL database and retrieve the results of the last two queries (also mentioned below) as dataframes:
+ -- a.Check the number of rentals for each customer for May
+create table sakila.customer_rentals_may
+select concat(first_name, ' ', last_name) customer_full_name, count(rental_id) as rental_per_costumer
+from sakila.rental_may rm
+left join sakila.customer c
+on rm.customer_id = c.customer_id
+group by rm.customer_id
+order by count(rental_id) desc;
+
+select* from sakila.customer_rentals_may;
+
+ -- b.Check the number of rentals for each customer for June
+create table sakila.customer_rentals_june
+select concat(first_name, ' ', last_name) customer_full_name, count(rental_id) as rental_per_costumer
+from sakila.rental_june rm
+left join sakila.customer c
+on rm.customer_id = c.customer_id
+group by rm.customer_id
+order by count(rental_id) desc;
+
+select* from sakila.customer_rentals_june;
+select * from sakila.actor;
+
+
+
+-- 6.Write a function that checks if customer borrowed more or less films in the month of June as compared to May.
+ -- **Hint**: For this part, you can create a join between the two dataframes created before, using the merge function available for pandas dataframes.
+ -- Here is a link to the documentation for the [merge function](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.merge.html).
\ No newline at end of file
diff --git a/SQL_9_python.ipynb b/SQL_9_python.ipynb
new file mode 100644
index 0000000..b246213
--- /dev/null
+++ b/SQL_9_python.ipynb
@@ -0,0 +1,660 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "id": "0cac804b",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Requirement already satisfied: mysql.connector in c:\\users\\pedro gomes\\anaconda3\\lib\\site-packages (2.2.9)\n",
+ "Requirement already satisfied: mysql.connector.python in c:\\users\\pedro gomes\\anaconda3\\lib\\site-packages (8.2.0)\n",
+ "Requirement already satisfied: protobuf<=4.21.12,>=4.21.1 in c:\\users\\pedro gomes\\anaconda3\\lib\\site-packages (from mysql.connector.python) (4.21.12)\n",
+ "Requirement already satisfied: sqlalchemy in c:\\users\\pedro gomes\\anaconda3\\lib\\site-packages (1.4.22)\n",
+ "Requirement already satisfied: greenlet!=0.4.17 in c:\\users\\pedro gomes\\anaconda3\\lib\\site-packages (from sqlalchemy) (1.1.1)\n",
+ "Requirement already satisfied: pymysql in c:\\users\\pedro gomes\\anaconda3\\lib\\site-packages (1.1.0)\n"
+ ]
+ }
+ ],
+ "source": [
+ "\n",
+ "!pip install mysql.connector\n",
+ "!pip install mysql.connector.python\n",
+ "!pip install sqlalchemy\n",
+ "!pip install pymysql\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "id": "a78c4743",
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [],
+ "source": [
+ "import pymysql\n",
+ "from sqlalchemy import create_engine\n",
+ "import pandas as pd"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "id": "89e210be",
+ "metadata": {
+ "scrolled": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "········\n"
+ ]
+ }
+ ],
+ "source": [
+ "import getpass # To get the password without showing the input\n",
+ "password = getpass.getpass()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "id": "2d9e5c65",
+ "metadata": {
+ "scrolled": false
+ },
+ "outputs": [],
+ "source": [
+ "connection_string = 'mysql+pymysql://root:' + password + '@localhost/sakila'\n",
+ "engine = create_engine(connection_string)\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "id": "9c8a66a8",
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " customer_full_name | \n",
+ " June_rentals | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " BRENDA WRIGHT | \n",
+ " 11 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " ALEX GRESHAM | \n",
+ " 10 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " FRANK WAGGONER | \n",
+ " 9 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " DAISY BATES | \n",
+ " 9 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " IAN STILL | \n",
+ " 9 | \n",
+ "
\n",
+ " \n",
+ " | ... | \n",
+ " ... | \n",
+ " ... | \n",
+ "
\n",
+ " \n",
+ " | 585 | \n",
+ " FRANCIS SIKES | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " | 586 | \n",
+ " ALLEN BUTTERFIELD | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " | 587 | \n",
+ " GREGORY MAULDIN | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " | 588 | \n",
+ " LAURA RODRIGUEZ | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " | 589 | \n",
+ " ELLEN SIMPSON | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
590 rows × 2 columns
\n",
+ "
"
+ ],
+ "text/plain": [
+ " customer_full_name June_rentals\n",
+ "0 BRENDA WRIGHT 11\n",
+ "1 ALEX GRESHAM 10\n",
+ "2 FRANK WAGGONER 9\n",
+ "3 DAISY BATES 9\n",
+ "4 IAN STILL 9\n",
+ ".. ... ...\n",
+ "585 FRANCIS SIKES 1\n",
+ "586 ALLEN BUTTERFIELD 1\n",
+ "587 GREGORY MAULDIN 1\n",
+ "588 LAURA RODRIGUEZ 1\n",
+ "589 ELLEN SIMPSON 1\n",
+ "\n",
+ "[590 rows x 2 columns]"
+ ]
+ },
+ "execution_count": 4,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "rentals_june = pd.read_sql_query('select * from sakila.customer_rentals_june', engine)\n",
+ "rentals_june"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "id": "1ad03830",
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " customer_full_name | \n",
+ " May_rentals | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " SUE PETERS | \n",
+ " 8 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " LESLIE SEWARD | \n",
+ " 7 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " EDNA WEST | \n",
+ " 7 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " CASSANDRA WALTERS | \n",
+ " 6 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " MINNIE ROMERO | \n",
+ " 6 | \n",
+ "
\n",
+ " \n",
+ " | ... | \n",
+ " ... | \n",
+ " ... | \n",
+ "
\n",
+ " \n",
+ " | 515 | \n",
+ " JOEL FRANCISCO | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " | 516 | \n",
+ " JACK FOUST | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " | 517 | \n",
+ " DOROTHY TAYLOR | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " | 518 | \n",
+ " ANITA MORALES | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " | 519 | \n",
+ " KATHERINE RIVERA | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
520 rows × 2 columns
\n",
+ "
"
+ ],
+ "text/plain": [
+ " customer_full_name May_rentals\n",
+ "0 SUE PETERS 8\n",
+ "1 LESLIE SEWARD 7\n",
+ "2 EDNA WEST 7\n",
+ "3 CASSANDRA WALTERS 6\n",
+ "4 MINNIE ROMERO 6\n",
+ ".. ... ...\n",
+ "515 JOEL FRANCISCO 1\n",
+ "516 JACK FOUST 1\n",
+ "517 DOROTHY TAYLOR 1\n",
+ "518 ANITA MORALES 1\n",
+ "519 KATHERINE RIVERA 1\n",
+ "\n",
+ "[520 rows x 2 columns]"
+ ]
+ },
+ "execution_count": 5,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "rentals_may = pd.read_sql_query('select * from sakila.customer_rentals_may', engine)\n",
+ "rentals_may"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "id": "d18008e9",
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " customer_full_name | \n",
+ " May_rentals | \n",
+ " June_rentals | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " SUE PETERS | \n",
+ " 8 | \n",
+ " 8 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " LESLIE SEWARD | \n",
+ " 7 | \n",
+ " 5 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " EDNA WEST | \n",
+ " 7 | \n",
+ " 5 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " CASSANDRA WALTERS | \n",
+ " 6 | \n",
+ " 3 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " MINNIE ROMERO | \n",
+ " 6 | \n",
+ " 5 | \n",
+ "
\n",
+ " \n",
+ " | ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ "
\n",
+ " \n",
+ " | 507 | \n",
+ " CLAUDIA FULLER | \n",
+ " 1 | \n",
+ " 8 | \n",
+ "
\n",
+ " \n",
+ " | 508 | \n",
+ " JOEL FRANCISCO | \n",
+ " 1 | \n",
+ " 7 | \n",
+ "
\n",
+ " \n",
+ " | 509 | \n",
+ " JACK FOUST | \n",
+ " 1 | \n",
+ " 3 | \n",
+ "
\n",
+ " \n",
+ " | 510 | \n",
+ " DOROTHY TAYLOR | \n",
+ " 1 | \n",
+ " 5 | \n",
+ "
\n",
+ " \n",
+ " | 511 | \n",
+ " ANITA MORALES | \n",
+ " 1 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
512 rows × 3 columns
\n",
+ "
"
+ ],
+ "text/plain": [
+ " customer_full_name May_rentals June_rentals\n",
+ "0 SUE PETERS 8 8\n",
+ "1 LESLIE SEWARD 7 5\n",
+ "2 EDNA WEST 7 5\n",
+ "3 CASSANDRA WALTERS 6 3\n",
+ "4 MINNIE ROMERO 6 5\n",
+ ".. ... ... ...\n",
+ "507 CLAUDIA FULLER 1 8\n",
+ "508 JOEL FRANCISCO 1 7\n",
+ "509 JACK FOUST 1 3\n",
+ "510 DOROTHY TAYLOR 1 5\n",
+ "511 ANITA MORALES 1 1\n",
+ "\n",
+ "[512 rows x 3 columns]"
+ ]
+ },
+ "execution_count": 6,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "rentals_may_june = pd.merge(rentals_may, rentals_june, on='customer_full_name')\n",
+ "rentals_may_june\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "b3a6f3d0",
+ "metadata": {},
+ "source": [
+ "-- 6.Write a function that checks if customer borrowed more or less films in the month of June as compared to May."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "id": "96323349",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def compare_rentals(df, column1, column2):\n",
+ " result = []\n",
+ "\n",
+ " for index, row in df.iterrows():\n",
+ " if row[column1] > row[column2]:\n",
+ " result.append(f\"{column1} is higher\")\n",
+ " elif row[column1] < row[column2]:\n",
+ " result.append(f\"{column2} is higher\")\n",
+ " else:\n",
+ " result.append(\"Rentals in May and June are the same\")\n",
+ "\n",
+ " df['rentals_dif'] = result\n",
+ " return df"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "id": "fc4f7a94",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " customer_full_name | \n",
+ " May_rentals | \n",
+ " June_rentals | \n",
+ " rentals_dif | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " SUE PETERS | \n",
+ " 8 | \n",
+ " 8 | \n",
+ " Rentals in May and June are the same | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " LESLIE SEWARD | \n",
+ " 7 | \n",
+ " 5 | \n",
+ " May_rentals is higher | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " EDNA WEST | \n",
+ " 7 | \n",
+ " 5 | \n",
+ " May_rentals is higher | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " CASSANDRA WALTERS | \n",
+ " 6 | \n",
+ " 3 | \n",
+ " May_rentals is higher | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " MINNIE ROMERO | \n",
+ " 6 | \n",
+ " 5 | \n",
+ " May_rentals is higher | \n",
+ "
\n",
+ " \n",
+ " | ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ "
\n",
+ " \n",
+ " | 507 | \n",
+ " CLAUDIA FULLER | \n",
+ " 1 | \n",
+ " 8 | \n",
+ " June_rentals is higher | \n",
+ "
\n",
+ " \n",
+ " | 508 | \n",
+ " JOEL FRANCISCO | \n",
+ " 1 | \n",
+ " 7 | \n",
+ " June_rentals is higher | \n",
+ "
\n",
+ " \n",
+ " | 509 | \n",
+ " JACK FOUST | \n",
+ " 1 | \n",
+ " 3 | \n",
+ " June_rentals is higher | \n",
+ "
\n",
+ " \n",
+ " | 510 | \n",
+ " DOROTHY TAYLOR | \n",
+ " 1 | \n",
+ " 5 | \n",
+ " June_rentals is higher | \n",
+ "
\n",
+ " \n",
+ " | 511 | \n",
+ " ANITA MORALES | \n",
+ " 1 | \n",
+ " 1 | \n",
+ " Rentals in May and June are the same | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
512 rows × 4 columns
\n",
+ "
"
+ ],
+ "text/plain": [
+ " customer_full_name May_rentals June_rentals \\\n",
+ "0 SUE PETERS 8 8 \n",
+ "1 LESLIE SEWARD 7 5 \n",
+ "2 EDNA WEST 7 5 \n",
+ "3 CASSANDRA WALTERS 6 3 \n",
+ "4 MINNIE ROMERO 6 5 \n",
+ ".. ... ... ... \n",
+ "507 CLAUDIA FULLER 1 8 \n",
+ "508 JOEL FRANCISCO 1 7 \n",
+ "509 JACK FOUST 1 3 \n",
+ "510 DOROTHY TAYLOR 1 5 \n",
+ "511 ANITA MORALES 1 1 \n",
+ "\n",
+ " rentals_dif \n",
+ "0 Rentals in May and June are the same \n",
+ "1 May_rentals is higher \n",
+ "2 May_rentals is higher \n",
+ "3 May_rentals is higher \n",
+ "4 May_rentals is higher \n",
+ ".. ... \n",
+ "507 June_rentals is higher \n",
+ "508 June_rentals is higher \n",
+ "509 June_rentals is higher \n",
+ "510 June_rentals is higher \n",
+ "511 Rentals in May and June are the same \n",
+ "\n",
+ "[512 rows x 4 columns]"
+ ]
+ },
+ "execution_count": 11,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "compare_rentals (rentals_may_june, 'May_rentals', 'June_rentals')"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3 (ipykernel)",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.9.7"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 5
+}