diff --git a/[lab-customer-analysis-round-2]TiagoQuaresma.ipynb b/[lab-customer-analysis-round-2]TiagoQuaresma.ipynb new file mode 100644 index 0000000..a701624 --- /dev/null +++ b/[lab-customer-analysis-round-2]TiagoQuaresma.ipynb @@ -0,0 +1,3555 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 282, + "id": "b6fc1519", + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "import warnings\n", + "warnings.filterwarnings('ignore')\n", + "\n", + "import time\n", + "from datetime import date" + ] + }, + { + "cell_type": "code", + "execution_count": 283, + "id": "433add14", + "metadata": {}, + "outputs": [], + "source": [ + "data=pd.read_csv(r'C:\\Users\\Quaresma\\Documents\\IRONHACK\\Lesson 4\\lab-customer-analysis-round-2\\files_for_lab\\csv_files\\marketing_customer_analysis.csv')" + ] + }, + { + "cell_type": "code", + "execution_count": 284, + "id": "6d75b545", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Unnamed: 0CustomerStateCustomer Lifetime ValueResponseCoverageEducationEffective To DateEmploymentStatusGender...Number of Open ComplaintsNumber of PoliciesPolicy TypePolicyRenew Offer TypeSales ChannelTotal Claim AmountVehicle ClassVehicle SizeVehicle Type
00DK49336Arizona4809.216960NoBasicCollege2/18/11EmployedM...0.09Corporate AutoCorporate L3Offer3Agent292.800000Four-Door CarMedsizeNaN
11KX64629California2228.525238NoBasicCollege1/18/11UnemployedF...0.01Personal AutoPersonal L3Offer4Call Center744.924331Four-Door CarMedsizeNaN
22LZ68649Washington14947.917300NoBasicBachelor2/10/11EmployedM...0.02Personal AutoPersonal L3Offer3Call Center480.000000SUVMedsizeA
33XL78013Oregon22332.439460YesExtendedCollege1/11/11EmployedM...0.02Corporate AutoCorporate L3Offer2Branch484.013411Four-Door CarMedsizeA
44QA50777Oregon9025.067525NoPremiumBachelor1/17/11Medical LeaveF...NaN7Personal AutoPersonal L2Offer1Branch707.925645Four-Door CarMedsizeNaN
..................................................................
1090510905FE99816Nevada15563.369440NoPremiumBachelor1/19/11UnemployedF...NaN7Personal AutoPersonal L1Offer3Web1214.400000Luxury CarMedsizeA
1090610906KX53892Oregon5259.444853NoBasicCollege1/6/11EmployedF...0.06Personal AutoPersonal L3Offer2Branch273.018929Four-Door CarMedsizeA
1090710907TL39050Arizona23893.304100NoExtendedBachelor2/6/11EmployedF...0.02Corporate AutoCorporate L3Offer1Web381.306996Luxury SUVMedsizeNaN
1090810908WA60547California11971.977650NoPremiumCollege2/13/11EmployedF...4.06Personal AutoPersonal L1Offer1Branch618.288849SUVMedsizeA
1090910909IV32877NaN6857.519928NaNBasicBachelor1/8/11UnemployedM...0.03Personal AutoPersonal L1Offer4Web1021.719397SUVMedsizeNaN
\n", + "

10910 rows × 26 columns

\n", + "
" + ], + "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]" + ] + }, + "execution_count": 284, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data" + ] + }, + { + "cell_type": "markdown", + "id": "8c8ac2a3", + "metadata": {}, + "source": [ + "### 1 - Show the dataframe shape." + ] + }, + { + "cell_type": "code", + "execution_count": 285, + "id": "9c45d11e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(10910, 26)" + ] + }, + "execution_count": 285, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\n", + "data.shape" + ] + }, + { + "cell_type": "markdown", + "id": "5a4851cb", + "metadata": {}, + "source": [ + "### 2 - Standardize header names." + ] + }, + { + "cell_type": "code", + "execution_count": 286, + "id": "5867d9d6", + "metadata": { + "scrolled": true + }, + "outputs": [], + "source": [ + "\n", + "cols = [data.columns[i].lower().replace(' ', '_') for i in range(len(data.columns))]\n", + " \n", + "data.columns=cols\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 287, + "id": "8a577455", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
customerstatecustomer_lifetime_valueresponsecoverageeducationeffective_to_dateemploymentstatusgenderincome...number_of_open_complaintsnumber_of_policiespolicy_typepolicyrenew_offer_typesales_channeltotal_claim_amountvehicle_classvehicle_sizevehicle_type
0DK49336Arizona4809.216960NoBasicCollege2/18/11EmployedM48029...0.09Corporate AutoCorporate L3Offer3Agent292.800000Four-Door CarMedsizeNaN
1KX64629California2228.525238NoBasicCollege1/18/11UnemployedF0...0.01Personal AutoPersonal L3Offer4Call Center744.924331Four-Door CarMedsizeNaN
2LZ68649Washington14947.917300NoBasicBachelor2/10/11EmployedM22139...0.02Personal AutoPersonal L3Offer3Call Center480.000000SUVMedsizeA
3XL78013Oregon22332.439460YesExtendedCollege1/11/11EmployedM49078...0.02Corporate AutoCorporate L3Offer2Branch484.013411Four-Door CarMedsizeA
4QA50777Oregon9025.067525NoPremiumBachelor1/17/11Medical LeaveF23675...NaN7Personal AutoPersonal L2Offer1Branch707.925645Four-Door CarMedsizeNaN
..................................................................
10905FE99816Nevada15563.369440NoPremiumBachelor1/19/11UnemployedF0...NaN7Personal AutoPersonal L1Offer3Web1214.400000Luxury CarMedsizeA
10906KX53892Oregon5259.444853NoBasicCollege1/6/11EmployedF61146...0.06Personal AutoPersonal L3Offer2Branch273.018929Four-Door CarMedsizeA
10907TL39050Arizona23893.304100NoExtendedBachelor2/6/11EmployedF39837...0.02Corporate AutoCorporate L3Offer1Web381.306996Luxury SUVMedsizeNaN
10908WA60547California11971.977650NoPremiumCollege2/13/11EmployedF64195...4.06Personal AutoPersonal L1Offer1Branch618.288849SUVMedsizeA
10909IV32877NaN6857.519928NaNBasicBachelor1/8/11UnemployedM0...0.03Personal AutoPersonal L1Offer4Web1021.719397SUVMedsizeNaN
\n", + "

10910 rows × 25 columns

\n", + "
" + ], + "text/plain": [ + " customer state customer_lifetime_value response coverage \\\n", + "0 DK49336 Arizona 4809.216960 No Basic \n", + "1 KX64629 California 2228.525238 No Basic \n", + "2 LZ68649 Washington 14947.917300 No Basic \n", + "3 XL78013 Oregon 22332.439460 Yes Extended \n", + "4 QA50777 Oregon 9025.067525 No Premium \n", + "... ... ... ... ... ... \n", + "10905 FE99816 Nevada 15563.369440 No Premium \n", + "10906 KX53892 Oregon 5259.444853 No Basic \n", + "10907 TL39050 Arizona 23893.304100 No Extended \n", + "10908 WA60547 California 11971.977650 No Premium \n", + "10909 IV32877 NaN 6857.519928 NaN Basic \n", + "\n", + " education effective_to_date employmentstatus gender income ... \\\n", + "0 College 2/18/11 Employed M 48029 ... \n", + "1 College 1/18/11 Unemployed F 0 ... \n", + "2 Bachelor 2/10/11 Employed M 22139 ... \n", + "3 College 1/11/11 Employed M 49078 ... \n", + "4 Bachelor 1/17/11 Medical Leave F 23675 ... \n", + "... ... ... ... ... ... ... \n", + "10905 Bachelor 1/19/11 Unemployed F 0 ... \n", + "10906 College 1/6/11 Employed F 61146 ... \n", + "10907 Bachelor 2/6/11 Employed F 39837 ... \n", + "10908 College 2/13/11 Employed F 64195 ... \n", + "10909 Bachelor 1/8/11 Unemployed M 0 ... \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 25 columns]" + ] + }, + "execution_count": 287, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data= data.drop('unnamed:_0', axis=1)\n", + "data" + ] + }, + { + "cell_type": "code", + "execution_count": 288, + "id": "17b61a88", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Index(['customer', 'state', 'customer_lifetime_value', 'response', 'coverage',\n", + " 'education', 'effective_to_date', 'employmentstatus', 'gender',\n", + " 'income', 'location_code', 'marital_status', 'monthly_premium_auto',\n", + " 'months_since_last_claim', 'months_since_policy_inception',\n", + " 'number_of_open_complaints', 'number_of_policies', 'policy_type',\n", + " 'policy', 'renew_offer_type', 'sales_channel', 'total_claim_amount',\n", + " 'vehicle_class', 'vehicle_size', 'vehicle_type'],\n", + " dtype='object')" + ] + }, + "execution_count": 288, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data.columns" + ] + }, + { + "cell_type": "code", + "execution_count": 289, + "id": "eb0e5f31", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0 NaN\n", + "1 NaN\n", + "2 A\n", + "3 A\n", + "4 NaN\n", + " ... \n", + "10905 A\n", + "10906 A\n", + "10907 NaN\n", + "10908 A\n", + "10909 NaN\n", + "Name: vehicle_type, Length: 10910, dtype: object" + ] + }, + "execution_count": 289, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data['vehicle_type']" + ] + }, + { + "cell_type": "markdown", + "id": "edd6cf39", + "metadata": {}, + "source": [ + "### 3 - Which columns are numerical?" + ] + }, + { + "cell_type": "code", + "execution_count": 290, + "id": "483848a2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
customer_lifetime_valueincomemonthly_premium_automonths_since_last_claimmonths_since_policy_inceptionnumber_of_open_complaintsnumber_of_policiestotal_claim_amount
04809.21696048029617.0520.09292.800000
12228.5252380643.0260.01744.924331
214947.9173002213910034.0310.02480.000000
322332.439460490789710.030.02484.013411
49025.06752523675117NaN31NaN7707.925645
...........................
1090515563.3694400253NaN40NaN71214.400000
109065259.44485361146657.0680.06273.018929
1090723893.3041003983720111.0630.02381.306996
1090811971.977650641951580.0274.06618.288849
109096857.519928010131.010.031021.719397
\n", + "

10910 rows × 8 columns

\n", + "
" + ], + "text/plain": [ + " customer_lifetime_value income monthly_premium_auto \\\n", + "0 4809.216960 48029 61 \n", + "1 2228.525238 0 64 \n", + "2 14947.917300 22139 100 \n", + "3 22332.439460 49078 97 \n", + "4 9025.067525 23675 117 \n", + "... ... ... ... \n", + "10905 15563.369440 0 253 \n", + "10906 5259.444853 61146 65 \n", + "10907 23893.304100 39837 201 \n", + "10908 11971.977650 64195 158 \n", + "10909 6857.519928 0 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 total_claim_amount \n", + "0 0.0 9 292.800000 \n", + "1 0.0 1 744.924331 \n", + "2 0.0 2 480.000000 \n", + "3 0.0 2 484.013411 \n", + "4 NaN 7 707.925645 \n", + "... ... ... ... \n", + "10905 NaN 7 1214.400000 \n", + "10906 0.0 6 273.018929 \n", + "10907 0.0 2 381.306996 \n", + "10908 4.0 6 618.288849 \n", + "10909 0.0 3 1021.719397 \n", + "\n", + "[10910 rows x 8 columns]" + ] + }, + "execution_count": 290, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\n", + "numerical= data[['customer_lifetime_value','income','monthly_premium_auto','months_since_last_claim','months_since_policy_inception'\n", + " ,'number_of_open_complaints','number_of_policies','total_claim_amount']]\n", + "numerical" + ] + }, + { + "cell_type": "markdown", + "id": "eb79b2d7", + "metadata": {}, + "source": [ + "### 4 - Which columns are categorical?" + ] + }, + { + "cell_type": "code", + "execution_count": 291, + "id": "158f0243", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
customerstateresponsecoverageeducationeffective_to_dateemploymentstatusgenderlocation_codemarital_statuspolicy_typepolicyrenew_offer_typesales_channelvehicle_classvehicle_sizevehicle_type
0DK49336ArizonaNoBasicCollege2/18/11EmployedMSuburbanMarriedCorporate AutoCorporate L3Offer3AgentFour-Door CarMedsizeNaN
1KX64629CaliforniaNoBasicCollege1/18/11UnemployedFSuburbanSinglePersonal AutoPersonal L3Offer4Call CenterFour-Door CarMedsizeNaN
2LZ68649WashingtonNoBasicBachelor2/10/11EmployedMSuburbanSinglePersonal AutoPersonal L3Offer3Call CenterSUVMedsizeA
3XL78013OregonYesExtendedCollege1/11/11EmployedMSuburbanSingleCorporate AutoCorporate L3Offer2BranchFour-Door CarMedsizeA
4QA50777OregonNoPremiumBachelor1/17/11Medical LeaveFSuburbanMarriedPersonal AutoPersonal L2Offer1BranchFour-Door CarMedsizeNaN
......................................................
10905FE99816NevadaNoPremiumBachelor1/19/11UnemployedFSuburbanMarriedPersonal AutoPersonal L1Offer3WebLuxury CarMedsizeA
10906KX53892OregonNoBasicCollege1/6/11EmployedFUrbanMarriedPersonal AutoPersonal L3Offer2BranchFour-Door CarMedsizeA
10907TL39050ArizonaNoExtendedBachelor2/6/11EmployedFRuralMarriedCorporate AutoCorporate L3Offer1WebLuxury SUVMedsizeNaN
10908WA60547CaliforniaNoPremiumCollege2/13/11EmployedFUrbanDivorcedPersonal AutoPersonal L1Offer1BranchSUVMedsizeA
10909IV32877NaNNaNBasicBachelor1/8/11UnemployedMSuburbanSinglePersonal AutoPersonal L1Offer4WebSUVMedsizeNaN
\n", + "

10910 rows × 17 columns

\n", + "
" + ], + "text/plain": [ + " customer state response coverage education effective_to_date \\\n", + "0 DK49336 Arizona No Basic College 2/18/11 \n", + "1 KX64629 California No Basic College 1/18/11 \n", + "2 LZ68649 Washington No Basic Bachelor 2/10/11 \n", + "3 XL78013 Oregon Yes Extended College 1/11/11 \n", + "4 QA50777 Oregon No Premium Bachelor 1/17/11 \n", + "... ... ... ... ... ... ... \n", + "10905 FE99816 Nevada No Premium Bachelor 1/19/11 \n", + "10906 KX53892 Oregon No Basic College 1/6/11 \n", + "10907 TL39050 Arizona No Extended Bachelor 2/6/11 \n", + "10908 WA60547 California No Premium College 2/13/11 \n", + "10909 IV32877 NaN NaN Basic Bachelor 1/8/11 \n", + "\n", + " employmentstatus gender location_code marital_status policy_type \\\n", + "0 Employed M Suburban Married Corporate Auto \n", + "1 Unemployed F Suburban Single Personal Auto \n", + "2 Employed M Suburban Single Personal Auto \n", + "3 Employed M Suburban Single Corporate Auto \n", + "4 Medical Leave F Suburban Married Personal Auto \n", + "... ... ... ... ... ... \n", + "10905 Unemployed F Suburban Married Personal Auto \n", + "10906 Employed F Urban Married Personal Auto \n", + "10907 Employed F Rural Married Corporate Auto \n", + "10908 Employed F Urban Divorced Personal Auto \n", + "10909 Unemployed M Suburban Single Personal Auto \n", + "\n", + " policy renew_offer_type sales_channel vehicle_class \\\n", + "0 Corporate L3 Offer3 Agent Four-Door Car \n", + "1 Personal L3 Offer4 Call Center Four-Door Car \n", + "2 Personal L3 Offer3 Call Center SUV \n", + "3 Corporate L3 Offer2 Branch Four-Door Car \n", + "4 Personal L2 Offer1 Branch Four-Door Car \n", + "... ... ... ... ... \n", + "10905 Personal L1 Offer3 Web Luxury Car \n", + "10906 Personal L3 Offer2 Branch Four-Door Car \n", + "10907 Corporate L3 Offer1 Web Luxury SUV \n", + "10908 Personal L1 Offer1 Branch SUV \n", + "10909 Personal L1 Offer4 Web SUV \n", + "\n", + " vehicle_size vehicle_type \n", + "0 Medsize NaN \n", + "1 Medsize NaN \n", + "2 Medsize A \n", + "3 Medsize A \n", + "4 Medsize NaN \n", + "... ... ... \n", + "10905 Medsize A \n", + "10906 Medsize A \n", + "10907 Medsize NaN \n", + "10908 Medsize A \n", + "10909 Medsize NaN \n", + "\n", + "[10910 rows x 17 columns]" + ] + }, + "execution_count": 291, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\n", + "categorical=data[['customer','state','response','coverage','education','effective_to_date','employmentstatus','gender','location_code'\n", + " ,'marital_status','policy_type','policy','renew_offer_type','sales_channel','vehicle_class','vehicle_size','vehicle_type']]\n", + "\n", + "categorical" + ] + }, + { + "cell_type": "markdown", + "id": "91d78930", + "metadata": {}, + "source": [ + "### 5 -Check and deal with NaN values." + ] + }, + { + "cell_type": "code", + "execution_count": 292, + "id": "567194b0", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "customer 0\n", + "state 631\n", + "customer_lifetime_value 0\n", + "response 631\n", + "coverage 0\n", + "education 0\n", + "effective_to_date 0\n", + "employmentstatus 0\n", + "gender 0\n", + "income 0\n", + "location_code 0\n", + "marital_status 0\n", + "monthly_premium_auto 0\n", + "months_since_last_claim 633\n", + "months_since_policy_inception 0\n", + "number_of_open_complaints 633\n", + "number_of_policies 0\n", + "policy_type 0\n", + "policy 0\n", + "renew_offer_type 0\n", + "sales_channel 0\n", + "total_claim_amount 0\n", + "vehicle_class 622\n", + "vehicle_size 622\n", + "vehicle_type 5482\n", + "dtype: int64" + ] + }, + "execution_count": 292, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# 5 -Check and deal with NaN values.\n", + "data.isna().sum()\n", + "#data.isna().sum().sum()\n", + "\n", + "#Drop 85% of the data set is a significant loss, so we have to treat them" + ] + }, + { + "cell_type": "code", + "execution_count": 293, + "id": "dc42fe64", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([nan, 'A'], dtype=object)" + ] + }, + "execution_count": 293, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data['vehicle_type'].unique()\n", + "#Since we only have 1 option and the Nan's are more or less 50% of the data set. I will drop this columns" + ] + }, + { + "cell_type": "code", + "execution_count": 294, + "id": "af64a942", + "metadata": {}, + "outputs": [], + "source": [ + "data= data.drop('vehicle_type', axis=1)" + ] + }, + { + "cell_type": "code", + "execution_count": 295, + "id": "c872f5b3", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
stateresponsemonths_since_last_claimnumber_of_open_complaintsvehicle_classvehicle_size
4OregonNoNaNNaNFour-Door CarMedsize
5NaNNaN2.00.0Four-Door CarMedsize
11NaNNaN5.00.0Two-Door CarMedsize
23CaliforniaNoNaNNaNFour-Door CarMedsize
51ArizonaNoNaNNaNFour-Door CarLarge
.....................
10883OregonNo18.03.0NaNNaN
10890OregonNo24.00.0NaNNaN
10894NaNNaN13.00.0Four-Door CarSmall
10905NevadaNoNaNNaNLuxury CarMedsize
10909NaNNaN31.00.0SUVMedsize
\n", + "

1776 rows × 6 columns

\n", + "
" + ], + "text/plain": [ + " state response months_since_last_claim \\\n", + "4 Oregon No NaN \n", + "5 NaN NaN 2.0 \n", + "11 NaN NaN 5.0 \n", + "23 California No NaN \n", + "51 Arizona No NaN \n", + "... ... ... ... \n", + "10883 Oregon No 18.0 \n", + "10890 Oregon No 24.0 \n", + "10894 NaN NaN 13.0 \n", + "10905 Nevada No NaN \n", + "10909 NaN NaN 31.0 \n", + "\n", + " number_of_open_complaints vehicle_class vehicle_size \n", + "4 NaN Four-Door Car Medsize \n", + "5 0.0 Four-Door Car Medsize \n", + "11 0.0 Two-Door Car Medsize \n", + "23 NaN Four-Door Car Medsize \n", + "51 NaN Four-Door Car Large \n", + "... ... ... ... \n", + "10883 3.0 NaN NaN \n", + "10890 0.0 NaN NaN \n", + "10894 0.0 Four-Door Car Small \n", + "10905 NaN Luxury Car Medsize \n", + "10909 0.0 SUV Medsize \n", + "\n", + "[1776 rows x 6 columns]" + ] + }, + "execution_count": 295, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "condition=data.isnull().any(axis=1)\n", + "data[condition][['state','response','months_since_last_claim','number_of_open_complaints','vehicle_class','vehicle_size']]\n", + "\n", + "#Since the percentage is singnificante I will find a way to fill them." + ] + }, + { + "cell_type": "code", + "execution_count": 315, + "id": "fab8d10f", + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "#for state\n", + "#data['state'] = data['state'].fillna(data['state'].mode())\n", + "#data['state'] = data['state'].fillna(data['state'].mode)\n", + "data['state'] = data['state'].fillna(data['state'].mode().iloc[0]) \n", + "#for response\n", + "data['response'] = data['response'].fillna(data['response'].mode)\n", + "#for months_since_last_claim \n", + "# Since the mean is sensitive to outliers, I will use the median to keep the dataset consistent and unbias\n", + "data['months_since_last_claim'] = data['months_since_last_claim'].fillna(data['months_since_last_claim'].median())\n", + "#for number_of_open_complaints\n", + "data['number_of_open_complaints'] = data['number_of_open_complaints'].fillna(data['number_of_open_complaints'].mode().iloc[0])\n", + "#for vehicle_class\n", + "data['vehicle_class'] = data['vehicle_class'].fillna(data['vehicle_class'].mode().iloc[0])\n", + "#for vehicle_size\t\n", + "data['vehicle_size'] = data['vehicle_size'].fillna(data['vehicle_size'].mode().iloc[0])\n" + ] + }, + { + "cell_type": "code", + "execution_count": 316, + "id": "35db1a27", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "customer 0\n", + "state 0\n", + "customer_lifetime_value 0\n", + "response 0\n", + "coverage 0\n", + "education 0\n", + "effective_to_date 0\n", + "employmentstatus 0\n", + "gender 0\n", + "income 0\n", + "location_code 0\n", + "marital_status 0\n", + "monthly_premium_auto 0\n", + "months_since_last_claim 0\n", + "months_since_policy_inception 0\n", + "number_of_open_complaints 0\n", + "number_of_policies 0\n", + "policy_type 0\n", + "policy 0\n", + "renew_offer_type 0\n", + "sales_channel 0\n", + "total_claim_amount 0\n", + "vehicle_class 0\n", + "vehicle_size 0\n", + "dtype: int64" + ] + }, + "execution_count": 316, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + " data.isna().sum()" + ] + }, + { + "cell_type": "code", + "execution_count": 312, + "id": "f3fd380f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array(['Arizona', 'California', 'Washington', 'Oregon', 'Nevada'],\n", + " dtype=object)" + ] + }, + "execution_count": 312, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data['state'].unique()" + ] + }, + { + "cell_type": "markdown", + "id": "550c5a56", + "metadata": {}, + "source": [ + "### 6 - Datetime format - Extract the months from the dataset and store in a separate column. Then filter the data to show only the information for the first quarter , ie. January, February and March. Hint: If data from March does not exist, consider only January and February." + ] + }, + { + "cell_type": "code", + "execution_count": 184, + "id": "5c2b77c7", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
customerstatecustomer_lifetime_valueresponsecoverageeducationeffective_to_dateemploymentstatusgenderincome...number_of_open_complaintsnumber_of_policiespolicy_typepolicyrenew_offer_typesales_channeltotal_claim_amountvehicle_classvehicle_sizeeffective_to_date_og
0DK49336Arizona4809.216960NoBasicCollege2/18/11EmployedM48029...0.09Corporate AutoCorporate L3Offer3Agent292.800000Four-Door CarMedsize2011-02-18
1KX64629California2228.525238NoBasicCollege1/18/11UnemployedF0...0.01Personal AutoPersonal L3Offer4Call Center744.924331Four-Door CarMedsize2011-01-18
2LZ68649Washington14947.917300NoBasicBachelor2/10/11EmployedM22139...0.02Personal AutoPersonal L3Offer3Call Center480.000000SUVMedsize2011-02-10
3XL78013Oregon22332.439460YesExtendedCollege1/11/11EmployedM49078...0.02Corporate AutoCorporate L3Offer2Branch484.013411Four-Door CarMedsize2011-01-11
4QA50777Oregon9025.067525NoPremiumBachelor1/17/11Medical LeaveF23675...NaN7Personal AutoPersonal L2Offer1Branch707.925645Four-Door CarMedsize2011-01-17
..................................................................
10905FE99816Nevada15563.369440NoPremiumBachelor1/19/11UnemployedF0...NaN7Personal AutoPersonal L1Offer3Web1214.400000Luxury CarMedsize2011-01-19
10906KX53892Oregon5259.444853NoBasicCollege1/6/11EmployedF61146...0.06Personal AutoPersonal L3Offer2Branch273.018929Four-Door CarMedsize2011-01-06
10907TL39050Arizona23893.304100NoExtendedBachelor2/6/11EmployedF39837...0.02Corporate AutoCorporate L3Offer1Web381.306996Luxury SUVMedsize2011-02-06
10908WA60547California11971.977650NoPremiumCollege2/13/11EmployedF64195...4.06Personal AutoPersonal L1Offer1Branch618.288849SUVMedsize2011-02-13
10909IV32877NaN6857.519928NaNBasicBachelor1/8/11UnemployedM0...0.03Personal AutoPersonal L1Offer4Web1021.719397SUVMedsize2011-01-08
\n", + "

10910 rows × 25 columns

\n", + "
" + ], + "text/plain": [ + " customer state customer_lifetime_value response coverage \\\n", + "0 DK49336 Arizona 4809.216960 No Basic \n", + "1 KX64629 California 2228.525238 No Basic \n", + "2 LZ68649 Washington 14947.917300 No Basic \n", + "3 XL78013 Oregon 22332.439460 Yes Extended \n", + "4 QA50777 Oregon 9025.067525 No Premium \n", + "... ... ... ... ... ... \n", + "10905 FE99816 Nevada 15563.369440 No Premium \n", + "10906 KX53892 Oregon 5259.444853 No Basic \n", + "10907 TL39050 Arizona 23893.304100 No Extended \n", + "10908 WA60547 California 11971.977650 No Premium \n", + "10909 IV32877 NaN 6857.519928 NaN Basic \n", + "\n", + " education effective_to_date employmentstatus gender income ... \\\n", + "0 College 2/18/11 Employed M 48029 ... \n", + "1 College 1/18/11 Unemployed F 0 ... \n", + "2 Bachelor 2/10/11 Employed M 22139 ... \n", + "3 College 1/11/11 Employed M 49078 ... \n", + "4 Bachelor 1/17/11 Medical Leave F 23675 ... \n", + "... ... ... ... ... ... ... \n", + "10905 Bachelor 1/19/11 Unemployed F 0 ... \n", + "10906 College 1/6/11 Employed F 61146 ... \n", + "10907 Bachelor 2/6/11 Employed F 39837 ... \n", + "10908 College 2/13/11 Employed F 64195 ... \n", + "10909 Bachelor 1/8/11 Unemployed M 0 ... \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 effective_to_date_og \n", + "0 Four-Door Car Medsize 2011-02-18 \n", + "1 Four-Door Car Medsize 2011-01-18 \n", + "2 SUV Medsize 2011-02-10 \n", + "3 Four-Door Car Medsize 2011-01-11 \n", + "4 Four-Door Car Medsize 2011-01-17 \n", + "... ... ... ... \n", + "10905 Luxury Car Medsize 2011-01-19 \n", + "10906 Four-Door Car Medsize 2011-01-06 \n", + "10907 Luxury SUV Medsize 2011-02-06 \n", + "10908 SUV Medsize 2011-02-13 \n", + "10909 SUV Medsize 2011-01-08 \n", + "\n", + "[10910 rows x 25 columns]" + ] + }, + "execution_count": 184, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data['effective_to_date_og']= pd.to_datetime(data['effective_to_date'])\n", + "data" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "551bcc6b", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 185, + "id": "59452680", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
customerstatecustomer_lifetime_valueresponsecoverageeducationeffective_to_dateemploymentstatusgenderincome...number_of_policiespolicy_typepolicyrenew_offer_typesales_channeltotal_claim_amountvehicle_classvehicle_sizeeffective_to_date_ogmonth
0DK49336Arizona4809.216960NoBasicCollege2/18/11EmployedM48029...9Corporate AutoCorporate L3Offer3Agent292.800000Four-Door CarMedsize2011-02-182
1KX64629California2228.525238NoBasicCollege1/18/11UnemployedF0...1Personal AutoPersonal L3Offer4Call Center744.924331Four-Door CarMedsize2011-01-181
2LZ68649Washington14947.917300NoBasicBachelor2/10/11EmployedM22139...2Personal AutoPersonal L3Offer3Call Center480.000000SUVMedsize2011-02-102
3XL78013Oregon22332.439460YesExtendedCollege1/11/11EmployedM49078...2Corporate AutoCorporate L3Offer2Branch484.013411Four-Door CarMedsize2011-01-111
4QA50777Oregon9025.067525NoPremiumBachelor1/17/11Medical LeaveF23675...7Personal AutoPersonal L2Offer1Branch707.925645Four-Door CarMedsize2011-01-171
..................................................................
10905FE99816Nevada15563.369440NoPremiumBachelor1/19/11UnemployedF0...7Personal AutoPersonal L1Offer3Web1214.400000Luxury CarMedsize2011-01-191
10906KX53892Oregon5259.444853NoBasicCollege1/6/11EmployedF61146...6Personal AutoPersonal L3Offer2Branch273.018929Four-Door CarMedsize2011-01-061
10907TL39050Arizona23893.304100NoExtendedBachelor2/6/11EmployedF39837...2Corporate AutoCorporate L3Offer1Web381.306996Luxury SUVMedsize2011-02-062
10908WA60547California11971.977650NoPremiumCollege2/13/11EmployedF64195...6Personal AutoPersonal L1Offer1Branch618.288849SUVMedsize2011-02-132
10909IV32877NaN6857.519928NaNBasicBachelor1/8/11UnemployedM0...3Personal AutoPersonal L1Offer4Web1021.719397SUVMedsize2011-01-081
\n", + "

10910 rows × 26 columns

\n", + "
" + ], + "text/plain": [ + " customer state customer_lifetime_value response coverage \\\n", + "0 DK49336 Arizona 4809.216960 No Basic \n", + "1 KX64629 California 2228.525238 No Basic \n", + "2 LZ68649 Washington 14947.917300 No Basic \n", + "3 XL78013 Oregon 22332.439460 Yes Extended \n", + "4 QA50777 Oregon 9025.067525 No Premium \n", + "... ... ... ... ... ... \n", + "10905 FE99816 Nevada 15563.369440 No Premium \n", + "10906 KX53892 Oregon 5259.444853 No Basic \n", + "10907 TL39050 Arizona 23893.304100 No Extended \n", + "10908 WA60547 California 11971.977650 No Premium \n", + "10909 IV32877 NaN 6857.519928 NaN Basic \n", + "\n", + " education effective_to_date employmentstatus gender income ... \\\n", + "0 College 2/18/11 Employed M 48029 ... \n", + "1 College 1/18/11 Unemployed F 0 ... \n", + "2 Bachelor 2/10/11 Employed M 22139 ... \n", + "3 College 1/11/11 Employed M 49078 ... \n", + "4 Bachelor 1/17/11 Medical Leave F 23675 ... \n", + "... ... ... ... ... ... ... \n", + "10905 Bachelor 1/19/11 Unemployed F 0 ... \n", + "10906 College 1/6/11 Employed F 61146 ... \n", + "10907 Bachelor 2/6/11 Employed F 39837 ... \n", + "10908 College 2/13/11 Employed F 64195 ... \n", + "10909 Bachelor 1/8/11 Unemployed M 0 ... \n", + "\n", + " number_of_policies policy_type policy renew_offer_type \\\n", + "0 9 Corporate Auto Corporate L3 Offer3 \n", + "1 1 Personal Auto Personal L3 Offer4 \n", + "2 2 Personal Auto Personal L3 Offer3 \n", + "3 2 Corporate Auto Corporate L3 Offer2 \n", + "4 7 Personal Auto Personal L2 Offer1 \n", + "... ... ... ... ... \n", + "10905 7 Personal Auto Personal L1 Offer3 \n", + "10906 6 Personal Auto Personal L3 Offer2 \n", + "10907 2 Corporate Auto Corporate L3 Offer1 \n", + "10908 6 Personal Auto Personal L1 Offer1 \n", + "10909 3 Personal Auto Personal L1 Offer4 \n", + "\n", + " sales_channel total_claim_amount vehicle_class vehicle_size \\\n", + "0 Agent 292.800000 Four-Door Car Medsize \n", + "1 Call Center 744.924331 Four-Door Car Medsize \n", + "2 Call Center 480.000000 SUV Medsize \n", + "3 Branch 484.013411 Four-Door Car Medsize \n", + "4 Branch 707.925645 Four-Door Car Medsize \n", + "... ... ... ... ... \n", + "10905 Web 1214.400000 Luxury Car Medsize \n", + "10906 Branch 273.018929 Four-Door Car Medsize \n", + "10907 Web 381.306996 Luxury SUV Medsize \n", + "10908 Branch 618.288849 SUV Medsize \n", + "10909 Web 1021.719397 SUV Medsize \n", + "\n", + " effective_to_date_og month \n", + "0 2011-02-18 2 \n", + "1 2011-01-18 1 \n", + "2 2011-02-10 2 \n", + "3 2011-01-11 1 \n", + "4 2011-01-17 1 \n", + "... ... ... \n", + "10905 2011-01-19 1 \n", + "10906 2011-01-06 1 \n", + "10907 2011-02-06 2 \n", + "10908 2011-02-13 2 \n", + "10909 2011-01-08 1 \n", + "\n", + "[10910 rows x 26 columns]" + ] + }, + "execution_count": 185, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data['month']= data['effective_to_date_og'].dt.month\n", + "data" + ] + }, + { + "cell_type": "code", + "execution_count": 187, + "id": "798836a2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
customerstatecustomer_lifetime_valueresponsecoverageeducationeffective_to_dateemploymentstatusgenderincome...number_of_policiespolicy_typepolicyrenew_offer_typesales_channeltotal_claim_amountvehicle_classvehicle_sizeeffective_to_date_ogmonth
0DK49336Arizona4809.216960NoBasicCollege2/18/11EmployedM48029...9Corporate AutoCorporate L3Offer3Agent292.800000Four-Door CarMedsize2011-02-182
1KX64629California2228.525238NoBasicCollege1/18/11UnemployedF0...1Personal AutoPersonal L3Offer4Call Center744.924331Four-Door CarMedsize2011-01-181
2LZ68649Washington14947.917300NoBasicBachelor2/10/11EmployedM22139...2Personal AutoPersonal L3Offer3Call Center480.000000SUVMedsize2011-02-102
3XL78013Oregon22332.439460YesExtendedCollege1/11/11EmployedM49078...2Corporate AutoCorporate L3Offer2Branch484.013411Four-Door CarMedsize2011-01-111
4QA50777Oregon9025.067525NoPremiumBachelor1/17/11Medical LeaveF23675...7Personal AutoPersonal L2Offer1Branch707.925645Four-Door CarMedsize2011-01-171
..................................................................
10905FE99816Nevada15563.369440NoPremiumBachelor1/19/11UnemployedF0...7Personal AutoPersonal L1Offer3Web1214.400000Luxury CarMedsize2011-01-191
10906KX53892Oregon5259.444853NoBasicCollege1/6/11EmployedF61146...6Personal AutoPersonal L3Offer2Branch273.018929Four-Door CarMedsize2011-01-061
10907TL39050Arizona23893.304100NoExtendedBachelor2/6/11EmployedF39837...2Corporate AutoCorporate L3Offer1Web381.306996Luxury SUVMedsize2011-02-062
10908WA60547California11971.977650NoPremiumCollege2/13/11EmployedF64195...6Personal AutoPersonal L1Offer1Branch618.288849SUVMedsize2011-02-132
10909IV32877NaN6857.519928NaNBasicBachelor1/8/11UnemployedM0...3Personal AutoPersonal L1Offer4Web1021.719397SUVMedsize2011-01-081
\n", + "

10910 rows × 26 columns

\n", + "
" + ], + "text/plain": [ + " customer state customer_lifetime_value response coverage \\\n", + "0 DK49336 Arizona 4809.216960 No Basic \n", + "1 KX64629 California 2228.525238 No Basic \n", + "2 LZ68649 Washington 14947.917300 No Basic \n", + "3 XL78013 Oregon 22332.439460 Yes Extended \n", + "4 QA50777 Oregon 9025.067525 No Premium \n", + "... ... ... ... ... ... \n", + "10905 FE99816 Nevada 15563.369440 No Premium \n", + "10906 KX53892 Oregon 5259.444853 No Basic \n", + "10907 TL39050 Arizona 23893.304100 No Extended \n", + "10908 WA60547 California 11971.977650 No Premium \n", + "10909 IV32877 NaN 6857.519928 NaN Basic \n", + "\n", + " education effective_to_date employmentstatus gender income ... \\\n", + "0 College 2/18/11 Employed M 48029 ... \n", + "1 College 1/18/11 Unemployed F 0 ... \n", + "2 Bachelor 2/10/11 Employed M 22139 ... \n", + "3 College 1/11/11 Employed M 49078 ... \n", + "4 Bachelor 1/17/11 Medical Leave F 23675 ... \n", + "... ... ... ... ... ... ... \n", + "10905 Bachelor 1/19/11 Unemployed F 0 ... \n", + "10906 College 1/6/11 Employed F 61146 ... \n", + "10907 Bachelor 2/6/11 Employed F 39837 ... \n", + "10908 College 2/13/11 Employed F 64195 ... \n", + "10909 Bachelor 1/8/11 Unemployed M 0 ... \n", + "\n", + " number_of_policies policy_type policy renew_offer_type \\\n", + "0 9 Corporate Auto Corporate L3 Offer3 \n", + "1 1 Personal Auto Personal L3 Offer4 \n", + "2 2 Personal Auto Personal L3 Offer3 \n", + "3 2 Corporate Auto Corporate L3 Offer2 \n", + "4 7 Personal Auto Personal L2 Offer1 \n", + "... ... ... ... ... \n", + "10905 7 Personal Auto Personal L1 Offer3 \n", + "10906 6 Personal Auto Personal L3 Offer2 \n", + "10907 2 Corporate Auto Corporate L3 Offer1 \n", + "10908 6 Personal Auto Personal L1 Offer1 \n", + "10909 3 Personal Auto Personal L1 Offer4 \n", + "\n", + " sales_channel total_claim_amount vehicle_class vehicle_size \\\n", + "0 Agent 292.800000 Four-Door Car Medsize \n", + "1 Call Center 744.924331 Four-Door Car Medsize \n", + "2 Call Center 480.000000 SUV Medsize \n", + "3 Branch 484.013411 Four-Door Car Medsize \n", + "4 Branch 707.925645 Four-Door Car Medsize \n", + "... ... ... ... ... \n", + "10905 Web 1214.400000 Luxury Car Medsize \n", + "10906 Branch 273.018929 Four-Door Car Medsize \n", + "10907 Web 381.306996 Luxury SUV Medsize \n", + "10908 Branch 618.288849 SUV Medsize \n", + "10909 Web 1021.719397 SUV Medsize \n", + "\n", + " effective_to_date_og month \n", + "0 2011-02-18 2 \n", + "1 2011-01-18 1 \n", + "2 2011-02-10 2 \n", + "3 2011-01-11 1 \n", + "4 2011-01-17 1 \n", + "... ... ... \n", + "10905 2011-01-19 1 \n", + "10906 2011-01-06 1 \n", + "10907 2011-02-06 2 \n", + "10908 2011-02-13 2 \n", + "10909 2011-01-08 1 \n", + "\n", + "[10910 rows x 26 columns]" + ] + }, + "execution_count": 187, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#assuming there is no -1 or something\n", + "first_quarter= data[data['month']<=3]\n", + "first_quarter" + ] + }, + { + "cell_type": "code", + "execution_count": 317, + "id": "78a02ea2", + "metadata": {}, + "outputs": [], + "source": [ + "def data_tranformation(df, coluna_date):\n", + " df[coluna_date]= pd.to_datetime(df[coluna_date])\n", + " \n", + " df['quarter']= df[coluna_date].dt.quarter\n", + " first_quarter= df[df['quarter']==1]\n", + " \n", + " return first_quarter\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 318, + "id": "156b16ef", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
customerstatecustomer_lifetime_valueresponsecoverageeducationeffective_to_dateemploymentstatusgenderincome...number_of_open_complaintsnumber_of_policiespolicy_typepolicyrenew_offer_typesales_channeltotal_claim_amountvehicle_classvehicle_sizequarter
0DK49336Arizona4809.216960NoBasicCollege2011-02-18EmployedM48029...0.09Corporate AutoCorporate L3Offer3Agent292.800000Four-Door CarMedsize1
1KX64629California2228.525238NoBasicCollege2011-01-18UnemployedF0...0.01Personal AutoPersonal L3Offer4Call Center744.924331Four-Door CarMedsize1
2LZ68649Washington14947.917300NoBasicBachelor2011-02-10EmployedM22139...0.02Personal AutoPersonal L3Offer3Call Center480.000000SUVMedsize1
3XL78013Oregon22332.439460YesExtendedCollege2011-01-11EmployedM49078...0.02Corporate AutoCorporate L3Offer2Branch484.013411Four-Door CarMedsize1
4QA50777Oregon9025.067525NoPremiumBachelor2011-01-17Medical LeaveF23675...0.07Personal AutoPersonal L2Offer1Branch707.925645Four-Door CarMedsize1
..................................................................
10905FE99816Nevada15563.369440NoPremiumBachelor2011-01-19UnemployedF0...0.07Personal AutoPersonal L1Offer3Web1214.400000Luxury CarMedsize1
10906KX53892Oregon5259.444853NoBasicCollege2011-01-06EmployedF61146...0.06Personal AutoPersonal L3Offer2Branch273.018929Four-Door CarMedsize1
10907TL39050Arizona23893.304100NoExtendedBachelor2011-02-06EmployedF39837...0.02Corporate AutoCorporate L3Offer1Web381.306996Luxury SUVMedsize1
10908WA60547California11971.977650NoPremiumCollege2011-02-13EmployedF64195...4.06Personal AutoPersonal L1Offer1Branch618.288849SUVMedsize1
10909IV32877California6857.519928<bound method Series.mode of 0 No\\n1 ...BasicBachelor2011-01-08UnemployedM0...0.03Personal AutoPersonal L1Offer4Web1021.719397SUVMedsize1
\n", + "

10910 rows × 25 columns

\n", + "
" + ], + "text/plain": [ + " customer state customer_lifetime_value \\\n", + "0 DK49336 Arizona 4809.216960 \n", + "1 KX64629 California 2228.525238 \n", + "2 LZ68649 Washington 14947.917300 \n", + "3 XL78013 Oregon 22332.439460 \n", + "4 QA50777 Oregon 9025.067525 \n", + "... ... ... ... \n", + "10905 FE99816 Nevada 15563.369440 \n", + "10906 KX53892 Oregon 5259.444853 \n", + "10907 TL39050 Arizona 23893.304100 \n", + "10908 WA60547 California 11971.977650 \n", + "10909 IV32877 California 6857.519928 \n", + "\n", + " response coverage education \\\n", + "0 No Basic College \n", + "1 No Basic College \n", + "2 No Basic Bachelor \n", + "3 Yes Extended College \n", + "4 No Premium Bachelor \n", + "... ... ... ... \n", + "10905 No Premium Bachelor \n", + "10906 No Basic College \n", + "10907 No Extended Bachelor \n", + "10908 No Premium College \n", + "10909