From 8ad5c46733e718eff3a720b00e4291eeaf1026f9 Mon Sep 17 00:00:00 2001 From: estcr Date: Thu, 14 Nov 2024 08:59:58 +0100 Subject: [PATCH 1/2] Solucion lab --- lab-dw-aggregating.ipynb | 963 +++++++++++++++++++++++++++++++++------ 1 file changed, 816 insertions(+), 147 deletions(-) diff --git a/lab-dw-aggregating.ipynb b/lab-dw-aggregating.ipynb index fff3ae5..75c1781 100644 --- a/lab-dw-aggregating.ipynb +++ b/lab-dw-aggregating.ipynb @@ -1,161 +1,830 @@ { - "cells": [ - { - "cell_type": "markdown", - "id": "31969215-2a90-4d8b-ac36-646a7ae13744", - "metadata": { - "id": "31969215-2a90-4d8b-ac36-646a7ae13744" - }, - "source": [ - "# Lab | Data Aggregation and Filtering" - ] - }, - { - "cell_type": "markdown", - "id": "a8f08a52-bec0-439b-99cc-11d3809d8b5d", - "metadata": { - "id": "a8f08a52-bec0-439b-99cc-11d3809d8b5d" - }, - "source": [ - "In this challenge, we will continue to work with customer data from an insurance company. We will use the dataset called marketing_customer_analysis.csv, which can be found at the following link:\n", - "\n", - "https://raw.githubusercontent.com/data-bootcamp-v4/data/main/marketing_customer_analysis.csv\n", - "\n", - "This dataset contains information such as customer demographics, policy details, vehicle information, and the customer's response to the last marketing campaign. Our goal is to explore and analyze this data by first performing data cleaning, formatting, and structuring." - ] - }, - { - "cell_type": "markdown", - "id": "9c98ddc5-b041-4c94-ada1-4dfee5c98e50", - "metadata": { - "id": "9c98ddc5-b041-4c94-ada1-4dfee5c98e50" - }, - "source": [ - "1. Create a new DataFrame that only includes customers who have a total_claim_amount greater than $1,000 and have a response of \"Yes\" to the last marketing campaign." - ] - }, - { - "cell_type": "markdown", - "id": "b9be383e-5165-436e-80c8-57d4c757c8c3", - "metadata": { - "id": "b9be383e-5165-436e-80c8-57d4c757c8c3" - }, - "source": [ - "2. Using the original Dataframe, analyze the average total_claim_amount by each policy type and gender for customers who have responded \"Yes\" to the last marketing campaign. Write your conclusions." - ] - }, - { - "cell_type": "markdown", - "id": "7050f4ac-53c5-4193-a3c0-8699b87196f0", - "metadata": { - "id": "7050f4ac-53c5-4193-a3c0-8699b87196f0" - }, - "source": [ - "3. Analyze the total number of customers who have policies in each state, and then filter the results to only include states where there are more than 500 customers." - ] - }, + "cells": [ + { + "cell_type": "markdown", + "id": "31969215-2a90-4d8b-ac36-646a7ae13744", + "metadata": { + "id": "31969215-2a90-4d8b-ac36-646a7ae13744" + }, + "source": [ + "# Lab | Data Aggregation and Filtering" + ] + }, + { + "cell_type": "markdown", + "id": "a8f08a52-bec0-439b-99cc-11d3809d8b5d", + "metadata": { + "id": "a8f08a52-bec0-439b-99cc-11d3809d8b5d" + }, + "source": [ + "In this challenge, we will continue to work with customer data from an insurance company. We will use the dataset called marketing_customer_analysis.csv, which can be found at the following link:\n", + "\n", + "https://raw.githubusercontent.com/data-bootcamp-v4/data/main/marketing_customer_analysis.csv\n", + "\n", + "This dataset contains information such as customer demographics, policy details, vehicle information, and the customer's response to the last marketing campaign. Our goal is to explore and analyze this data by first performing data cleaning, formatting, and structuring." + ] + }, + { + "cell_type": "markdown", + "id": "9c98ddc5-b041-4c94-ada1-4dfee5c98e50", + "metadata": { + "id": "9c98ddc5-b041-4c94-ada1-4dfee5c98e50" + }, + "source": [ + "1. Create a new DataFrame that only includes customers who have a total_claim_amount greater than $1,000 and have a response of \"Yes\" to the last marketing campaign." + ] + }, + { + "cell_type": "markdown", + "id": "b9be383e-5165-436e-80c8-57d4c757c8c3", + "metadata": { + "id": "b9be383e-5165-436e-80c8-57d4c757c8c3" + }, + "source": [ + "2. Using the original Dataframe, analyze the average total_claim_amount by each policy type and gender for customers who have responded \"Yes\" to the last marketing campaign. Write your conclusions." + ] + }, + { + "cell_type": "markdown", + "id": "7050f4ac-53c5-4193-a3c0-8699b87196f0", + "metadata": { + "id": "7050f4ac-53c5-4193-a3c0-8699b87196f0" + }, + "source": [ + "3. Analyze the total number of customers who have policies in each state, and then filter the results to only include states where there are more than 500 customers." + ] + }, + { + "cell_type": "markdown", + "id": "b60a4443-a1a7-4bbf-b78e-9ccdf9895e0d", + "metadata": { + "id": "b60a4443-a1a7-4bbf-b78e-9ccdf9895e0d" + }, + "source": [ + "4. Find the maximum, minimum, and median customer lifetime value by education level and gender. Write your conclusions." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "e3a940f2", + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "url=\"https://raw.githubusercontent.com/data-bootcamp-v4/data/main/marketing_customer_analysis.csv\"\n", + "df=pd.read_csv(url)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "94d8bc95", + "metadata": {}, + "outputs": [ { - "cell_type": "markdown", - "id": "b60a4443-a1a7-4bbf-b78e-9ccdf9895e0d", - "metadata": { - "id": "b60a4443-a1a7-4bbf-b78e-9ccdf9895e0d" - }, - "source": [ - "4. Find the maximum, minimum, and median customer lifetime value by education level and gender. Write your conclusions." - ] - }, + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "RangeIndex: 10910 entries, 0 to 10909\n", + "Data columns (total 26 columns):\n", + " # Column Non-Null Count Dtype \n", + "--- ------ -------------- ----- \n", + " 0 Unnamed: 0 10910 non-null int64 \n", + " 1 Customer 10910 non-null object \n", + " 2 State 10279 non-null object \n", + " 3 Customer Lifetime Value 10910 non-null float64\n", + " 4 Response 10279 non-null object \n", + " 5 Coverage 10910 non-null object \n", + " 6 Education 10910 non-null object \n", + " 7 Effective To Date 10910 non-null object \n", + " 8 EmploymentStatus 10910 non-null object \n", + " 9 Gender 10910 non-null object \n", + " 10 Income 10910 non-null int64 \n", + " 11 Location Code 10910 non-null object \n", + " 12 Marital Status 10910 non-null object \n", + " 13 Monthly Premium Auto 10910 non-null int64 \n", + " 14 Months Since Last Claim 10277 non-null float64\n", + " 15 Months Since Policy Inception 10910 non-null int64 \n", + " 16 Number of Open Complaints 10277 non-null float64\n", + " 17 Number of Policies 10910 non-null int64 \n", + " 18 Policy Type 10910 non-null object \n", + " 19 Policy 10910 non-null object \n", + " 20 Renew Offer Type 10910 non-null object \n", + " 21 Sales Channel 10910 non-null object \n", + " 22 Total Claim Amount 10910 non-null float64\n", + " 23 Vehicle Class 10288 non-null object \n", + " 24 Vehicle Size 10288 non-null object \n", + " 25 Vehicle Type 5428 non-null object \n", + "dtypes: float64(4), int64(5), object(17)\n", + "memory usage: 2.2+ MB\n" + ] + } + ], + "source": [ + "df.info()" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "10c9d82d", + "metadata": {}, + "outputs": [ { - "cell_type": "markdown", - "id": "b42999f9-311f-481e-ae63-40a5577072c5", - "metadata": { - "id": "b42999f9-311f-481e-ae63-40a5577072c5" - }, - "source": [ - "## Bonus" + "data": { + "text/plain": [ + "Index(['Unnamed: 0', 'Customer', 'State', 'Customer Lifetime Value',\n", + " 'Response', 'Coverage', 'Education', 'Effective To Date',\n", + " 'EmploymentStatus', 'Gender', 'Income', 'Location Code',\n", + " 'Marital Status', 'Monthly Premium Auto', 'Months Since Last Claim',\n", + " 'Months Since Policy Inception', 'Number of Open Complaints',\n", + " 'Number of Policies', 'Policy Type', 'Policy', 'Renew Offer Type',\n", + " 'Sales Channel', 'Total Claim Amount', 'Vehicle Class', 'Vehicle Size',\n", + " 'Vehicle Type'],\n", + " dtype='object')" ] - }, + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.columns" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "b34a3c34", + "metadata": {}, + "outputs": [ { - "cell_type": "markdown", - "id": "81ff02c5-6584-4f21-a358-b918697c6432", - "metadata": { - "id": "81ff02c5-6584-4f21-a358-b918697c6432" - }, - "source": [ - "5. The marketing team wants to analyze the number of policies sold by state and month. Present the data in a table where the months are arranged as columns and the states are arranged as rows." + "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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Unnamed: 0CustomerStateCustomer Lifetime ValueResponseCoverageEducationEffective To DateEmploymentStatusGender...Number of Open ComplaintsNumber of PoliciesPolicy TypePolicyRenew Offer TypeSales ChannelTotal Claim AmountVehicle ClassVehicle SizeVehicle Type
32373237YV55495Arizona5744.229745NoBasicHigh School or Below1/15/11EmployedF...0.06Personal AutoPersonal L1Offer1Branch204.475147Four-Door CarMedsizeA
74577457HI60054NaN9404.447425NaNExtendedBachelor2/1/11EmployedF...NaN2Personal AutoPersonal L2Offer1Agent202.905809Two-Door CarMedsizeNaN
1007510075AK90865Oregon8207.858272NoBasicHigh School or Below2/22/11UnemployedF...0.05Special AutoSpecial L2Offer2Agent686.908270Sports CarMedsizeNaN
36423642AU46443Nevada7517.083811NoBasicBachelor2/28/11UnemployedF...0.03Personal AutoPersonal L3Offer1Agent1178.995926SUVMedsizeA
30983098GK67747Washington4386.277558YesBasicCollege2/11/11RetiredM...0.05Special AutoSpecial L3Offer1Agent321.600000Four-Door CarMedsizeA
496496QD86074Oregon9035.671134YesPremiumHigh School or Below1/21/11EmployedF...NaN9Corporate AutoCorporate L1Offer2Web542.400000Four-Door CarLargeA
17651765MR22119Oregon4430.572112NoBasicHigh School or Below1/7/11EmployedM...0.01Personal AutoPersonal L3Offer4Web537.600000SUVMedsizeNaN
48504850BS26376California7519.133631YesExtendedHigh School or Below2/20/11EmployedM...1.06Corporate AutoCorporate L1Offer1Agent185.355353Four-Door CarMedsizeNaN
28922892XN25550Oregon5345.201117NoExtendedCollege1/2/11EmployedM...0.01Personal AutoPersonal L2Offer4Agent904.813121SUVMedsizeA
129129ZM45168Oregon2398.354197NoBasicCollege2/14/11DisabledM...0.01Personal AutoPersonal L2Offer1Branch423.823547Four-Door CarMedsizeA
\n", + "

10 rows × 26 columns

\n", + "
" + ], + "text/plain": [ + " Unnamed: 0 Customer State Customer Lifetime Value Response \\\n", + "3237 3237 YV55495 Arizona 5744.229745 No \n", + "7457 7457 HI60054 NaN 9404.447425 NaN \n", + "10075 10075 AK90865 Oregon 8207.858272 No \n", + "3642 3642 AU46443 Nevada 7517.083811 No \n", + "3098 3098 GK67747 Washington 4386.277558 Yes \n", + "496 496 QD86074 Oregon 9035.671134 Yes \n", + "1765 1765 MR22119 Oregon 4430.572112 No \n", + "4850 4850 BS26376 California 7519.133631 Yes \n", + "2892 2892 XN25550 Oregon 5345.201117 No \n", + "129 129 ZM45168 Oregon 2398.354197 No \n", + "\n", + " Coverage Education Effective To Date EmploymentStatus \\\n", + "3237 Basic High School or Below 1/15/11 Employed \n", + "7457 Extended Bachelor 2/1/11 Employed \n", + "10075 Basic High School or Below 2/22/11 Unemployed \n", + "3642 Basic Bachelor 2/28/11 Unemployed \n", + "3098 Basic College 2/11/11 Retired \n", + "496 Premium High School or Below 1/21/11 Employed \n", + "1765 Basic High School or Below 1/7/11 Employed \n", + "4850 Extended High School or Below 2/20/11 Employed \n", + "2892 Extended College 1/2/11 Employed \n", + "129 Basic College 2/14/11 Disabled \n", + "\n", + " Gender ... Number of Open Complaints Number of Policies \\\n", + "3237 F ... 0.0 6 \n", + "7457 F ... NaN 2 \n", + "10075 F ... 0.0 5 \n", + "3642 F ... 0.0 3 \n", + "3098 M ... 0.0 5 \n", + "496 F ... NaN 9 \n", + "1765 M ... 0.0 1 \n", + "4850 M ... 1.0 6 \n", + "2892 M ... 0.0 1 \n", + "129 M ... 0.0 1 \n", + "\n", + " Policy Type Policy Renew Offer Type Sales Channel \\\n", + "3237 Personal Auto Personal L1 Offer1 Branch \n", + "7457 Personal Auto Personal L2 Offer1 Agent \n", + "10075 Special Auto Special L2 Offer2 Agent \n", + "3642 Personal Auto Personal L3 Offer1 Agent \n", + "3098 Special Auto Special L3 Offer1 Agent \n", + "496 Corporate Auto Corporate L1 Offer2 Web \n", + "1765 Personal Auto Personal L3 Offer4 Web \n", + "4850 Corporate Auto Corporate L1 Offer1 Agent \n", + "2892 Personal Auto Personal L2 Offer4 Agent \n", + "129 Personal Auto Personal L2 Offer1 Branch \n", + "\n", + " Total Claim Amount Vehicle Class Vehicle Size Vehicle Type \n", + "3237 204.475147 Four-Door Car Medsize A \n", + "7457 202.905809 Two-Door Car Medsize NaN \n", + "10075 686.908270 Sports Car Medsize NaN \n", + "3642 1178.995926 SUV Medsize A \n", + "3098 321.600000 Four-Door Car Medsize A \n", + "496 542.400000 Four-Door Car Large A \n", + "1765 537.600000 SUV Medsize NaN \n", + "4850 185.355353 Four-Door Car Medsize NaN \n", + "2892 904.813121 SUV Medsize A \n", + "129 423.823547 Four-Door Car Medsize A \n", + "\n", + "[10 rows x 26 columns]" ] - }, + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.sample(10)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "d7ff5f54", + "metadata": {}, + "outputs": [ { - "cell_type": "markdown", - "id": "b6aec097-c633-4017-a125-e77a97259cda", - "metadata": { - "id": "b6aec097-c633-4017-a125-e77a97259cda" - }, - "source": [ - "6. Display a new DataFrame that contains the number of policies sold by month, by state, for the top 3 states with the highest number of policies sold.\n", - "\n", - "*Hint:*\n", - "- *To accomplish this, you will first need to group the data by state and month, then count the number of policies sold for each group. Afterwards, you will need to sort the data by the count of policies sold in descending order.*\n", - "- *Next, you will select the top 3 states with the highest number of policies sold.*\n", - "- *Finally, you will create a new DataFrame that contains the number of policies sold by month for each of the top 3 states.*" + "data": { + "text/plain": [ + "array([nan, 'A'], dtype=object)" ] - }, + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df[\"Vehicle Type\"].unique()" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "f39be210", + "metadata": {}, + "outputs": [ { - "cell_type": "markdown", - "id": "ba975b8a-a2cf-4fbf-9f59-ebc381767009", - "metadata": { - "id": "ba975b8a-a2cf-4fbf-9f59-ebc381767009" - }, - "source": [ - "7. The marketing team wants to analyze the effect of different marketing channels on the customer response rate.\n", - "\n", - "Hint: You can use melt to unpivot the data and create a table that shows the customer response rate (those who responded \"Yes\") by marketing channel." - ] - }, + "name": "stdout", + "output_type": "stream", + "text": [ + " Unnamed: 0 Customer State Customer Lifetime Value Response \\\n", + "189 189 OK31456 California 11009.130490 Yes \n", + "236 236 YJ16163 Oregon 11009.130490 Yes \n", + "419 419 GW43195 Oregon 25807.063000 Yes \n", + "442 442 IP94270 Arizona 13736.132500 Yes \n", + "587 587 FJ28407 California 5619.689084 Yes \n", + "... ... ... ... ... ... \n", + "10351 10351 FN44127 Oregon 3508.569533 Yes \n", + "10373 10373 XZ64172 Oregon 10963.957230 Yes \n", + "10487 10487 IX60941 Oregon 3508.569533 Yes \n", + "10565 10565 QO62792 Oregon 7840.165778 Yes \n", + "10708 10708 CK39096 Oregon 5619.689084 Yes \n", + "\n", + " Coverage Education Effective To Date EmploymentStatus \\\n", + "189 Premium Bachelor 1/24/11 Employed \n", + "236 Premium Bachelor 1/24/11 Employed \n", + "419 Extended College 2/13/11 Employed \n", + "442 Premium Master 2/13/11 Disabled \n", + "587 Premium High School or Below 1/26/11 Unemployed \n", + "... ... ... ... ... \n", + "10351 Extended College 1/5/11 Medical Leave \n", + "10373 Premium High School or Below 2/8/11 Employed \n", + "10487 Extended College 1/5/11 Medical Leave \n", + "10565 Extended College 1/14/11 Employed \n", + "10708 Premium High School or Below 1/26/11 Unemployed \n", + "\n", + " Gender ... Number of Open Complaints Number of Policies \\\n", + "189 F ... 0.0 1 \n", + "236 F ... 0.0 1 \n", + "419 F ... 1.0 2 \n", + "442 F ... 0.0 8 \n", + "587 M ... 0.0 1 \n", + "... ... ... ... ... \n", + "10351 M ... 1.0 1 \n", + "10373 M ... 0.0 1 \n", + "10487 M ... 1.0 1 \n", + "10565 M ... 2.0 1 \n", + "10708 M ... 0.0 1 \n", + "\n", + " Policy Type Policy Renew Offer Type Sales Channel \\\n", + "189 Corporate Auto Corporate L3 Offer2 Agent \n", + "236 Special Auto Special L3 Offer2 Agent \n", + "419 Personal Auto Personal L2 Offer1 Branch \n", + "442 Personal Auto Personal L2 Offer1 Web \n", + "587 Personal Auto Personal L1 Offer2 Web \n", + "... ... ... ... ... \n", + "10351 Personal Auto Personal L2 Offer2 Branch \n", + "10373 Corporate Auto Corporate L2 Offer1 Agent \n", + "10487 Personal Auto Personal L3 Offer2 Branch \n", + "10565 Personal Auto Personal L3 Offer2 Agent \n", + "10708 Personal Auto Personal L3 Offer2 Web \n", + "\n", + " Total Claim Amount Vehicle Class Vehicle Size Vehicle Type \n", + "189 1358.400000 Luxury Car Medsize NaN \n", + "236 1358.400000 Luxury Car Medsize A \n", + "419 1027.200000 Luxury Car Small A \n", + "442 1261.319869 SUV Medsize A \n", + "587 1027.000029 SUV Medsize A \n", + "... ... ... ... ... \n", + "10351 1176.278800 Four-Door Car Small NaN \n", + "10373 1324.800000 Luxury SUV Medsize NaN \n", + "10487 1176.278800 Four-Door Car Small NaN \n", + "10565 1008.000000 NaN NaN NaN \n", + "10708 1027.000029 SUV Medsize A \n", + "\n", + "[67 rows x 26 columns]\n" + ] + } + ], + "source": [ + "#1\n", + "# Filtrar el DataFrame\n", + "df_filtrado = df[(df['Total Claim Amount'] > 1000) & (df['Response'] == 'Yes')]\n", + "\n", + "# Mostrar el DataFrame resultante\n", + "print(df_filtrado)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fe5b7cd6", + "metadata": {}, + "outputs": [ { - "cell_type": "markdown", - "id": "e4378d94-48fb-4850-a802-b1bc8f427b2d", - "metadata": { - "id": "e4378d94-48fb-4850-a802-b1bc8f427b2d" - }, - "source": [ - "External Resources for Data Filtering: https://towardsdatascience.com/filtering-data-frames-in-pandas-b570b1f834b9" - ] - }, + "name": "stdout", + "output_type": "stream", + "text": [ + "Policy Type Gender\n", + "Corporate Auto F 433.74\n", + " M 408.58\n", + "Personal Auto F 452.97\n", + " M 457.01\n", + "Special Auto F 453.28\n", + " M 429.53\n", + "Name: Total Claim Amount, dtype: float64\n" + ] + } + ], + "source": [ + "#2\n", + "# Filtrar el DataFrame por clientes que respondieron \"Yes\"\n", + "yes = df[df['Response'] == 'Yes']\n", + "\n", + "# Calcular el monto promedio de Total Claim Amount por Policy Type y Gender\n", + "avg_claim_by_policy_gender = yes.groupby(['Policy Type', 'Gender'])['Total Claim Amount'].mean().round(2)\n", + "\n", + "# Mostrar el resultado en formato de tabla\n", + "print(avg_claim_by_policy_gender)\n", + "\n", + "#No noto conclusiones significativas ya que son todos los resultados muy similares" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "44f356d5", + "metadata": {}, + "outputs": [ { - "cell_type": "code", - "execution_count": null, - "id": "449513f4-0459-46a0-a18d-9398d974c9ad", - "metadata": { - "id": "449513f4-0459-46a0-a18d-9398d974c9ad" - }, - "outputs": [], - "source": [ - "# your code goes here" - ] + "name": "stdout", + "output_type": "stream", + "text": [ + "State\n", + "California 3552\n", + "Oregon 2909\n", + "Arizona 1937\n", + "Nevada 993\n", + "Washington 888\n", + "Name: count, dtype: int64\n" + ] } - ], - "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.13" - }, - "colab": { - "provenance": [] + ], + "source": [ + "#3\n", + "# Contar el número total de clientes por estado\n", + "conteo_por_estado = df['State'].value_counts()\n", + "\n", + "# Filtrar solo los estados con más de 500 clientes\n", + "estados_mas_500 = conteo_por_estado[conteo_por_estado> 500]\n", + "\n", + "# Mostrar el resultado\n", + "print(estados_mas_500)" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "3153c3c5", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " max min median\n", + "Education Gender \n", + "Bachelor F 73225.96 1904.00 5640.51\n", + " M 67907.27 1898.01 5548.03\n", + "College F 61850.19 1898.68 5623.61\n", + " M 61134.68 1918.12 6005.85\n", + "Doctor F 44856.11 2395.57 5332.46\n", + " M 32677.34 2267.60 5577.67\n", + "High School or Below F 55277.45 2144.92 6039.55\n", + " M 83325.38 1940.98 6286.73\n", + "Master F 51016.07 2417.78 5729.86\n", + " M 50568.26 2272.31 5579.10\n" + ] } + ], + "source": [ + "#4\n", + "estadisticas = df.groupby(['Education', 'Gender'])['Customer Lifetime Value'].agg(['max', 'min', 'median']).round(2)\n", + "\n", + "# Mostrar la tabla resultante\n", + "print(estadisticas)" + ] + }, + { + "cell_type": "markdown", + "id": "b42999f9-311f-481e-ae63-40a5577072c5", + "metadata": { + "id": "b42999f9-311f-481e-ae63-40a5577072c5" + }, + "source": [ + "## Bonus" + ] + }, + { + "cell_type": "markdown", + "id": "81ff02c5-6584-4f21-a358-b918697c6432", + "metadata": { + "id": "81ff02c5-6584-4f21-a358-b918697c6432" + }, + "source": [ + "5. The marketing team wants to analyze the number of policies sold by state and month. Present the data in a table where the months are arranged as columns and the states are arranged as rows." + ] + }, + { + "cell_type": "markdown", + "id": "b6aec097-c633-4017-a125-e77a97259cda", + "metadata": { + "id": "b6aec097-c633-4017-a125-e77a97259cda" + }, + "source": [ + "6. Display a new DataFrame that contains the number of policies sold by month, by state, for the top 3 states with the highest number of policies sold.\n", + "\n", + "*Hint:*\n", + "- *To accomplish this, you will first need to group the data by state and month, then count the number of policies sold for each group. Afterwards, you will need to sort the data by the count of policies sold in descending order.*\n", + "- *Next, you will select the top 3 states with the highest number of policies sold.*\n", + "- *Finally, you will create a new DataFrame that contains the number of policies sold by month for each of the top 3 states.*" + ] + }, + { + "cell_type": "markdown", + "id": "ba975b8a-a2cf-4fbf-9f59-ebc381767009", + "metadata": { + "id": "ba975b8a-a2cf-4fbf-9f59-ebc381767009" + }, + "source": [ + "7. The marketing team wants to analyze the effect of different marketing channels on the customer response rate.\n", + "\n", + "Hint: You can use melt to unpivot the data and create a table that shows the customer response rate (those who responded \"Yes\") by marketing channel." + ] + }, + { + "cell_type": "markdown", + "id": "e4378d94-48fb-4850-a802-b1bc8f427b2d", + "metadata": { + "id": "e4378d94-48fb-4850-a802-b1bc8f427b2d" + }, + "source": [ + "External Resources for Data Filtering: https://towardsdatascience.com/filtering-data-frames-in-pandas-b570b1f834b9" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "449513f4-0459-46a0-a18d-9398d974c9ad", + "metadata": { + "id": "449513f4-0459-46a0-a18d-9398d974c9ad" + }, + "outputs": [], + "source": [ + "# your code goes here" + ] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": "base", + "language": "python", + "name": "python3" }, - "nbformat": 4, - "nbformat_minor": 5 -} \ No newline at end of file + "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.3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} From 03a6e2f2844e9d111173eac8c9041d60553bd09f Mon Sep 17 00:00:00 2001 From: estcr Date: Thu, 14 Nov 2024 17:58:07 +0100 Subject: [PATCH 2/2] Update lab-dw-aggregating.ipynb --- lab-dw-aggregating.ipynb | 624 +++++++++++++++++++++++++++++++++------ 1 file changed, 533 insertions(+), 91 deletions(-) diff --git a/lab-dw-aggregating.ipynb b/lab-dw-aggregating.ipynb index 75c1781..2105d17 100644 --- a/lab-dw-aggregating.ipynb +++ b/lab-dw-aggregating.ipynb @@ -547,81 +547,418 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 19, + "id": "8981cc14", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array(['Arizona', 'California', 'Washington', 'Oregon', nan, 'Nevada'],\n", + " dtype=object)" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df[\"State\"].unique()" + ] + }, + { + "cell_type": "code", + "execution_count": 24, "id": "f39be210", "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - " Unnamed: 0 Customer State Customer Lifetime Value Response \\\n", - "189 189 OK31456 California 11009.130490 Yes \n", - "236 236 YJ16163 Oregon 11009.130490 Yes \n", - "419 419 GW43195 Oregon 25807.063000 Yes \n", - "442 442 IP94270 Arizona 13736.132500 Yes \n", - "587 587 FJ28407 California 5619.689084 Yes \n", - "... ... ... ... ... ... \n", - "10351 10351 FN44127 Oregon 3508.569533 Yes \n", - "10373 10373 XZ64172 Oregon 10963.957230 Yes \n", - "10487 10487 IX60941 Oregon 3508.569533 Yes \n", - "10565 10565 QO62792 Oregon 7840.165778 Yes \n", - "10708 10708 CK39096 Oregon 5619.689084 Yes \n", - "\n", - " Coverage Education Effective To Date EmploymentStatus \\\n", - "189 Premium Bachelor 1/24/11 Employed \n", - "236 Premium Bachelor 1/24/11 Employed \n", - "419 Extended College 2/13/11 Employed \n", - "442 Premium Master 2/13/11 Disabled \n", - "587 Premium High School or Below 1/26/11 Unemployed \n", - "... ... ... ... ... \n", - "10351 Extended College 1/5/11 Medical Leave \n", - "10373 Premium High School or Below 2/8/11 Employed \n", - "10487 Extended College 1/5/11 Medical Leave \n", - "10565 Extended College 1/14/11 Employed \n", - "10708 Premium High School or Below 1/26/11 Unemployed \n", - "\n", - " Gender ... Number of Open Complaints Number of Policies \\\n", - "189 F ... 0.0 1 \n", - "236 F ... 0.0 1 \n", - "419 F ... 1.0 2 \n", - "442 F ... 0.0 8 \n", - "587 M ... 0.0 1 \n", - "... ... ... ... ... \n", - "10351 M ... 1.0 1 \n", - "10373 M ... 0.0 1 \n", - "10487 M ... 1.0 1 \n", - "10565 M ... 2.0 1 \n", - "10708 M ... 0.0 1 \n", - "\n", - " Policy Type Policy Renew Offer Type Sales Channel \\\n", - "189 Corporate Auto Corporate L3 Offer2 Agent \n", - "236 Special Auto Special L3 Offer2 Agent \n", - "419 Personal Auto Personal L2 Offer1 Branch \n", - "442 Personal Auto Personal L2 Offer1 Web \n", - "587 Personal Auto Personal L1 Offer2 Web \n", - "... ... ... ... ... \n", - "10351 Personal Auto Personal L2 Offer2 Branch \n", - "10373 Corporate Auto Corporate L2 Offer1 Agent \n", - "10487 Personal Auto Personal L3 Offer2 Branch \n", - "10565 Personal Auto Personal L3 Offer2 Agent \n", - "10708 Personal Auto Personal L3 Offer2 Web \n", - "\n", - " Total Claim Amount Vehicle Class Vehicle Size Vehicle Type \n", - "189 1358.400000 Luxury Car Medsize NaN \n", - "236 1358.400000 Luxury Car Medsize A \n", - "419 1027.200000 Luxury Car Small A \n", - "442 1261.319869 SUV Medsize A \n", - "587 1027.000029 SUV Medsize A \n", - "... ... ... ... ... \n", - "10351 1176.278800 Four-Door Car Small NaN \n", - "10373 1324.800000 Luxury SUV Medsize NaN \n", - "10487 1176.278800 Four-Door Car Small NaN \n", - "10565 1008.000000 NaN NaN NaN \n", - "10708 1027.000029 SUV Medsize A \n", - "\n", - "[67 rows x 26 columns]\n" - ] + "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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Unnamed: 0CustomerStateCustomer Lifetime ValueResponseCoverageEducationEffective To DateEmploymentStatusGender...Number of Open ComplaintsNumber of PoliciesPolicy TypePolicyRenew Offer TypeSales ChannelTotal Claim AmountVehicle ClassVehicle SizeVehicle Type
189189OK31456California11009.130490YesPremiumBachelor1/24/11EmployedF...0.01Corporate AutoCorporate L3Offer2Agent1358.400000Luxury CarMedsizeNaN
236236YJ16163Oregon11009.130490YesPremiumBachelor1/24/11EmployedF...0.01Special AutoSpecial L3Offer2Agent1358.400000Luxury CarMedsizeA
419419GW43195Oregon25807.063000YesExtendedCollege2/13/11EmployedF...1.02Personal AutoPersonal L2Offer1Branch1027.200000Luxury CarSmallA
442442IP94270Arizona13736.132500YesPremiumMaster2/13/11DisabledF...0.08Personal AutoPersonal L2Offer1Web1261.319869SUVMedsizeA
587587FJ28407California5619.689084YesPremiumHigh School or Below1/26/11UnemployedM...0.01Personal AutoPersonal L1Offer2Web1027.000029SUVMedsizeA
..................................................................
1035110351FN44127Oregon3508.569533YesExtendedCollege1/5/11Medical LeaveM...1.01Personal AutoPersonal L2Offer2Branch1176.278800Four-Door CarSmallNaN
1037310373XZ64172Oregon10963.957230YesPremiumHigh School or Below2/8/11EmployedM...0.01Corporate AutoCorporate L2Offer1Agent1324.800000Luxury SUVMedsizeNaN
1048710487IX60941Oregon3508.569533YesExtendedCollege1/5/11Medical LeaveM...1.01Personal AutoPersonal L3Offer2Branch1176.278800Four-Door CarSmallNaN
1056510565QO62792Oregon7840.165778YesExtendedCollege1/14/11EmployedM...2.01Personal AutoPersonal L3Offer2Agent1008.000000NaNNaNNaN
1070810708CK39096Oregon5619.689084YesPremiumHigh School or Below1/26/11UnemployedM...0.01Personal AutoPersonal L3Offer2Web1027.000029SUVMedsizeA
\n", + "

67 rows × 26 columns

\n", + "
" + ], + "text/plain": [ + " Unnamed: 0 Customer State Customer Lifetime Value Response \\\n", + "189 189 OK31456 California 11009.130490 Yes \n", + "236 236 YJ16163 Oregon 11009.130490 Yes \n", + "419 419 GW43195 Oregon 25807.063000 Yes \n", + "442 442 IP94270 Arizona 13736.132500 Yes \n", + "587 587 FJ28407 California 5619.689084 Yes \n", + "... ... ... ... ... ... \n", + "10351 10351 FN44127 Oregon 3508.569533 Yes \n", + "10373 10373 XZ64172 Oregon 10963.957230 Yes \n", + "10487 10487 IX60941 Oregon 3508.569533 Yes \n", + "10565 10565 QO62792 Oregon 7840.165778 Yes \n", + "10708 10708 CK39096 Oregon 5619.689084 Yes \n", + "\n", + " Coverage Education Effective To Date EmploymentStatus \\\n", + "189 Premium Bachelor 1/24/11 Employed \n", + "236 Premium Bachelor 1/24/11 Employed \n", + "419 Extended College 2/13/11 Employed \n", + "442 Premium Master 2/13/11 Disabled \n", + "587 Premium High School or Below 1/26/11 Unemployed \n", + "... ... ... ... ... \n", + "10351 Extended College 1/5/11 Medical Leave \n", + "10373 Premium High School or Below 2/8/11 Employed \n", + "10487 Extended College 1/5/11 Medical Leave \n", + "10565 Extended College 1/14/11 Employed \n", + "10708 Premium High School or Below 1/26/11 Unemployed \n", + "\n", + " Gender ... Number of Open Complaints Number of Policies \\\n", + "189 F ... 0.0 1 \n", + "236 F ... 0.0 1 \n", + "419 F ... 1.0 2 \n", + "442 F ... 0.0 8 \n", + "587 M ... 0.0 1 \n", + "... ... ... ... ... \n", + "10351 M ... 1.0 1 \n", + "10373 M ... 0.0 1 \n", + "10487 M ... 1.0 1 \n", + "10565 M ... 2.0 1 \n", + "10708 M ... 0.0 1 \n", + "\n", + " Policy Type Policy Renew Offer Type Sales Channel \\\n", + "189 Corporate Auto Corporate L3 Offer2 Agent \n", + "236 Special Auto Special L3 Offer2 Agent \n", + "419 Personal Auto Personal L2 Offer1 Branch \n", + "442 Personal Auto Personal L2 Offer1 Web \n", + "587 Personal Auto Personal L1 Offer2 Web \n", + "... ... ... ... ... \n", + "10351 Personal Auto Personal L2 Offer2 Branch \n", + "10373 Corporate Auto Corporate L2 Offer1 Agent \n", + "10487 Personal Auto Personal L3 Offer2 Branch \n", + "10565 Personal Auto Personal L3 Offer2 Agent \n", + "10708 Personal Auto Personal L3 Offer2 Web \n", + "\n", + " Total Claim Amount Vehicle Class Vehicle Size Vehicle Type \n", + "189 1358.400000 Luxury Car Medsize NaN \n", + "236 1358.400000 Luxury Car Medsize A \n", + "419 1027.200000 Luxury Car Small A \n", + "442 1261.319869 SUV Medsize A \n", + "587 1027.000029 SUV Medsize A \n", + "... ... ... ... ... \n", + "10351 1176.278800 Four-Door Car Small NaN \n", + "10373 1324.800000 Luxury SUV Medsize NaN \n", + "10487 1176.278800 Four-Door Car Small NaN \n", + "10565 1008.000000 NaN NaN NaN \n", + "10708 1027.000029 SUV Medsize A \n", + "\n", + "[67 rows x 26 columns]" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ @@ -630,12 +967,12 @@ "df_filtrado = df[(df['Total Claim Amount'] > 1000) & (df['Response'] == 'Yes')]\n", "\n", "# Mostrar el DataFrame resultante\n", - "print(df_filtrado)" + "df_filtrado" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "id": "fe5b7cd6", "metadata": {}, "outputs": [ @@ -702,27 +1039,132 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 20, "id": "3153c3c5", "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - " max min median\n", - "Education Gender \n", - "Bachelor F 73225.96 1904.00 5640.51\n", - " M 67907.27 1898.01 5548.03\n", - "College F 61850.19 1898.68 5623.61\n", - " M 61134.68 1918.12 6005.85\n", - "Doctor F 44856.11 2395.57 5332.46\n", - " M 32677.34 2267.60 5577.67\n", - "High School or Below F 55277.45 2144.92 6039.55\n", - " M 83325.38 1940.98 6286.73\n", - "Master F 51016.07 2417.78 5729.86\n", - " M 50568.26 2272.31 5579.10\n" - ] + "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", + "
maxminmedian
EducationGender
BachelorF73225.961904.005640.51
M67907.271898.015548.03
CollegeF61850.191898.685623.61
M61134.681918.126005.85
DoctorF44856.112395.575332.46
M32677.342267.605577.67
High School or BelowF55277.452144.926039.55
M83325.381940.986286.73
MasterF51016.072417.785729.86
M50568.262272.315579.10
\n", + "
" + ], + "text/plain": [ + " max min median\n", + "Education Gender \n", + "Bachelor F 73225.96 1904.00 5640.51\n", + " M 67907.27 1898.01 5548.03\n", + "College F 61850.19 1898.68 5623.61\n", + " M 61134.68 1918.12 6005.85\n", + "Doctor F 44856.11 2395.57 5332.46\n", + " M 32677.34 2267.60 5577.67\n", + "High School or Below F 55277.45 2144.92 6039.55\n", + " M 83325.38 1940.98 6286.73\n", + "Master F 51016.07 2417.78 5729.86\n", + " M 50568.26 2272.31 5579.10" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ @@ -730,7 +1172,7 @@ "estadisticas = df.groupby(['Education', 'Gender'])['Customer Lifetime Value'].agg(['max', 'min', 'median']).round(2)\n", "\n", "# Mostrar la tabla resultante\n", - "print(estadisticas)" + "estadisticas" ] }, {