diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 58461f2..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.ipynb_checkpoints \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index e759125..0000000 --- a/README.md +++ /dev/null @@ -1,121 +0,0 @@ -![logo_ironhack_blue 7](https://user-images.githubusercontent.com/23629340/40541063-a07a0a8a-601a-11e8-91b5-2f13e4e6b441.png) - -# LAB | Data Aggregation and Filtering -
- -

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: - -- Use Python programming techniques to filter and order data subsets, group data by one or more variables, and use aggregation functions to obtain insights, and derive meaningful conclusions from the data. - -
-
- -
- -
- -

Prerequisites

-
- -Before this starting this lab, you should have learnt about: - -- Python Programming -- Introduction to Pandas DataFrames and Series -- Data Cleaning: handling null values and duplicates -- Data Formatting: dealing with strings, dates, renaming columns, using map, apply and mapapply methods -- Data structuring and combining data: methods such as pivot, stack/unstack or melt for data structuring and merge, concat or join for combining data. -- Data Aggregation: groupby and aggregation functions - -
-
- -
- - -## Introduction - -Welcome to the data aggregation and filtering lab! In this lab, you will practice how to apply various aggregation functions and filter data to obtain insights, identify patterns, and derive meaningful conclusions from your data. - -Aggregation is a powerful technique that allows you to group your data by one or more variables and calculate summary statistics for each group. This is especially useful when working with large datasets, as it can help you to understand the overall structure of your data and identify trends and patterns that might not be immediately apparent. - -During this lab, you will work with a variety of datasets and practice how to use common aggregation functions such as sum, count, mean, median, min, and max. You will also practice how to group your data by one or more variables and how to apply these aggregation functions to obtain insights and draw meaningful conclusions from your data. Also, you will practice data filtering a bit more. By the end of this lab, you will have a strong understanding of how aggregation works and how it can be used to analyze data in a variety of contexts. So let's get started! - -
- -**Happy coding!** :heart: - - -## Important Notes - -This lab is built on top of the `data cleaning and formatting` and `data structuring and combining` lab. If you couldn't complete those lasb, ask your TA for the lab solutions so you can do this lab on top of it. - -## Requirements - -- Fork this repo -- Clone it to your machine - -## Getting Started - -Complete the challenges in the `Jupyter Notebook` file. 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. - - -## FAQs -
- I am stuck in the exercise and don't know how to solve the problem or where to start. -
- - If you are stuck in your code and don't know how to solve the problem or where to start, you should take a step back and try to form a clear question about the specific issue you are facing. This will help you narrow down the problem and come up with potential solutions. - - - For example, is it a concept that you don't understand, or are you receiving an error message that you don't know how to fix? It is usually helpful to try to state the problem as clearly as possible, including any error messages you are receiving. This can help you communicate the issue to others and potentially get help from classmates or online resources. - - - Once you have a clear understanding of the problem, you will be able to start working toward the solution. - - [Back to top](#faqs) - -
- - -
- I am unable to push changes to the repository. What should I do? -
- -There are a couple of possible reasons why you may be unable to *push* changes to a Git repository: - -1. **You have not committed your changes:** Before you can push your changes to the repository, you need to commit them using the `git commit` command. Make sure you have committed your changes and try pushing again. To do this, run the following terminal commands from the project folder: - ```bash - git add . - git commit -m "Your commit message" - git push - ``` -2. **You do not have permission to push to the repository:** If you have cloned the repository directly from the main Ironhack repository without making a *Fork* first, you do not have write access to the repository. -To check which remote repository you have cloned, run the following terminal command from the project folder: - ```bash - git remote -v - ``` -If the link shown is the same as the main Ironhack repository, you will need to fork the repository to your GitHub account first and then clone your fork to your local machine to be able to push the changes. - -**Note**: You should make a copy of your local code to avoid losing it in the process. - - [Back to top](#faqs) - -
- diff --git a/lab-dw-aggregating (1).ipynb b/lab-dw-aggregating (1).ipynb new file mode 100644 index 0000000..b53c5e5 --- /dev/null +++ b/lab-dw-aggregating (1).ipynb @@ -0,0 +1 @@ +{"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:\n"," - have a **low total_claim_amount** (e.g., below $1,000),\n"," - have a response \"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:\n"," - the average `monthly_premium` and/or customer lifetime value by `policy_type` and `gender` for customers who responded \"Yes\", and\n"," - compare these insights to `total_claim_amount` patterns, and discuss which segments appear most profitable or low-risk for the company."]},{"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":"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":9,"id":"449513f4-0459-46a0-a18d-9398d974c9ad","metadata":{"id":"449513f4-0459-46a0-a18d-9398d974c9ad","colab":{"base_uri":"https://localhost:8080/","height":721},"executionInfo":{"status":"ok","timestamp":1754244152696,"user_tz":-120,"elapsed":187,"user":{"displayName":"Santiago Larrea","userId":"01956628674237458372"}},"outputId":"feda26e5-e532-4c79-c302-f6af77fef758"},"outputs":[{"output_type":"execute_result","data":{"text/plain":[" Unnamed: 0 Customer State Customer Lifetime Value Response \\\n","0 0 DK49336 Arizona 4809.216960 No \n","1 1 KX64629 California 2228.525238 No \n","2 2 LZ68649 Washington 14947.917300 No \n","3 3 XL78013 Oregon 22332.439460 Yes \n","4 4 QA50777 Oregon 9025.067525 No \n","... ... ... ... ... ... \n","10905 10905 FE99816 Nevada 15563.369440 No \n","10906 10906 KX53892 Oregon 5259.444853 No \n","10907 10907 TL39050 Arizona 23893.304100 No \n","10908 10908 WA60547 California 11971.977650 No \n","10909 10909 IV32877 NaN 6857.519928 NaN \n","\n"," Coverage Education Effective To Date EmploymentStatus Gender Income \\\n","0 Basic College 2/18/11 Employed M 48029 \n","1 Basic College 1/18/11 Unemployed F 0 \n","2 Basic Bachelor 2/10/11 Employed M 22139 \n","3 Extended College 1/11/11 Employed M 49078 \n","4 Premium Bachelor 1/17/11 Medical Leave F 23675 \n","... ... ... ... ... ... ... \n","10905 Premium Bachelor 1/19/11 Unemployed F 0 \n","10906 Basic College 1/6/11 Employed F 61146 \n","10907 Extended Bachelor 2/6/11 Employed F 39837 \n","10908 Premium College 2/13/11 Employed F 64195 \n","10909 Basic Bachelor 1/8/11 Unemployed M 0 \n","\n"," Location Code Marital Status Monthly Premium Auto \\\n","0 Suburban Married 61 \n","1 Suburban Single 64 \n","2 Suburban Single 100 \n","3 Suburban Single 97 \n","4 Suburban Married 117 \n","... ... ... ... \n","10905 Suburban Married 253 \n","10906 Urban Married 65 \n","10907 Rural Married 201 \n","10908 Urban Divorced 158 \n","10909 Suburban Single 101 \n","\n"," Months Since Last Claim Months Since Policy Inception \\\n","0 7.0 52 \n","1 3.0 26 \n","2 34.0 31 \n","3 10.0 3 \n","4 NaN 31 \n","... ... ... \n","10905 NaN 40 \n","10906 7.0 68 \n","10907 11.0 63 \n","10908 0.0 27 \n","10909 31.0 1 \n","\n"," Number of Open Complaints Number of Policies Policy Type \\\n","0 0.0 9 Corporate Auto \n","1 0.0 1 Personal Auto \n","2 0.0 2 Personal Auto \n","3 0.0 2 Corporate Auto \n","4 NaN 7 Personal Auto \n","... ... ... ... \n","10905 NaN 7 Personal Auto \n","10906 0.0 6 Personal Auto \n","10907 0.0 2 Corporate Auto \n","10908 4.0 6 Personal Auto \n","10909 0.0 3 Personal Auto \n","\n"," Policy Renew Offer Type Sales Channel Total Claim Amount \\\n","0 Corporate L3 Offer3 Agent 292.800000 \n","1 Personal L3 Offer4 Call Center 744.924331 \n","2 Personal L3 Offer3 Call Center 480.000000 \n","3 Corporate L3 Offer2 Branch 484.013411 \n","4 Personal L2 Offer1 Branch 707.925645 \n","... ... ... ... ... \n","10905 Personal L1 Offer3 Web 1214.400000 \n","10906 Personal L3 Offer2 Branch 273.018929 \n","10907 Corporate L3 Offer1 Web 381.306996 \n","10908 Personal L1 Offer1 Branch 618.288849 \n","10909 Personal L1 Offer4 Web 1021.719397 \n","\n"," Vehicle Class Vehicle Size Vehicle Type \n","0 Four-Door Car Medsize NaN \n","1 Four-Door Car Medsize NaN \n","2 SUV Medsize A \n","3 Four-Door Car Medsize A \n","4 Four-Door Car Medsize NaN \n","... ... ... ... \n","10905 Luxury Car Medsize A \n","10906 Four-Door Car Medsize A \n","10907 Luxury SUV Medsize NaN \n","10908 SUV Medsize A \n","10909 SUV Medsize NaN \n","\n","[10910 rows x 26 columns]"],"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"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \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 DateEmploymentStatusGenderIncomeLocation CodeMarital StatusMonthly Premium AutoMonths Since Last ClaimMonths Since Policy InceptionNumber of Open ComplaintsNumber of PoliciesPolicy TypePolicyRenew Offer TypeSales ChannelTotal Claim AmountVehicle ClassVehicle SizeVehicle Type
00DK49336Arizona4809.216960NoBasicCollege2/18/11EmployedM48029SuburbanMarried617.0520.09Corporate AutoCorporate L3Offer3Agent292.800000Four-Door CarMedsizeNaN
11KX64629California2228.525238NoBasicCollege1/18/11UnemployedF0SuburbanSingle643.0260.01Personal AutoPersonal L3Offer4Call Center744.924331Four-Door CarMedsizeNaN
22LZ68649Washington14947.917300NoBasicBachelor2/10/11EmployedM22139SuburbanSingle10034.0310.02Personal AutoPersonal L3Offer3Call Center480.000000SUVMedsizeA
33XL78013Oregon22332.439460YesExtendedCollege1/11/11EmployedM49078SuburbanSingle9710.030.02Corporate AutoCorporate L3Offer2Branch484.013411Four-Door CarMedsizeA
44QA50777Oregon9025.067525NoPremiumBachelor1/17/11Medical LeaveF23675SuburbanMarried117NaN31NaN7Personal AutoPersonal L2Offer1Branch707.925645Four-Door CarMedsizeNaN
.................................................................................
1090510905FE99816Nevada15563.369440NoPremiumBachelor1/19/11UnemployedF0SuburbanMarried253NaN40NaN7Personal AutoPersonal L1Offer3Web1214.400000Luxury CarMedsizeA
1090610906KX53892Oregon5259.444853NoBasicCollege1/6/11EmployedF61146UrbanMarried657.0680.06Personal AutoPersonal L3Offer2Branch273.018929Four-Door CarMedsizeA
1090710907TL39050Arizona23893.304100NoExtendedBachelor2/6/11EmployedF39837RuralMarried20111.0630.02Corporate AutoCorporate L3Offer1Web381.306996Luxury SUVMedsizeNaN
1090810908WA60547California11971.977650NoPremiumCollege2/13/11EmployedF64195UrbanDivorced1580.0274.06Personal AutoPersonal L1Offer1Branch618.288849SUVMedsizeA
1090910909IV32877NaN6857.519928NaNBasicBachelor1/8/11UnemployedM0SuburbanSingle10131.010.03Personal AutoPersonal L1Offer4Web1021.719397SUVMedsizeNaN
\n","

10910 rows × 26 columns

\n","
\n","
\n","\n","
\n"," \n","\n"," \n","\n"," \n","
\n","\n","\n","
\n"," \n","\n","\n","\n"," \n","
\n","\n","
\n"," \n"," \n"," \n","
\n","\n","
\n","
\n"],"application/vnd.google.colaboratory.intrinsic+json":{"type":"dataframe","variable_name":"df"}},"metadata":{},"execution_count":9},{"output_type":"stream","name":"stdout","text":["Warning: Total number of columns (26) exceeds max_columns (20) limiting to first (20) columns.\n"]}],"source":["# your code goes here\n","\n","import pandas as pd\n","\n","url = 'https://raw.githubusercontent.com/data-bootcamp-v4/data/main/marketing_customer_analysis.csv'\n","\n","df = pd.read_csv(url)\n","\n","pd.set_option('display.max_columns',None)\n","\n","df"]},{"cell_type":"code","source":["#1\n","df_1 = df[(df['Total Claim Amount']< 1000) & (df['Response']== 'Yes')]\n","\n","df_1 = df_1.round(2)\n","\n","df_1"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":597},"id":"lF-elNKkF5Yd","executionInfo":{"status":"ok","timestamp":1754244374176,"user_tz":-120,"elapsed":45,"user":{"displayName":"Santiago Larrea","userId":"01956628674237458372"}},"outputId":"9df77c81-86a3-4eb5-f123-42899d8b5196"},"id":"lF-elNKkF5Yd","execution_count":16,"outputs":[{"output_type":"execute_result","data":{"text/plain":[" Unnamed: 0 Customer State Customer Lifetime Value Response \\\n","3 3 XL78013 Oregon 22332.44 Yes \n","8 8 FM55990 California 5989.77 Yes \n","15 15 CW49887 California 4626.80 Yes \n","19 19 NJ54277 California 3746.75 Yes \n","27 27 MQ68407 Oregon 4376.36 Yes \n","... ... ... ... ... ... \n","10844 10844 FM31768 Arizona 5979.72 Yes \n","10852 10852 KZ80424 Washington 8382.48 Yes \n","10872 10872 XT67997 California 5979.72 Yes \n","10887 10887 BY78730 Oregon 8879.79 Yes \n","10897 10897 MM70762 Arizona 9075.77 Yes \n","\n"," Coverage Education Effective To Date EmploymentStatus \\\n","3 Extended College 1/11/11 Employed \n","8 Premium College 1/19/11 Employed \n","15 Basic Master 1/16/11 Employed \n","19 Extended College 2/26/11 Employed \n","27 Premium Bachelor 2/28/11 Employed \n","... ... ... ... ... \n","10844 Extended High School or Below 2/7/11 Employed \n","10852 Basic Bachelor 1/27/11 Employed \n","10872 Extended High School or Below 2/7/11 Employed \n","10887 Basic High School or Below 2/3/11 Employed \n","10897 Basic Master 1/26/11 Employed \n","\n"," Gender Income Location Code Marital Status Monthly Premium Auto \\\n","3 M 49078 Suburban Single 97 \n","8 M 66839 Suburban Single 154 \n","15 F 79487 Suburban Divorced 114 \n","19 F 41479 Rural Married 94 \n","27 F 63774 Rural Divorced 111 \n","... ... ... ... ... ... \n","10844 F 57693 Suburban Divorced 76 \n","10852 M 25998 Suburban Married 71 \n","10872 F 57693 Suburban Divorced 76 \n","10887 F 52583 Urban Single 113 \n","10897 M 37722 Rural Single 116 \n","\n"," Months Since Last Claim Months Since Policy Inception \\\n","3 10.0 3 \n","8 33.0 24 \n","15 20.0 87 \n","19 14.0 38 \n","27 18.0 63 \n","... ... ... \n","10844 16.0 56 \n","10852 16.0 38 \n","10872 16.0 56 \n","10887 12.0 59 \n","10897 8.0 23 \n","\n"," Number of Open Complaints Number of Policies Policy Type \\\n","3 0.0 2 Corporate Auto \n","8 0.0 1 Personal Auto \n","15 0.0 1 Special Auto \n","19 1.0 1 Personal Auto \n","27 0.0 1 Personal Auto \n","... ... ... ... \n","10844 0.0 3 Personal Auto \n","10852 0.0 2 Personal Auto \n","10872 0.0 3 Personal Auto \n","10887 0.0 7 Special Auto \n","10897 0.0 8 Personal Auto \n","\n"," Policy Renew Offer Type Sales Channel Total Claim Amount \\\n","3 Corporate L3 Offer2 Branch 484.01 \n","8 Personal L1 Offer2 Branch 739.20 \n","15 Special L1 Offer2 Branch 547.20 \n","19 Personal L2 Offer2 Call Center 19.58 \n","27 Personal L3 Offer2 Agent 60.04 \n","... ... ... ... ... \n","10844 Personal L1 Offer2 Agent 547.20 \n","10852 Personal L2 Offer2 Call Center 791.88 \n","10872 Personal L3 Offer2 Agent 547.20 \n","10887 Special L2 Offer1 Agent 528.20 \n","10897 Personal L1 Offer1 Agent 158.08 \n","\n"," Vehicle Class Vehicle Size Vehicle Type \n","3 Four-Door Car Medsize A \n","8 Sports Car Medsize NaN \n","15 SUV Medsize NaN \n","19 Two-Door Car Large A \n","27 Four-Door Car Medsize NaN \n","... ... ... ... \n","10844 Four-Door Car Medsize NaN \n","10852 NaN NaN A \n","10872 Four-Door Car Medsize NaN \n","10887 SUV Small A \n","10897 Sports Car Medsize A \n","\n","[1399 rows x 26 columns]"],"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"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \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 DateEmploymentStatusGenderIncomeLocation CodeMarital StatusMonthly Premium AutoMonths Since Last ClaimMonths Since Policy InceptionNumber of Open ComplaintsNumber of PoliciesPolicy TypePolicyRenew Offer TypeSales ChannelTotal Claim AmountVehicle ClassVehicle SizeVehicle Type
33XL78013Oregon22332.44YesExtendedCollege1/11/11EmployedM49078SuburbanSingle9710.030.02Corporate AutoCorporate L3Offer2Branch484.01Four-Door CarMedsizeA
88FM55990California5989.77YesPremiumCollege1/19/11EmployedM66839SuburbanSingle15433.0240.01Personal AutoPersonal L1Offer2Branch739.20Sports CarMedsizeNaN
1515CW49887California4626.80YesBasicMaster1/16/11EmployedF79487SuburbanDivorced11420.0870.01Special AutoSpecial L1Offer2Branch547.20SUVMedsizeNaN
1919NJ54277California3746.75YesExtendedCollege2/26/11EmployedF41479RuralMarried9414.0381.01Personal AutoPersonal L2Offer2Call Center19.58Two-Door CarLargeA
2727MQ68407Oregon4376.36YesPremiumBachelor2/28/11EmployedF63774RuralDivorced11118.0630.01Personal AutoPersonal L3Offer2Agent60.04Four-Door CarMedsizeNaN
.................................................................................
1084410844FM31768Arizona5979.72YesExtendedHigh School or Below2/7/11EmployedF57693SuburbanDivorced7616.0560.03Personal AutoPersonal L1Offer2Agent547.20Four-Door CarMedsizeNaN
1085210852KZ80424Washington8382.48YesBasicBachelor1/27/11EmployedM25998SuburbanMarried7116.0380.02Personal AutoPersonal L2Offer2Call Center791.88NaNNaNA
1087210872XT67997California5979.72YesExtendedHigh School or Below2/7/11EmployedF57693SuburbanDivorced7616.0560.03Personal AutoPersonal L3Offer2Agent547.20Four-Door CarMedsizeNaN
1088710887BY78730Oregon8879.79YesBasicHigh School or Below2/3/11EmployedF52583UrbanSingle11312.0590.07Special AutoSpecial L2Offer1Agent528.20SUVSmallA
1089710897MM70762Arizona9075.77YesBasicMaster1/26/11EmployedM37722RuralSingle1168.0230.08Personal AutoPersonal L1Offer1Agent158.08Sports CarMedsizeA
\n","

1399 rows × 26 columns

\n","
\n","
\n","\n","
\n"," \n","\n"," \n","\n"," \n","
\n","\n","\n","
\n"," \n","\n","\n","\n"," \n","
\n","\n","
\n"," \n"," \n"," \n","
\n","\n","
\n","
\n"],"application/vnd.google.colaboratory.intrinsic+json":{"type":"dataframe","variable_name":"df_1"}},"metadata":{},"execution_count":16}]},{"cell_type":"code","source":["#2\n","grouped = round(df[df['Response'] == 'Yes'].groupby(['Policy Type','Gender']).agg({'Monthly Premium Auto':['mean','count'],'Customer Lifetime Value':['mean','count']}),2)\n","\n","claims_grouped = round(df[df['Response'] == 'Yes'].groupby(['Policy Type','Gender']).agg({'Total Claim Amount': ['mean', 'count']}), 2)\n","\n","combined = grouped.join(claims_grouped)\n","\n","combined\n","\n","\n","#Conslusiones: Based on the data, Special Auto - Male customers show the highest Customer Lifetime Value (CLV) with relatively low average claims,\n","#suggesting they are a profitable, low-risk segment. In contrast,\n","#Personal Auto - Male clients have lower CLV and higher claim amounts,\n","#indicating a higher-risk, less profitable profile."],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":300},"id":"Vh0etVIeHTms","executionInfo":{"status":"ok","timestamp":1754245743409,"user_tz":-120,"elapsed":24,"user":{"displayName":"Santiago Larrea","userId":"01956628674237458372"}},"outputId":"d70ed5d4-0258-4512-f9b7-9b07a8389e8c"},"id":"Vh0etVIeHTms","execution_count":27,"outputs":[{"output_type":"execute_result","data":{"text/plain":[" Monthly Premium Auto Customer Lifetime Value \\\n"," mean count mean \n","Policy Type Gender \n","Corporate Auto F 94.30 169 7712.63 \n"," M 92.19 154 7944.47 \n","Personal Auto F 99.00 540 8339.79 \n"," M 91.09 536 7448.38 \n","Special Auto F 92.31 35 7691.58 \n"," M 86.34 32 8247.09 \n","\n"," Total Claim Amount \n"," count mean count \n","Policy Type Gender \n","Corporate Auto F 169 433.74 169 \n"," M 154 408.58 154 \n","Personal Auto F 540 452.97 540 \n"," M 536 457.01 536 \n","Special Auto F 35 453.28 35 \n"," M 32 429.53 32 "],"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","
Monthly Premium AutoCustomer Lifetime ValueTotal Claim Amount
meancountmeancountmeancount
Policy TypeGender
Corporate AutoF94.301697712.63169433.74169
M92.191547944.47154408.58154
Personal AutoF99.005408339.79540452.97540
M91.095367448.38536457.01536
Special AutoF92.31357691.5835453.2835
M86.34328247.0932429.5332
\n","
\n","
\n","\n","
\n"," \n","\n"," \n","\n"," \n","
\n","\n","\n","
\n"," \n","\n","\n","\n"," \n","
\n","\n","
\n"," \n"," \n"," \n","
\n","\n","
\n","
\n"],"application/vnd.google.colaboratory.intrinsic+json":{"type":"dataframe","variable_name":"combined","summary":"{\n \"name\": \"combined\",\n \"rows\": 6,\n \"fields\": [\n {\n \"column\": [\n \"Monthly Premium Auto\",\n \"mean\"\n ],\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 4.136353063589549,\n \"min\": 86.34,\n \"max\": 99.0,\n \"num_unique_values\": 6,\n \"samples\": [\n 94.3,\n 92.19,\n 86.34\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": [\n \"Monthly Premium Auto\",\n \"count\"\n ],\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 234,\n \"min\": 32,\n \"max\": 540,\n \"num_unique_values\": 6,\n \"samples\": [\n 169,\n 154,\n 32\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": [\n \"Customer Lifetime Value\",\n \"mean\"\n ],\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 345.92725927088605,\n \"min\": 7448.38,\n \"max\": 8339.79,\n \"num_unique_values\": 6,\n \"samples\": [\n 7712.63,\n 7944.47,\n 8247.09\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": [\n \"Customer Lifetime Value\",\n \"count\"\n ],\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 234,\n \"min\": 32,\n \"max\": 540,\n \"num_unique_values\": 6,\n \"samples\": [\n 169,\n 154,\n 32\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": [\n \"Total Claim Amount\",\n \"mean\"\n ],\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 18.79339751082811,\n \"min\": 408.58,\n \"max\": 457.01,\n \"num_unique_values\": 6,\n \"samples\": [\n 433.74,\n 408.58,\n 429.53\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": [\n \"Total Claim Amount\",\n \"count\"\n ],\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 234,\n \"min\": 32,\n \"max\": 540,\n \"num_unique_values\": 6,\n \"samples\": [\n 169,\n 154,\n 32\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"}},"metadata":{},"execution_count":27}]},{"cell_type":"code","source":["#3\n","grouped_3 = df.groupby('State').agg({'Customer':['count']})\n","\n","grouped_3[grouped_3[('Customer', 'count')] > 500]"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":269},"id":"PK5hqfkpLUAW","executionInfo":{"status":"ok","timestamp":1754247144095,"user_tz":-120,"elapsed":6,"user":{"displayName":"Santiago Larrea","userId":"01956628674237458372"}},"outputId":"b8530a84-f678-4de1-9fdc-cef654004886"},"id":"PK5hqfkpLUAW","execution_count":38,"outputs":[{"output_type":"execute_result","data":{"text/plain":[" Customer\n"," count\n","State \n","Arizona 1937\n","California 3552\n","Nevada 993\n","Oregon 2909\n","Washington 888"],"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","
Customer
count
State
Arizona1937
California3552
Nevada993
Oregon2909
Washington888
\n","
\n","
\n","\n","
\n"," \n","\n"," \n","\n"," \n","
\n","\n","\n","
\n"," \n","\n","\n","\n"," \n","
\n","\n","
\n","
\n"],"application/vnd.google.colaboratory.intrinsic+json":{"type":"dataframe","summary":"{\n \"name\": \"grouped_3[grouped_3[('Customer', 'count')] > 500]\",\n \"rows\": 5,\n \"fields\": [\n {\n \"column\": [\n \"State\",\n \"\"\n ],\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 5,\n \"samples\": [\n \"California\",\n \"Washington\",\n \"Nevada\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": [\n \"Customer\",\n \"count\"\n ],\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 1169,\n \"min\": 888,\n \"max\": 3552,\n \"num_unique_values\": 5,\n \"samples\": [\n 3552,\n 888,\n 993\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"}},"metadata":{},"execution_count":38}]},{"cell_type":"code","source":["min_max_median = round(df.groupby(['Education','Gender']).agg({'Customer Lifetime Value':['max','min','mean']}))\n","\n","min_max_median\n","\n","#Conclusions: Customers with \"High School or Below\" education show the highest average Customer Lifetime Value (CLV), particularly males. In contrast, those with a \"Doctor\" degree exhibit the lowest CLV averages, suggesting lower long-term value despite higher education levels."],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":426},"id":"hD14OlABR3uO","executionInfo":{"status":"ok","timestamp":1754247339448,"user_tz":-120,"elapsed":30,"user":{"displayName":"Santiago Larrea","userId":"01956628674237458372"}},"outputId":"e25912c9-2855-4afc-a8e9-3a61ebce09e6"},"id":"hD14OlABR3uO","execution_count":40,"outputs":[{"output_type":"execute_result","data":{"text/plain":[" Customer Lifetime Value \n"," max min mean\n","Education Gender \n","Bachelor F 73226.0 1904.0 7874.0\n"," M 67907.0 1898.0 7704.0\n","College F 61850.0 1899.0 7749.0\n"," M 61135.0 1918.0 8052.0\n","Doctor F 44856.0 2396.0 7329.0\n"," M 32677.0 2268.0 7415.0\n","High School or Below F 55277.0 2145.0 8675.0\n"," M 83325.0 1941.0 8150.0\n","Master F 51016.0 2418.0 8157.0\n"," M 50568.0 2272.0 8169.0"],"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","
Customer Lifetime Value
maxminmean
EducationGender
BachelorF73226.01904.07874.0
M67907.01898.07704.0
CollegeF61850.01899.07749.0
M61135.01918.08052.0
DoctorF44856.02396.07329.0
M32677.02268.07415.0
High School or BelowF55277.02145.08675.0
M83325.01941.08150.0
MasterF51016.02418.08157.0
M50568.02272.08169.0
\n","
\n","
\n","\n","
\n"," \n","\n"," \n","\n"," \n","
\n","\n","\n","
\n"," \n","\n","\n","\n"," \n","
\n","\n","
\n"," \n"," \n"," \n","
\n","\n","
\n","
\n"],"application/vnd.google.colaboratory.intrinsic+json":{"type":"dataframe","variable_name":"min_max_median","summary":"{\n \"name\": \"min_max_median\",\n \"rows\": 10,\n \"fields\": [\n {\n \"column\": [\n \"Customer Lifetime Value\",\n \"max\"\n ],\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 14610.092752386388,\n \"min\": 32677.0,\n \"max\": 83325.0,\n \"num_unique_values\": 10,\n \"samples\": [\n 51016.0,\n 67907.0,\n 32677.0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": [\n \"Customer Lifetime Value\",\n \"min\"\n ],\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 217.6263107050963,\n \"min\": 1898.0,\n \"max\": 2418.0,\n \"num_unique_values\": 10,\n \"samples\": [\n 2418.0,\n 1898.0,\n 2268.0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": [\n \"Customer Lifetime Value\",\n \"mean\"\n ],\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 400.0403313000661,\n \"min\": 7329.0,\n \"max\": 8675.0,\n \"num_unique_values\": 10,\n \"samples\": [\n 8157.0,\n 7704.0,\n 7415.0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"}},"metadata":{},"execution_count":40}]}],"metadata":{"colab":{"provenance":[]},"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"}},"nbformat":4,"nbformat_minor":5} \ No newline at end of file diff --git a/lab-dw-aggregating.ipynb b/lab-dw-aggregating.ipynb deleted file mode 100644 index fadd718..0000000 --- a/lab-dw-aggregating.ipynb +++ /dev/null @@ -1,165 +0,0 @@ -{ - "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:\n", - " - have a **low total_claim_amount** (e.g., below $1,000),\n", - " - have a response \"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:\n", - " - the average `monthly_premium` and/or customer lifetime value by `policy_type` and `gender` for customers who responded \"Yes\", and\n", - " - compare these insights to `total_claim_amount` patterns, and discuss which segments appear most profitable or low-risk for the company." - ] - }, - { - "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": "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": null, - "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": "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" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -}