diff --git a/Copie de lab-dw-aggregating.ipynb b/Copie de lab-dw-aggregating.ipynb
new file mode 100644
index 0000000..3f9a523
--- /dev/null
+++ b/Copie de lab-dw-aggregating.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":"code","source":["#Our goal is to explore and analyze this data by first performing data cleaning, formatting, and structuring.\n","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)\n","df"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":739},"id":"M_MTyL43bFVS","executionInfo":{"status":"ok","timestamp":1760910183779,"user_tz":-120,"elapsed":1098,"user":{"displayName":"Rahala Moindze","userId":"02611134585983790642"}},"outputId":"076aaada-ee1a-4b73-9bc0-5cb9f2376fff"},"id":"M_MTyL43bFVS","execution_count":1,"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 ... \\\n","0 Basic College 2/18/11 Employed M ... \n","1 Basic College 1/18/11 Unemployed F ... \n","2 Basic Bachelor 2/10/11 Employed M ... \n","3 Extended College 1/11/11 Employed M ... \n","4 Premium Bachelor 1/17/11 Medical Leave F ... \n","... ... ... ... ... ... ... \n","10905 Premium Bachelor 1/19/11 Unemployed F ... \n","10906 Basic College 1/6/11 Employed F ... \n","10907 Extended Bachelor 2/6/11 Employed F ... \n","10908 Premium College 2/13/11 Employed F ... \n","10909 Basic Bachelor 1/8/11 Unemployed M ... \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","
Unnamed: 0
\n","
Customer
\n","
State
\n","
Customer Lifetime Value
\n","
Response
\n","
Coverage
\n","
Education
\n","
Effective To Date
\n","
EmploymentStatus
\n","
Gender
\n","
...
\n","
Number of Open Complaints
\n","
Number of Policies
\n","
Policy Type
\n","
Policy
\n","
Renew Offer Type
\n","
Sales Channel
\n","
Total Claim Amount
\n","
Vehicle Class
\n","
Vehicle Size
\n","
Vehicle Type
\n","
\n"," \n"," \n","
\n","
0
\n","
0
\n","
DK49336
\n","
Arizona
\n","
4809.216960
\n","
No
\n","
Basic
\n","
College
\n","
2/18/11
\n","
Employed
\n","
M
\n","
...
\n","
0.0
\n","
9
\n","
Corporate Auto
\n","
Corporate L3
\n","
Offer3
\n","
Agent
\n","
292.800000
\n","
Four-Door Car
\n","
Medsize
\n","
NaN
\n","
\n","
\n","
1
\n","
1
\n","
KX64629
\n","
California
\n","
2228.525238
\n","
No
\n","
Basic
\n","
College
\n","
1/18/11
\n","
Unemployed
\n","
F
\n","
...
\n","
0.0
\n","
1
\n","
Personal Auto
\n","
Personal L3
\n","
Offer4
\n","
Call Center
\n","
744.924331
\n","
Four-Door Car
\n","
Medsize
\n","
NaN
\n","
\n","
\n","
2
\n","
2
\n","
LZ68649
\n","
Washington
\n","
14947.917300
\n","
No
\n","
Basic
\n","
Bachelor
\n","
2/10/11
\n","
Employed
\n","
M
\n","
...
\n","
0.0
\n","
2
\n","
Personal Auto
\n","
Personal L3
\n","
Offer3
\n","
Call Center
\n","
480.000000
\n","
SUV
\n","
Medsize
\n","
A
\n","
\n","
\n","
3
\n","
3
\n","
XL78013
\n","
Oregon
\n","
22332.439460
\n","
Yes
\n","
Extended
\n","
College
\n","
1/11/11
\n","
Employed
\n","
M
\n","
...
\n","
0.0
\n","
2
\n","
Corporate Auto
\n","
Corporate L3
\n","
Offer2
\n","
Branch
\n","
484.013411
\n","
Four-Door Car
\n","
Medsize
\n","
A
\n","
\n","
\n","
4
\n","
4
\n","
QA50777
\n","
Oregon
\n","
9025.067525
\n","
No
\n","
Premium
\n","
Bachelor
\n","
1/17/11
\n","
Medical Leave
\n","
F
\n","
...
\n","
NaN
\n","
7
\n","
Personal Auto
\n","
Personal L2
\n","
Offer1
\n","
Branch
\n","
707.925645
\n","
Four-Door Car
\n","
Medsize
\n","
NaN
\n","
\n","
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
\n","
\n","
10905
\n","
10905
\n","
FE99816
\n","
Nevada
\n","
15563.369440
\n","
No
\n","
Premium
\n","
Bachelor
\n","
1/19/11
\n","
Unemployed
\n","
F
\n","
...
\n","
NaN
\n","
7
\n","
Personal Auto
\n","
Personal L1
\n","
Offer3
\n","
Web
\n","
1214.400000
\n","
Luxury Car
\n","
Medsize
\n","
A
\n","
\n","
\n","
10906
\n","
10906
\n","
KX53892
\n","
Oregon
\n","
5259.444853
\n","
No
\n","
Basic
\n","
College
\n","
1/6/11
\n","
Employed
\n","
F
\n","
...
\n","
0.0
\n","
6
\n","
Personal Auto
\n","
Personal L3
\n","
Offer2
\n","
Branch
\n","
273.018929
\n","
Four-Door Car
\n","
Medsize
\n","
A
\n","
\n","
\n","
10907
\n","
10907
\n","
TL39050
\n","
Arizona
\n","
23893.304100
\n","
No
\n","
Extended
\n","
Bachelor
\n","
2/6/11
\n","
Employed
\n","
F
\n","
...
\n","
0.0
\n","
2
\n","
Corporate Auto
\n","
Corporate L3
\n","
Offer1
\n","
Web
\n","
381.306996
\n","
Luxury SUV
\n","
Medsize
\n","
NaN
\n","
\n","
\n","
10908
\n","
10908
\n","
WA60547
\n","
California
\n","
11971.977650
\n","
No
\n","
Premium
\n","
College
\n","
2/13/11
\n","
Employed
\n","
F
\n","
...
\n","
4.0
\n","
6
\n","
Personal Auto
\n","
Personal L1
\n","
Offer1
\n","
Branch
\n","
618.288849
\n","
SUV
\n","
Medsize
\n","
A
\n","
\n","
\n","
10909
\n","
10909
\n","
IV32877
\n","
NaN
\n","
6857.519928
\n","
NaN
\n","
Basic
\n","
Bachelor
\n","
1/8/11
\n","
Unemployed
\n","
M
\n","
...
\n","
0.0
\n","
3
\n","
Personal Auto
\n","
Personal L1
\n","
Offer4
\n","
Web
\n","
1021.719397
\n","
SUV
\n","
Medsize
\n","
NaN
\n","
\n"," \n","
\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":1}]},{"cell_type":"code","source":["#Performing data cleaning, formatting, and structuring.\n","df.columns = df.columns.str.lower().str.replace(' ', '_')\n"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":617},"id":"oq-TKyyZbneW","executionInfo":{"status":"ok","timestamp":1760910297858,"user_tz":-120,"elapsed":116,"user":{"displayName":"Rahala Moindze","userId":"02611134585983790642"}},"outputId":"32a18b19-2801-4581-981b-b1a3738a5a1d"},"id":"oq-TKyyZbneW","execution_count":2,"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 ... \\\n","0 Basic College 2/18/11 Employed M ... \n","1 Basic College 1/18/11 Unemployed F ... \n","2 Basic Bachelor 2/10/11 Employed M ... \n","3 Extended College 1/11/11 Employed M ... \n","4 Premium Bachelor 1/17/11 Medical Leave F ... \n","... ... ... ... ... ... ... \n","10905 Premium Bachelor 1/19/11 Unemployed F ... \n","10906 Basic College 1/6/11 Employed F ... \n","10907 Extended Bachelor 2/6/11 Employed F ... \n","10908 Premium College 2/13/11 Employed F ... \n","10909 Basic Bachelor 1/8/11 Unemployed M ... \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","
unnamed:_0
\n","
customer
\n","
state
\n","
customer_lifetime_value
\n","
response
\n","
coverage
\n","
education
\n","
effective_to_date
\n","
employmentstatus
\n","
gender
\n","
...
\n","
number_of_open_complaints
\n","
number_of_policies
\n","
policy_type
\n","
policy
\n","
renew_offer_type
\n","
sales_channel
\n","
total_claim_amount
\n","
vehicle_class
\n","
vehicle_size
\n","
vehicle_type
\n","
\n"," \n"," \n","
\n","
0
\n","
0
\n","
DK49336
\n","
Arizona
\n","
4809.216960
\n","
No
\n","
Basic
\n","
College
\n","
2/18/11
\n","
Employed
\n","
M
\n","
...
\n","
0.0
\n","
9
\n","
Corporate Auto
\n","
Corporate L3
\n","
Offer3
\n","
Agent
\n","
292.800000
\n","
Four-Door Car
\n","
Medsize
\n","
NaN
\n","
\n","
\n","
1
\n","
1
\n","
KX64629
\n","
California
\n","
2228.525238
\n","
No
\n","
Basic
\n","
College
\n","
1/18/11
\n","
Unemployed
\n","
F
\n","
...
\n","
0.0
\n","
1
\n","
Personal Auto
\n","
Personal L3
\n","
Offer4
\n","
Call Center
\n","
744.924331
\n","
Four-Door Car
\n","
Medsize
\n","
NaN
\n","
\n","
\n","
2
\n","
2
\n","
LZ68649
\n","
Washington
\n","
14947.917300
\n","
No
\n","
Basic
\n","
Bachelor
\n","
2/10/11
\n","
Employed
\n","
M
\n","
...
\n","
0.0
\n","
2
\n","
Personal Auto
\n","
Personal L3
\n","
Offer3
\n","
Call Center
\n","
480.000000
\n","
SUV
\n","
Medsize
\n","
A
\n","
\n","
\n","
3
\n","
3
\n","
XL78013
\n","
Oregon
\n","
22332.439460
\n","
Yes
\n","
Extended
\n","
College
\n","
1/11/11
\n","
Employed
\n","
M
\n","
...
\n","
0.0
\n","
2
\n","
Corporate Auto
\n","
Corporate L3
\n","
Offer2
\n","
Branch
\n","
484.013411
\n","
Four-Door Car
\n","
Medsize
\n","
A
\n","
\n","
\n","
4
\n","
4
\n","
QA50777
\n","
Oregon
\n","
9025.067525
\n","
No
\n","
Premium
\n","
Bachelor
\n","
1/17/11
\n","
Medical Leave
\n","
F
\n","
...
\n","
NaN
\n","
7
\n","
Personal Auto
\n","
Personal L2
\n","
Offer1
\n","
Branch
\n","
707.925645
\n","
Four-Door Car
\n","
Medsize
\n","
NaN
\n","
\n","
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
\n","
\n","
10905
\n","
10905
\n","
FE99816
\n","
Nevada
\n","
15563.369440
\n","
No
\n","
Premium
\n","
Bachelor
\n","
1/19/11
\n","
Unemployed
\n","
F
\n","
...
\n","
NaN
\n","
7
\n","
Personal Auto
\n","
Personal L1
\n","
Offer3
\n","
Web
\n","
1214.400000
\n","
Luxury Car
\n","
Medsize
\n","
A
\n","
\n","
\n","
10906
\n","
10906
\n","
KX53892
\n","
Oregon
\n","
5259.444853
\n","
No
\n","
Basic
\n","
College
\n","
1/6/11
\n","
Employed
\n","
F
\n","
...
\n","
0.0
\n","
6
\n","
Personal Auto
\n","
Personal L3
\n","
Offer2
\n","
Branch
\n","
273.018929
\n","
Four-Door Car
\n","
Medsize
\n","
A
\n","
\n","
\n","
10907
\n","
10907
\n","
TL39050
\n","
Arizona
\n","
23893.304100
\n","
No
\n","
Extended
\n","
Bachelor
\n","
2/6/11
\n","
Employed
\n","
F
\n","
...
\n","
0.0
\n","
2
\n","
Corporate Auto
\n","
Corporate L3
\n","
Offer1
\n","
Web
\n","
381.306996
\n","
Luxury SUV
\n","
Medsize
\n","
NaN
\n","
\n","
\n","
10908
\n","
10908
\n","
WA60547
\n","
California
\n","
11971.977650
\n","
No
\n","
Premium
\n","
College
\n","
2/13/11
\n","
Employed
\n","
F
\n","
...
\n","
4.0
\n","
6
\n","
Personal Auto
\n","
Personal L1
\n","
Offer1
\n","
Branch
\n","
618.288849
\n","
SUV
\n","
Medsize
\n","
A
\n","
\n","
\n","
10909
\n","
10909
\n","
IV32877
\n","
NaN
\n","
6857.519928
\n","
NaN
\n","
Basic
\n","
Bachelor
\n","
1/8/11
\n","
Unemployed
\n","
M
\n","
...
\n","
0.0
\n","
3
\n","
Personal Auto
\n","
Personal L1
\n","
Offer4
\n","
Web
\n","
1021.719397
\n","
SUV
\n","
Medsize
\n","
NaN
\n","
\n"," \n","
\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":2}]},{"cell_type":"code","source":["pd.to_datetime(df[\"effective_to_date\"], errors=\"ignore\")"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":548},"id":"8fsMLdtgbttb","executionInfo":{"status":"ok","timestamp":1760910943258,"user_tz":-120,"elapsed":49,"user":{"displayName":"Rahala Moindze","userId":"02611134585983790642"}},"outputId":"4a8f793e-1ea0-404d-b273-aa740ab923be"},"id":"8fsMLdtgbttb","execution_count":8,"outputs":[{"output_type":"stream","name":"stderr","text":["/tmp/ipython-input-2338632711.py:1: FutureWarning: errors='ignore' is deprecated and will raise in a future version. Use to_datetime without passing `errors` and catch exceptions explicitly instead\n"," pd.to_datetime(df[\"effective_to_date\"], errors=\"ignore\")\n","/tmp/ipython-input-2338632711.py:1: UserWarning: Could not infer format, so each element will be parsed individually, falling back to `dateutil`. To ensure parsing is consistent and as-expected, please specify a format.\n"," pd.to_datetime(df[\"effective_to_date\"], errors=\"ignore\")\n"]},{"output_type":"execute_result","data":{"text/plain":["2 2011-02-10\n","3 2011-01-11\n","10 2011-01-02\n","13 2011-01-26\n","16 2011-02-07\n"," ... \n","10902 2011-01-24\n","10903 2011-01-07\n","10904 2011-02-24\n","10906 2011-01-06\n","10908 2011-02-13\n","Name: effective_to_date, Length: 4543, dtype: datetime64[ns]"],"text/html":["
"]},"metadata":{},"execution_count":6}]},{"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":"code","source":["#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.\n","df_filtered = df[(df[\"total_claim_amount\"] < 1000) & (df[\"response\"] == \"Yes\")]\n","df_filtered\n"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":652},"id":"m3SNAD9rd5iu","executionInfo":{"status":"ok","timestamp":1760910949694,"user_tz":-120,"elapsed":54,"user":{"displayName":"Rahala Moindze","userId":"02611134585983790642"}},"outputId":"7bbd3662-7684-4ae0-ca80-42d3dc1eef4b"},"id":"m3SNAD9rd5iu","execution_count":9,"outputs":[{"output_type":"execute_result","data":{"text/plain":[" unnamed:_0 customer state customer_lifetime_value response \\\n","3 3 XL78013 Oregon 22332.439460 Yes \n","19 19 NJ54277 California 3746.751625 Yes \n","69 69 QG27547 Oregon 2867.312197 Yes \n","102 102 VG56765 Arizona 2471.528431 Yes \n","113 113 EC28398 Oregon 5096.673223 Yes \n","... ... ... ... ... ... \n","10818 10818 XT35473 Arizona 2300.691547 Yes \n","10825 10825 FB17016 Oregon 5470.060561 Yes \n","10840 10840 ME22430 Nevada 2453.570794 Yes \n","10887 10887 BY78730 Oregon 8879.790017 Yes \n","10897 10897 MM70762 Arizona 9075.768214 Yes \n","\n"," coverage education effective_to_date employmentstatus \\\n","3 Extended College 1/11/11 Employed \n","19 Extended College 2/26/11 Employed \n","69 Extended Bachelor 1/3/11 Retired \n","102 Basic High School or Below 1/15/11 Employed \n","113 Basic Master 1/28/11 Disabled \n","... ... ... ... ... \n","10818 Basic Bachelor 1/15/11 Retired \n","10825 Extended Bachelor 2/17/11 Employed \n","10840 Basic Bachelor 2/9/11 Medical Leave \n","10887 Basic High School or Below 2/3/11 Employed \n","10897 Basic Master 1/26/11 Employed \n","\n"," gender ... number_of_open_complaints number_of_policies \\\n","3 M ... 0.0 2 \n","19 F ... 1.0 1 \n","69 F ... 0.0 1 \n","102 M ... 0.0 1 \n","113 F ... 0.0 3 \n","... ... ... ... ... \n","10818 M ... 0.0 1 \n","10825 F ... 0.0 1 \n","10840 M ... 0.0 1 \n","10887 F ... 0.0 7 \n","10897 M ... 0.0 8 \n","\n"," policy_type policy renew_offer_type sales_channel \\\n","3 Corporate Auto Corporate L3 Offer2 Branch \n","19 Personal Auto Personal L2 Offer2 Call Center \n","69 Personal Auto Personal L3 Offer2 Call Center \n","102 Personal Auto Personal L2 Offer2 Agent \n","113 Corporate Auto Corporate L2 Offer1 Agent \n","... ... ... ... ... \n","10818 Personal Auto Personal L3 Offer1 Agent \n","10825 Personal Auto Personal L3 Offer2 Agent \n","10840 Personal Auto Personal L2 Offer1 Agent \n","10887 Special Auto Special L2 Offer1 Agent \n","10897 Personal Auto Personal L1 Offer1 Agent \n","\n"," total_claim_amount vehicle_class vehicle_size vehicle_type \n","3 484.013411 Four-Door Car Medsize A \n","19 19.575683 Two-Door Car Large A \n","69 374.400000 Four-Door Car Medsize A \n","102 114.273025 Two-Door Car Medsize A \n","113 312.000000 Four-Door Car Small A \n","... ... ... ... ... \n","10818 302.400000 Four-Door Car Large A \n","10825 702.990032 SUV Medsize A \n","10840 331.200000 Four-Door Car Medsize A \n","10887 528.200860 SUV Small A \n","10897 158.077504 Sports Car Medsize A \n","\n","[614 rows x 26 columns]"],"text/html":["\n","
\n","
\n","\n","
\n"," \n","
\n","
\n","
unnamed:_0
\n","
customer
\n","
state
\n","
customer_lifetime_value
\n","
response
\n","
coverage
\n","
education
\n","
effective_to_date
\n","
employmentstatus
\n","
gender
\n","
...
\n","
number_of_open_complaints
\n","
number_of_policies
\n","
policy_type
\n","
policy
\n","
renew_offer_type
\n","
sales_channel
\n","
total_claim_amount
\n","
vehicle_class
\n","
vehicle_size
\n","
vehicle_type
\n","
\n"," \n"," \n","
\n","
3
\n","
3
\n","
XL78013
\n","
Oregon
\n","
22332.439460
\n","
Yes
\n","
Extended
\n","
College
\n","
1/11/11
\n","
Employed
\n","
M
\n","
...
\n","
0.0
\n","
2
\n","
Corporate Auto
\n","
Corporate L3
\n","
Offer2
\n","
Branch
\n","
484.013411
\n","
Four-Door Car
\n","
Medsize
\n","
A
\n","
\n","
\n","
19
\n","
19
\n","
NJ54277
\n","
California
\n","
3746.751625
\n","
Yes
\n","
Extended
\n","
College
\n","
2/26/11
\n","
Employed
\n","
F
\n","
...
\n","
1.0
\n","
1
\n","
Personal Auto
\n","
Personal L2
\n","
Offer2
\n","
Call Center
\n","
19.575683
\n","
Two-Door Car
\n","
Large
\n","
A
\n","
\n","
\n","
69
\n","
69
\n","
QG27547
\n","
Oregon
\n","
2867.312197
\n","
Yes
\n","
Extended
\n","
Bachelor
\n","
1/3/11
\n","
Retired
\n","
F
\n","
...
\n","
0.0
\n","
1
\n","
Personal Auto
\n","
Personal L3
\n","
Offer2
\n","
Call Center
\n","
374.400000
\n","
Four-Door Car
\n","
Medsize
\n","
A
\n","
\n","
\n","
102
\n","
102
\n","
VG56765
\n","
Arizona
\n","
2471.528431
\n","
Yes
\n","
Basic
\n","
High School or Below
\n","
1/15/11
\n","
Employed
\n","
M
\n","
...
\n","
0.0
\n","
1
\n","
Personal Auto
\n","
Personal L2
\n","
Offer2
\n","
Agent
\n","
114.273025
\n","
Two-Door Car
\n","
Medsize
\n","
A
\n","
\n","
\n","
113
\n","
113
\n","
EC28398
\n","
Oregon
\n","
5096.673223
\n","
Yes
\n","
Basic
\n","
Master
\n","
1/28/11
\n","
Disabled
\n","
F
\n","
...
\n","
0.0
\n","
3
\n","
Corporate Auto
\n","
Corporate L2
\n","
Offer1
\n","
Agent
\n","
312.000000
\n","
Four-Door Car
\n","
Small
\n","
A
\n","
\n","
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
\n","
\n","
10818
\n","
10818
\n","
XT35473
\n","
Arizona
\n","
2300.691547
\n","
Yes
\n","
Basic
\n","
Bachelor
\n","
1/15/11
\n","
Retired
\n","
M
\n","
...
\n","
0.0
\n","
1
\n","
Personal Auto
\n","
Personal L3
\n","
Offer1
\n","
Agent
\n","
302.400000
\n","
Four-Door Car
\n","
Large
\n","
A
\n","
\n","
\n","
10825
\n","
10825
\n","
FB17016
\n","
Oregon
\n","
5470.060561
\n","
Yes
\n","
Extended
\n","
Bachelor
\n","
2/17/11
\n","
Employed
\n","
F
\n","
...
\n","
0.0
\n","
1
\n","
Personal Auto
\n","
Personal L3
\n","
Offer2
\n","
Agent
\n","
702.990032
\n","
SUV
\n","
Medsize
\n","
A
\n","
\n","
\n","
10840
\n","
10840
\n","
ME22430
\n","
Nevada
\n","
2453.570794
\n","
Yes
\n","
Basic
\n","
Bachelor
\n","
2/9/11
\n","
Medical Leave
\n","
M
\n","
...
\n","
0.0
\n","
1
\n","
Personal Auto
\n","
Personal L2
\n","
Offer1
\n","
Agent
\n","
331.200000
\n","
Four-Door Car
\n","
Medsize
\n","
A
\n","
\n","
\n","
10887
\n","
10887
\n","
BY78730
\n","
Oregon
\n","
8879.790017
\n","
Yes
\n","
Basic
\n","
High School or Below
\n","
2/3/11
\n","
Employed
\n","
F
\n","
...
\n","
0.0
\n","
7
\n","
Special Auto
\n","
Special L2
\n","
Offer1
\n","
Agent
\n","
528.200860
\n","
SUV
\n","
Small
\n","
A
\n","
\n","
\n","
10897
\n","
10897
\n","
MM70762
\n","
Arizona
\n","
9075.768214
\n","
Yes
\n","
Basic
\n","
Master
\n","
1/26/11
\n","
Employed
\n","
M
\n","
...
\n","
0.0
\n","
8
\n","
Personal Auto
\n","
Personal L1
\n","
Offer1
\n","
Agent
\n","
158.077504
\n","
Sports Car
\n","
Medsize
\n","
A
\n","
\n"," \n","
\n","
614 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_filtered"}},"metadata":{},"execution_count":9}]},{"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":"code","source":["#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 compare these insights to total_claim_amount patterns, and discuss which segments appear most profitable or low-risk for the company.\n","df_filtered = df[df[\"response\"] == \"Yes\"]\n","df_filtered.groupby([\"policy_type\", \"gender\"])[[\"monthly_premium_auto\", \"customer_lifetime_value\"]].mean()\n","\n","\n","\n"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":269},"id":"vYyj3BPWeUVw","executionInfo":{"status":"ok","timestamp":1760911115037,"user_tz":-120,"elapsed":68,"user":{"displayName":"Rahala Moindze","userId":"02611134585983790642"}},"outputId":"390a2759-689a-48e6-eddd-3ef327f264b3"},"id":"vYyj3BPWeUVw","execution_count":11,"outputs":[{"output_type":"execute_result","data":{"text/plain":[" monthly_premium_auto customer_lifetime_value\n","policy_type gender \n","Corporate Auto F 93.597403 8400.519583\n"," M 90.819672 7545.446171\n","Personal Auto F 99.100000 7755.844201\n"," M 92.821429 7402.677522\n","Special Auto F 102.294118 8403.318929\n"," M 84.928571 8655.148804"],"text/html":["\n","
\n","
\n","\n","
\n"," \n","
\n","
\n","
\n","
monthly_premium_auto
\n","
customer_lifetime_value
\n","
\n","
\n","
policy_type
\n","
gender
\n","
\n","
\n","
\n"," \n"," \n","
\n","
Corporate Auto
\n","
F
\n","
93.597403
\n","
8400.519583
\n","
\n","
\n","
M
\n","
90.819672
\n","
7545.446171
\n","
\n","
\n","
Personal Auto
\n","
F
\n","
99.100000
\n","
7755.844201
\n","
\n","
\n","
M
\n","
92.821429
\n","
7402.677522
\n","
\n","
\n","
Special Auto
\n","
F
\n","
102.294118
\n","
8403.318929
\n","
\n","
\n","
M
\n","
84.928571
\n","
8655.148804
\n","
\n"," \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","summary":"{\n \"name\": \"df_filtered\",\n \"rows\": 6,\n \"fields\": [\n {\n \"column\": \"monthly_premium_auto\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 6.143723829765385,\n \"min\": 84.92857142857143,\n \"max\": 102.29411764705883,\n \"num_unique_values\": 6,\n \"samples\": [\n 93.59740259740259,\n 90.81967213114754,\n 84.92857142857143\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"customer_lifetime_value\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 523.6223252488743,\n \"min\": 7402.677521579365,\n \"max\": 8655.148803714286,\n \"num_unique_values\": 6,\n \"samples\": [\n 8400.519582948053,\n 7545.446171163934,\n 8655.148803714286\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"}},"metadata":{},"execution_count":11}]},{"cell_type":"code","source":["#for customers who responded \"Yes\", and compare these insights to total_claim_amount patterns, and discuss which segments appear most profitable or low-risk for the company.\n","df_filtered = df[df[\"response\"] == \"Yes\"]\n","df_filtered.groupby([\"policy_type\", \"gender\"])[[\"total_claim_amount\"]].mean()\n"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":269},"id":"X4-pFT2Re_F-","executionInfo":{"status":"ok","timestamp":1760911176379,"user_tz":-120,"elapsed":65,"user":{"displayName":"Rahala Moindze","userId":"02611134585983790642"}},"outputId":"42b62676-6c8d-42f2-a4d3-dbbc189a6d19"},"id":"X4-pFT2Re_F-","execution_count":12,"outputs":[{"output_type":"execute_result","data":{"text/plain":[" total_claim_amount\n","policy_type gender \n","Corporate Auto F 404.104008\n"," M 391.370774\n","Personal Auto F 457.056315\n"," M 472.489180\n","Special Auto F 495.689401\n"," M 368.523035"],"text/html":["\n","
\n","
\n","\n","
\n"," \n","
\n","
\n","
\n","
total_claim_amount
\n","
\n","
\n","
policy_type
\n","
gender
\n","
\n","
\n"," \n"," \n","
\n","
Corporate Auto
\n","
F
\n","
404.104008
\n","
\n","
\n","
M
\n","
391.370774
\n","
\n","
\n","
Personal Auto
\n","
F
\n","
457.056315
\n","
\n","
\n","
M
\n","
472.489180
\n","
\n","
\n","
Special Auto
\n","
F
\n","
495.689401
\n","
\n","
\n","
M
\n","
368.523035
\n","
\n"," \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","summary":"{\n \"name\": \"df_filtered\",\n \"rows\": 6,\n \"fields\": [\n {\n \"column\": \"total_claim_amount\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 50.557891011578654,\n \"min\": 368.523035,\n \"max\": 495.6894014705882,\n \"num_unique_values\": 6,\n \"samples\": [\n 404.1040077662338,\n 391.3707735409836,\n 368.523035\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"}},"metadata":{},"execution_count":12}]},{"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":"code","source":["#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.\n","df_filtered = df.groupby([\"state\"])[\"customer\"].count()\n","df_filtered[df_filtered > 500]"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":209},"id":"rtoKsNJUfGQJ","executionInfo":{"status":"ok","timestamp":1760911207691,"user_tz":-120,"elapsed":33,"user":{"displayName":"Rahala Moindze","userId":"02611134585983790642"}},"outputId":"1211a818-8ca4-4f29-c124-7d07099c026b"},"id":"rtoKsNJUfGQJ","execution_count":13,"outputs":[{"output_type":"execute_result","data":{"text/plain":["state\n","Arizona 868\n","California 1552\n","Oregon 1281\n","Name: customer, dtype: int64"],"text/html":["
\n","\n","
\n"," \n","
\n","
\n","
customer
\n","
\n","
\n","
state
\n","
\n","
\n"," \n"," \n","
\n","
Arizona
\n","
868
\n","
\n","
\n","
California
\n","
1552
\n","
\n","
\n","
Oregon
\n","
1281
\n","
\n"," \n","
\n","
"]},"metadata":{},"execution_count":13}]},{"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","source":["#Find the maximum, minimum, and median customer lifetime value by education level and gender. Write your conclusions.\n","df_filtered = df.groupby([\"education\", \"gender\"])[\"customer_lifetime_value\"].agg([\"max\", \"min\", \"median\"])\n","df_filtered"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":394},"id":"WPUTVyf6fM-g","executionInfo":{"status":"ok","timestamp":1760911234551,"user_tz":-120,"elapsed":58,"user":{"displayName":"Rahala Moindze","userId":"02611134585983790642"}},"outputId":"4ef96c83-ae25-4f73-c619-5cacd3af7815"},"id":"WPUTVyf6fM-g","execution_count":14,"outputs":[{"output_type":"execute_result","data":{"text/plain":[" max min median\n","education gender \n","Bachelor F 58753.88046 1904.000852 5752.485185\n"," M 67907.27050 2030.783687 5797.377350\n","College F 61850.18803 2004.350666 5642.596077\n"," M 44795.46942 1918.119700 6005.847375\n","Doctor F 44856.11397 2395.570000 5789.850900\n"," M 32677.34284 2267.604038 5843.989737\n","High School or Below F 55277.44589 2150.178588 5978.754765\n"," M 83325.38119 2132.771675 6081.481291\n","Master F 51016.06704 2417.777032 5714.165863\n"," M 50568.25912 2357.503128 5512.342258"],"text/html":["\n","
\n","
\n","\n","
\n"," \n","
\n","
\n","
\n","
max
\n","
min
\n","
median
\n","
\n","
\n","
education
\n","
gender
\n","
\n","
\n","
\n","
\n"," \n"," \n","
\n","
Bachelor
\n","
F
\n","
58753.88046
\n","
1904.000852
\n","
5752.485185
\n","
\n","
\n","
M
\n","
67907.27050
\n","
2030.783687
\n","
5797.377350
\n","
\n","
\n","
College
\n","
F
\n","
61850.18803
\n","
2004.350666
\n","
5642.596077
\n","
\n","
\n","
M
\n","
44795.46942
\n","
1918.119700
\n","
6005.847375
\n","
\n","
\n","
Doctor
\n","
F
\n","
44856.11397
\n","
2395.570000
\n","
5789.850900
\n","
\n","
\n","
M
\n","
32677.34284
\n","
2267.604038
\n","
5843.989737
\n","
\n","
\n","
High School or Below
\n","
F
\n","
55277.44589
\n","
2150.178588
\n","
5978.754765
\n","
\n","
\n","
M
\n","
83325.38119
\n","
2132.771675
\n","
6081.481291
\n","
\n","
\n","
Master
\n","
F
\n","
51016.06704
\n","
2417.777032
\n","
5714.165863
\n","
\n","
\n","
M
\n","
50568.25912
\n","
2357.503128
\n","
5512.342258
\n","
\n"," \n","
\n","
\n","
\n","\n","
\n"," \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_filtered","summary":"{\n \"name\": \"df_filtered\",\n \"rows\": 10,\n \"fields\": [\n {\n \"column\": \"max\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 14026.787480127306,\n \"min\": 32677.34284,\n \"max\": 83325.38119,\n \"num_unique_values\": 10,\n \"samples\": [\n 51016.06704,\n 67907.2705,\n 32677.34284\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"min\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 193.8744872520534,\n \"min\": 1904.000852,\n \"max\": 2417.777032,\n \"num_unique_values\": 10,\n \"samples\": [\n 2417.777032,\n 2030.783687,\n 2267.604038\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"median\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 173.6336279098286,\n \"min\": 5512.342258,\n \"max\": 6081.481291,\n \"num_unique_values\": 10,\n \"samples\": [\n 5714.165863,\n 5797.377350000001,\n 5843.989737\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"}},"metadata":{},"execution_count":14}]},{"cell_type":"code","source":[],"metadata":{"id":"spdYJDjcfYVu"},"id":"spdYJDjcfYVu","execution_count":null,"outputs":[]},{"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":"code","source":["#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.\n","df_filtered = df.groupby([\"state\", \"effective_to_date\"])[\"number_of_policies\"].sum()\n","df_filtered.unstack()"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":287},"id":"_4n-czXFfhFj","executionInfo":{"status":"ok","timestamp":1760911396914,"user_tz":-120,"elapsed":43,"user":{"displayName":"Rahala Moindze","userId":"02611134585983790642"}},"outputId":"5972fbc3-83d0-49d8-9610-a47d29b00148"},"id":"_4n-czXFfhFj","execution_count":16,"outputs":[{"output_type":"execute_result","data":{"text/plain":["effective_to_date 1/1/11 1/10/11 1/11/11 1/12/11 1/13/11 1/14/11 \\\n","state \n","Arizona 55 58 32 49 62 31 \n","California 75 111 121 64 92 64 \n","Nevada 29 10 18 22 12 15 \n","Oregon 71 127 35 38 56 53 \n","Washington 18 30 14 15 16 34 \n","\n","effective_to_date 1/15/11 1/16/11 1/17/11 1/18/11 ... 2/26/11 2/27/11 \\\n","state ... \n","Arizona 45 25 50 70 ... 39 33 \n","California 66 79 58 117 ... 101 51 \n","Nevada 23 8 12 23 ... 21 26 \n","Oregon 47 81 97 77 ... 57 45 \n","Washington 8 15 23 16 ... 13 23 \n","\n","effective_to_date 2/28/11 2/3/11 2/4/11 2/5/11 2/6/11 2/7/11 2/8/11 \\\n","state \n","Arizona 40 79 63 71 38 27 51 \n","California 57 86 70 104 71 100 33 \n","Nevada 41 34 18 14 7 24 42 \n","Oregon 58 82 76 80 67 94 47 \n","Washington 33 21 21 31 23 27 9 \n","\n","effective_to_date 2/9/11 \n","state \n","Arizona 30 \n","California 68 \n","Nevada 8 \n","Oregon 40 \n","Washington 14 \n","\n","[5 rows x 59 columns]"],"text/html":["\n","
\n","
\n","\n","
\n"," \n","
\n","
effective_to_date
\n","
1/1/11
\n","
1/10/11
\n","
1/11/11
\n","
1/12/11
\n","
1/13/11
\n","
1/14/11
\n","
1/15/11
\n","
1/16/11
\n","
1/17/11
\n","
1/18/11
\n","
...
\n","
2/26/11
\n","
2/27/11
\n","
2/28/11
\n","
2/3/11
\n","
2/4/11
\n","
2/5/11
\n","
2/6/11
\n","
2/7/11
\n","
2/8/11
\n","
2/9/11
\n","
\n","
\n","
state
\n","
\n","
\n","
\n","
\n","
\n","
\n","
\n","
\n","
\n","
\n","
\n","
\n","
\n","
\n","
\n","
\n","
\n","
\n","
\n","
\n","
\n","
\n"," \n"," \n","
\n","
Arizona
\n","
55
\n","
58
\n","
32
\n","
49
\n","
62
\n","
31
\n","
45
\n","
25
\n","
50
\n","
70
\n","
...
\n","
39
\n","
33
\n","
40
\n","
79
\n","
63
\n","
71
\n","
38
\n","
27
\n","
51
\n","
30
\n","
\n","
\n","
California
\n","
75
\n","
111
\n","
121
\n","
64
\n","
92
\n","
64
\n","
66
\n","
79
\n","
58
\n","
117
\n","
...
\n","
101
\n","
51
\n","
57
\n","
86
\n","
70
\n","
104
\n","
71
\n","
100
\n","
33
\n","
68
\n","
\n","
\n","
Nevada
\n","
29
\n","
10
\n","
18
\n","
22
\n","
12
\n","
15
\n","
23
\n","
8
\n","
12
\n","
23
\n","
...
\n","
21
\n","
26
\n","
41
\n","
34
\n","
18
\n","
14
\n","
7
\n","
24
\n","
42
\n","
8
\n","
\n","
\n","
Oregon
\n","
71
\n","
127
\n","
35
\n","
38
\n","
56
\n","
53
\n","
47
\n","
81
\n","
97
\n","
77
\n","
...
\n","
57
\n","
45
\n","
58
\n","
82
\n","
76
\n","
80
\n","
67
\n","
94
\n","
47
\n","
40
\n","
\n","
\n","
Washington
\n","
18
\n","
30
\n","
14
\n","
15
\n","
16
\n","
34
\n","
8
\n","
15
\n","
23
\n","
16
\n","
...
\n","
13
\n","
23
\n","
33
\n","
21
\n","
21
\n","
31
\n","
23
\n","
27
\n","
9
\n","
14
\n","
\n"," \n","
\n","
5 rows × 59 columns
\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"}},"metadata":{},"execution_count":16}]},{"cell_type":"code","source":["df = df.drop_duplicates()\n","df.duplicated().sum()\n","df"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":687},"id":"8VCTteGTgQCW","executionInfo":{"status":"ok","timestamp":1760911526859,"user_tz":-120,"elapsed":68,"user":{"displayName":"Rahala Moindze","userId":"02611134585983790642"}},"outputId":"ad3f5bbf-1b92-4678-c34a-d0d9c297a8e0"},"id":"8VCTteGTgQCW","execution_count":18,"outputs":[{"output_type":"execute_result","data":{"text/plain":[" unnamed:_0 customer state customer_lifetime_value response \\\n","2 2 LZ68649 Washington 14947.917300 No \n","3 3 XL78013 Oregon 22332.439460 Yes \n","10 10 HG93801 Arizona 5154.764074 No \n","13 13 KR82385 California 5454.587929 No \n","16 16 FH51383 California 5326.677654 No \n","... ... ... ... ... ... \n","10902 10902 PP30874 California 3579.023825 No \n","10903 10903 SU71163 Arizona 2771.663013 No \n","10904 10904 QI63521 Nevada 19228.463620 No \n","10906 10906 KX53892 Oregon 5259.444853 No \n","10908 10908 WA60547 California 11971.977650 No \n","\n"," coverage education effective_to_date employmentstatus \\\n","2 Basic Bachelor 2/10/11 Employed \n","3 Extended College 1/11/11 Employed \n","10 Extended High School or Below 1/2/11 Employed \n","13 Basic Master 1/26/11 Employed \n","16 Basic High School or Below 2/7/11 Employed \n","... ... ... ... ... \n","10902 Extended High School or Below 1/24/11 Employed \n","10903 Basic College 1/7/11 Employed \n","10904 Basic High School or Below 2/24/11 Unemployed \n","10906 Basic College 1/6/11 Employed \n","10908 Premium College 2/13/11 Employed \n","\n"," gender ... number_of_open_complaints number_of_policies \\\n","2 M ... 0.0 2 \n","3 M ... 0.0 2 \n","10 M ... 0.0 1 \n","13 M ... 0.0 4 \n","16 F ... 0.0 6 \n","... ... ... ... ... \n","10902 F ... 2.0 1 \n","10903 M ... 4.0 1 \n","10904 M ... 0.0 2 \n","10906 F ... 0.0 6 \n","10908 F ... 4.0 6 \n","\n"," policy_type policy renew_offer_type sales_channel \\\n","2 Personal Auto Personal L3 Offer3 Call Center \n","3 Corporate Auto Corporate L3 Offer2 Branch \n","10 Corporate Auto Corporate L3 Offer2 Branch \n","13 Personal Auto Personal L3 Offer4 Call Center \n","16 Personal Auto Personal L3 Offer4 Call Center \n","... ... ... ... ... \n","10902 Personal Auto Personal L2 Offer2 Agent \n","10903 Personal Auto Personal L2 Offer2 Branch \n","10904 Personal Auto Personal L2 Offer1 Branch \n","10906 Personal Auto Personal L3 Offer2 Branch \n","10908 Personal Auto Personal L1 Offer1 Branch \n","\n"," total_claim_amount vehicle_class vehicle_size vehicle_type \n","2 480.000000 SUV Medsize A \n","3 484.013411 Four-Door Car Medsize A \n","10 442.521087 SUV Large A \n","13 331.200000 Two-Door Car Medsize A \n","16 300.528579 Two-Door Car Large A \n","... ... ... ... ... \n","10902 655.200000 Four-Door Car Medsize A \n","10903 355.200000 Two-Door Car Medsize A \n","10904 897.600000 Luxury SUV Medsize A \n","10906 273.018929 Four-Door Car Medsize A \n","10908 618.288849 SUV Medsize A \n","\n","[4543 rows x 26 columns]"],"text/html":["\n","
\n","
\n","\n","
\n"," \n","
\n","
\n","
unnamed:_0
\n","
customer
\n","
state
\n","
customer_lifetime_value
\n","
response
\n","
coverage
\n","
education
\n","
effective_to_date
\n","
employmentstatus
\n","
gender
\n","
...
\n","
number_of_open_complaints
\n","
number_of_policies
\n","
policy_type
\n","
policy
\n","
renew_offer_type
\n","
sales_channel
\n","
total_claim_amount
\n","
vehicle_class
\n","
vehicle_size
\n","
vehicle_type
\n","
\n"," \n"," \n","
\n","
2
\n","
2
\n","
LZ68649
\n","
Washington
\n","
14947.917300
\n","
No
\n","
Basic
\n","
Bachelor
\n","
2/10/11
\n","
Employed
\n","
M
\n","
...
\n","
0.0
\n","
2
\n","
Personal Auto
\n","
Personal L3
\n","
Offer3
\n","
Call Center
\n","
480.000000
\n","
SUV
\n","
Medsize
\n","
A
\n","
\n","
\n","
3
\n","
3
\n","
XL78013
\n","
Oregon
\n","
22332.439460
\n","
Yes
\n","
Extended
\n","
College
\n","
1/11/11
\n","
Employed
\n","
M
\n","
...
\n","
0.0
\n","
2
\n","
Corporate Auto
\n","
Corporate L3
\n","
Offer2
\n","
Branch
\n","
484.013411
\n","
Four-Door Car
\n","
Medsize
\n","
A
\n","
\n","
\n","
10
\n","
10
\n","
HG93801
\n","
Arizona
\n","
5154.764074
\n","
No
\n","
Extended
\n","
High School or Below
\n","
1/2/11
\n","
Employed
\n","
M
\n","
...
\n","
0.0
\n","
1
\n","
Corporate Auto
\n","
Corporate L3
\n","
Offer2
\n","
Branch
\n","
442.521087
\n","
SUV
\n","
Large
\n","
A
\n","
\n","
\n","
13
\n","
13
\n","
KR82385
\n","
California
\n","
5454.587929
\n","
No
\n","
Basic
\n","
Master
\n","
1/26/11
\n","
Employed
\n","
M
\n","
...
\n","
0.0
\n","
4
\n","
Personal Auto
\n","
Personal L3
\n","
Offer4
\n","
Call Center
\n","
331.200000
\n","
Two-Door Car
\n","
Medsize
\n","
A
\n","
\n","
\n","
16
\n","
16
\n","
FH51383
\n","
California
\n","
5326.677654
\n","
No
\n","
Basic
\n","
High School or Below
\n","
2/7/11
\n","
Employed
\n","
F
\n","
...
\n","
0.0
\n","
6
\n","
Personal Auto
\n","
Personal L3
\n","
Offer4
\n","
Call Center
\n","
300.528579
\n","
Two-Door Car
\n","
Large
\n","
A
\n","
\n","
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
...
\n","
\n","
\n","
10902
\n","
10902
\n","
PP30874
\n","
California
\n","
3579.023825
\n","
No
\n","
Extended
\n","
High School or Below
\n","
1/24/11
\n","
Employed
\n","
F
\n","
...
\n","
2.0
\n","
1
\n","
Personal Auto
\n","
Personal L2
\n","
Offer2
\n","
Agent
\n","
655.200000
\n","
Four-Door Car
\n","
Medsize
\n","
A
\n","
\n","
\n","
10903
\n","
10903
\n","
SU71163
\n","
Arizona
\n","
2771.663013
\n","
No
\n","
Basic
\n","
College
\n","
1/7/11
\n","
Employed
\n","
M
\n","
...
\n","
4.0
\n","
1
\n","
Personal Auto
\n","
Personal L2
\n","
Offer2
\n","
Branch
\n","
355.200000
\n","
Two-Door Car
\n","
Medsize
\n","
A
\n","
\n","
\n","
10904
\n","
10904
\n","
QI63521
\n","
Nevada
\n","
19228.463620
\n","
No
\n","
Basic
\n","
High School or Below
\n","
2/24/11
\n","
Unemployed
\n","
M
\n","
...
\n","
0.0
\n","
2
\n","
Personal Auto
\n","
Personal L2
\n","
Offer1
\n","
Branch
\n","
897.600000
\n","
Luxury SUV
\n","
Medsize
\n","
A
\n","
\n","
\n","
10906
\n","
10906
\n","
KX53892
\n","
Oregon
\n","
5259.444853
\n","
No
\n","
Basic
\n","
College
\n","
1/6/11
\n","
Employed
\n","
F
\n","
...
\n","
0.0
\n","
6
\n","
Personal Auto
\n","
Personal L3
\n","
Offer2
\n","
Branch
\n","
273.018929
\n","
Four-Door Car
\n","
Medsize
\n","
A
\n","
\n","
\n","
10908
\n","
10908
\n","
WA60547
\n","
California
\n","
11971.977650
\n","
No
\n","
Premium
\n","
College
\n","
2/13/11
\n","
Employed
\n","
F
\n","
...
\n","
4.0
\n","
6
\n","
Personal Auto
\n","
Personal L1
\n","
Offer1
\n","
Branch
\n","
618.288849
\n","
SUV
\n","
Medsize
\n","
A
\n","
\n"," \n","
\n","
4543 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":18}]},{"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":"code","source":["#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","# Group by state and sum the number of policies to find the total for each state\n","state_policy_counts = df.groupby(\"state\")[\"number_of_policies\"].sum()\n","\n","# Sort the states by the total number of policies in descending order and select the top 3\n","top_3_states = state_policy_counts.sort_values(ascending=False).head(3).index\n","\n","# Filter the original DataFrame to include only the top 3 states\n","df_top_states = df[df[\"state\"].isin(top_3_states)]\n","\n","# Group the filtered data by state and month, sum the policies, and unstack to get the desired format\n","df_policies_by_month_state = df_top_states.groupby([\"state\", df_top_states[\"effective_to_date\"].str.split('/').str[0]])[\"number_of_policies\"].sum().unstack()\n","\n","df_policies_by_month_state"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":175},"id":"xbCYaw-4f82Z","executionInfo":{"status":"ok","timestamp":1760911572424,"user_tz":-120,"elapsed":51,"user":{"displayName":"Rahala Moindze","userId":"02611134585983790642"}},"outputId":"b3f5490d-12ae-425d-aa71-6fe57577ea72"},"id":"xbCYaw-4f82Z","execution_count":20,"outputs":[{"output_type":"execute_result","data":{"text/plain":["effective_to_date 1 2\n","state \n","Arizona 1344 1297\n","California 2439 2158\n","Oregon 2009 1885"],"text/html":["\n","
\n","
\n","\n","
\n"," \n","
\n","
effective_to_date
\n","
1
\n","
2
\n","
\n","
\n","
state
\n","
\n","
\n","
\n"," \n"," \n","
\n","
Arizona
\n","
1344
\n","
1297
\n","
\n","
\n","
California
\n","
2439
\n","
2158
\n","
\n","
\n","
Oregon
\n","
2009
\n","
1885
\n","
\n"," \n","
\n","
\n","
\n","\n","
\n"," \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_policies_by_month_state","summary":"{\n \"name\": \"df_policies_by_month_state\",\n \"rows\": 3,\n \"fields\": [\n {\n \"column\": \"state\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 3,\n \"samples\": [\n \"Arizona\",\n \"California\",\n \"Oregon\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"1\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 551,\n \"min\": 1344,\n \"max\": 2439,\n \"num_unique_values\": 3,\n \"samples\": [\n 1344,\n 2439,\n 2009\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"2\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 439,\n \"min\": 1297,\n \"max\": 2158,\n \"num_unique_values\": 3,\n \"samples\": [\n 1297,\n 2158,\n 1885\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"}},"metadata":{},"execution_count":20}]},{"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":21,"id":"449513f4-0459-46a0-a18d-9398d974c9ad","metadata":{"id":"449513f4-0459-46a0-a18d-9398d974c9ad","colab":{"base_uri":"https://localhost:8080/","height":241},"executionInfo":{"status":"ok","timestamp":1760911665530,"user_tz":-120,"elapsed":60,"user":{"displayName":"Rahala Moindze","userId":"02611134585983790642"}},"outputId":"ee71dc5a-e2e2-4d16-a46d-2b463b405372"},"outputs":[{"output_type":"execute_result","data":{"text/plain":["sales_channel\n","Agent 332\n","Branch 123\n","Call Center 97\n","Web 89\n","Name: response, dtype: int64"],"text/html":["
\n","\n","
\n"," \n","
\n","
\n","
response
\n","
\n","
\n","
sales_channel
\n","
\n","
\n"," \n"," \n","
\n","
Agent
\n","
332
\n","
\n","
\n","
Branch
\n","
123
\n","
\n","
\n","
Call Center
\n","
97
\n","
\n","
\n","
Web
\n","
89
\n","
\n"," \n","
\n","
"]},"metadata":{},"execution_count":21}],"source":["# The marketing team wants to analyze the effect of different marketing channels on the customer response rate. 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.\n","df_filtered = df[df[\"response\"] == \"Yes\"]\n","df_filtered = df_filtered.groupby([\"sales_channel\"])[\"response\"].count()\n","df_filtered"]}],"metadata":{"colab":{"provenance":[{"file_id":"1Zh_-RoDo-Y0W9BYFP8newGqJMRMhmtrE","timestamp":1760911673849}]},"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