From 57de61c6ed154111f68ff7dc67e7e8f27a12653a Mon Sep 17 00:00:00 2001 From: Julia Date: Mon, 15 Sep 2025 08:50:56 +0100 Subject: [PATCH] Solved Lab --- lab-dw-data-structuring-and-combining.ipynb | 3441 ++++++++++++++++++- 1 file changed, 3433 insertions(+), 8 deletions(-) diff --git a/lab-dw-data-structuring-and-combining.ipynb b/lab-dw-data-structuring-and-combining.ipynb index ec4e3f9..f7bc834 100644 --- a/lab-dw-data-structuring-and-combining.ipynb +++ b/lab-dw-data-structuring-and-combining.ipynb @@ -36,14 +36,2316 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 102, "id": "492d06e3-92c7-4105-ac72-536db98d3244", "metadata": { "id": "492d06e3-92c7-4105-ac72-536db98d3244" }, + "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", + "
CustomerSTGENDEREducationCustomer Lifetime ValueIncomeMonthly Premium AutoNumber of Open ComplaintsPolicy TypeVehicle ClassTotal Claim Amount
0RB50392WashingtonNaNMasterNaN0.01000.01/0/00Personal AutoFour-Door Car2.704934
1QZ44356ArizonaFBachelor697953.59%0.094.01/0/00Personal AutoFour-Door Car1131.464935
2AI49188NevadaFBachelor1288743.17%48767.0108.01/0/00Personal AutoTwo-Door Car566.472247
3WW63253CaliforniaMBachelor764586.18%0.0106.01/0/00Corporate AutoSUV529.881344
4GA49547WashingtonMHigh School or Below536307.65%36357.068.01/0/00Personal AutoFour-Door Car17.269323
....................................
4003NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
4004NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
4005NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
4006NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
4007NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
\n", + "

4008 rows × 11 columns

\n", + "
" + ], + "text/plain": [ + " Customer ST GENDER Education \\\n", + "0 RB50392 Washington NaN Master \n", + "1 QZ44356 Arizona F Bachelor \n", + "2 AI49188 Nevada F Bachelor \n", + "3 WW63253 California M Bachelor \n", + "4 GA49547 Washington M High School or Below \n", + "... ... ... ... ... \n", + "4003 NaN NaN NaN NaN \n", + "4004 NaN NaN NaN NaN \n", + "4005 NaN NaN NaN NaN \n", + "4006 NaN NaN NaN NaN \n", + "4007 NaN NaN NaN NaN \n", + "\n", + " Customer Lifetime Value Income Monthly Premium Auto \\\n", + "0 NaN 0.0 1000.0 \n", + "1 697953.59% 0.0 94.0 \n", + "2 1288743.17% 48767.0 108.0 \n", + "3 764586.18% 0.0 106.0 \n", + "4 536307.65% 36357.0 68.0 \n", + "... ... ... ... \n", + "4003 NaN NaN NaN \n", + "4004 NaN NaN NaN \n", + "4005 NaN NaN NaN \n", + "4006 NaN NaN NaN \n", + "4007 NaN NaN NaN \n", + "\n", + " Number of Open Complaints Policy Type Vehicle Class \\\n", + "0 1/0/00 Personal Auto Four-Door Car \n", + "1 1/0/00 Personal Auto Four-Door Car \n", + "2 1/0/00 Personal Auto Two-Door Car \n", + "3 1/0/00 Corporate Auto SUV \n", + "4 1/0/00 Personal Auto Four-Door Car \n", + "... ... ... ... \n", + "4003 NaN NaN NaN \n", + "4004 NaN NaN NaN \n", + "4005 NaN NaN NaN \n", + "4006 NaN NaN NaN \n", + "4007 NaN NaN NaN \n", + "\n", + " Total Claim Amount \n", + "0 2.704934 \n", + "1 1131.464935 \n", + "2 566.472247 \n", + "3 529.881344 \n", + "4 17.269323 \n", + "... ... \n", + "4003 NaN \n", + "4004 NaN \n", + "4005 NaN \n", + "4006 NaN \n", + "4007 NaN \n", + "\n", + "[4008 rows x 11 columns]" + ] + }, + "execution_count": 102, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Your code goes here\n", + "import pandas as pd\n", + "import numpy as np\n", + "url = 'https://raw.githubusercontent.com/data-bootcamp-v4/data/main/file1.csv'\n", + "insurance_company_df = pd.read_csv(url)\n", + "insurance_company_df" + ] + }, + { + "cell_type": "code", + "execution_count": 103, + "id": "9828e4c7-7056-4de2-b84a-0e552df63be0", + "metadata": {}, "outputs": [], "source": [ - "# Your code goes here" + "def info_dataframe(dataframe):\n", + "\n", + " print(f\"Head: {dataframe.head()}\")\n", + " print(f\"Duplicates: {dataframe.duplicated().sum()}\")\n", + " print(f\"Info: {dataframe.info()}\")\n", + " print(f\"Shape: {dataframe.shape}\")\n", + " print(f\"Info: {dataframe.info()}\")\n", + " print(f\"Columns: {dataframe.columns}\")\n", + " print(f\"Missing Value: {dataframe.isnull()}\")\n", + " dataframe_nulls = dataframe.isnull()\n", + " print(dataframe_nulls[\"customer\"].value_counts())\n", + " print(dataframe_nulls[\"state\"].value_counts())\n", + " print(dataframe_nulls[\"gender\"].value_counts())\n", + " print(dataframe_nulls[\"education\"].value_counts())\n", + " print(dataframe_nulls[\"customer_lifetime_value\"].value_counts())\n", + " print(dataframe_nulls[\"income\"].value_counts())\n", + " print(dataframe_nulls[\"monthly_premium_auto\"].value_counts())\n", + " print(dataframe_nulls[\"number_of_open_complaints\"].value_counts())\n", + " print(dataframe_nulls[\"policy_type\"].value_counts())\n", + " print(dataframe_nulls[\"vehicle_class\"].value_counts())\n", + " print(dataframe_nulls[\"total_claim_amount\"].value_counts())\n", + " \n", + " return dataframe\n", + "\n", + "def cleaned_dataframe(dataframe):\n", + "\n", + " dataframe.columns = dataframe.columns.str.lower()\n", + " dataframe.columns = dataframe.columns.str.replace(\"\\s\", \"_\", regex=True)\n", + " dataframe.columns = dataframe.columns.str.replace(r\"\\bst\\b\", \"state\", regex=True)\n", + " dataframe[\"gender\"] = dataframe[\"gender\"].str.replace(\"Femal\", \"F\").str.strip()\n", + " dataframe[\"gender\"] = dataframe[\"gender\"].str.replace(\"female\", \"F\").str.strip()\n", + " dataframe[\"gender\"] = dataframe[\"gender\"].str.replace(\"Male\", \"M\").str.strip()\n", + " print(dataframe[\"gender\"].unique())\n", + " dataframe[\"state\"] = dataframe[\"state\"].str.replace(r\"\\bCali\\b\", \"California\", regex=True).str.strip()\n", + " dataframe[\"state\"] = dataframe[\"state\"].str.replace(\"AZ\", \"Arizona\").str.strip()\n", + " dataframe[\"state\"] = dataframe[\"state\"].str.replace(\"WA\", \"Washington\").str.strip()\n", + " print(dataframe[\"state\"].unique())\n", + " dataframe[\"education\"] = dataframe[\"education\"].str.replace(\"Bachelors\", \"Bachelor\").str.strip()\n", + " print(dataframe[\"education\"].unique())\n", + " dataframe[\"customer_lifetime_value\"] = dataframe[\"customer_lifetime_value\"].astype(str).str.replace(\"%\", \"\").str.strip()\n", + " print(dataframe[\"customer_lifetime_value\"].unique())\n", + " dataframe[\"vehicle_class\"] = dataframe[\"vehicle_class\"].str.replace(\"Sports Car\", \"Luxury\").str.strip()\n", + " dataframe[\"vehicle_class\"] = dataframe[\"vehicle_class\"].str.replace(\"Luxury SUV\", \"Luxury\").str.strip()\n", + " dataframe[\"vehicle_class\"] = dataframe[\"vehicle_class\"].str.replace(\"Luxury Car\", \"Luxury\").str.strip()\n", + " print(dataframe[\"vehicle_class\"].unique())\n", + " dataframe[\"customer_lifetime_value\"] = dataframe[\"customer_lifetime_value\"].astype(str).replace('[^\\d.]', '', regex=True).replace(\"\", np.nan).astype(float)\n", + " dataframe[\"number_of_open_complaints\"] = dataframe[\"number_of_open_complaints\"].astype(str).str.split(\"/\").str[1]\n", + " print(dataframe[\"number_of_open_complaints\"].unique())\n", + " dataframe[\"number_of_open_complaints\"].astype(float)\n", + " dataframe = dataframe.dropna()\n", + " dataframe = dataframe.reset_index(drop=True)\n", + " \n", + " return dataframe" + ] + }, + { + "cell_type": "code", + "execution_count": 104, + "id": "24045cc9-0c66-45fd-88c2-f671a44731a7", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[nan 'F' 'M']\n", + "['Washington' 'Arizona' 'Nevada' 'California' 'Oregon' nan]\n", + "['Master' 'Bachelor' 'High School or Below' 'College' 'Doctor' nan]\n", + "['nan' '697953.59' '1288743.17' ... '2031499.76' '323912.47' '899704.02']\n", + "['Four-Door Car' 'Two-Door Car' 'SUV' 'Luxury' nan]\n", + "['0' '2' '1' '3' '5' '4' nan]\n", + "Head: customer state gender education customer_lifetime_value \\\n", + "0 RB50392 Washington NaN Master NaN \n", + "1 QZ44356 Arizona F Bachelor 697953.59 \n", + "2 AI49188 Nevada F Bachelor 1288743.17 \n", + "3 WW63253 California M Bachelor 764586.18 \n", + "4 GA49547 Washington M High School or Below 536307.65 \n", + "\n", + " income monthly_premium_auto number_of_open_complaints policy_type \\\n", + "0 0.0 1000.0 0 Personal Auto \n", + "1 0.0 94.0 0 Personal Auto \n", + "2 48767.0 108.0 0 Personal Auto \n", + "3 0.0 106.0 0 Corporate Auto \n", + "4 36357.0 68.0 0 Personal Auto \n", + "\n", + " vehicle_class total_claim_amount \n", + "0 Four-Door Car 2.704934 \n", + "1 Four-Door Car 1131.464935 \n", + "2 Two-Door Car 566.472247 \n", + "3 SUV 529.881344 \n", + "4 Four-Door Car 17.269323 \n", + "Duplicates: 2936\n", + "\n", + "RangeIndex: 4008 entries, 0 to 4007\n", + "Data columns (total 11 columns):\n", + " # Column Non-Null Count Dtype \n", + "--- ------ -------------- ----- \n", + " 0 customer 1071 non-null object \n", + " 1 state 1071 non-null object \n", + " 2 gender 954 non-null object \n", + " 3 education 1071 non-null object \n", + " 4 customer_lifetime_value 1068 non-null float64\n", + " 5 income 1071 non-null float64\n", + " 6 monthly_premium_auto 1071 non-null float64\n", + " 7 number_of_open_complaints 1071 non-null object \n", + " 8 policy_type 1071 non-null object \n", + " 9 vehicle_class 1071 non-null object \n", + " 10 total_claim_amount 1071 non-null float64\n", + "dtypes: float64(4), object(7)\n", + "memory usage: 344.6+ KB\n", + "Info: None\n", + "Shape: (4008, 11)\n", + "\n", + "RangeIndex: 4008 entries, 0 to 4007\n", + "Data columns (total 11 columns):\n", + " # Column Non-Null Count Dtype \n", + "--- ------ -------------- ----- \n", + " 0 customer 1071 non-null object \n", + " 1 state 1071 non-null object \n", + " 2 gender 954 non-null object \n", + " 3 education 1071 non-null object \n", + " 4 customer_lifetime_value 1068 non-null float64\n", + " 5 income 1071 non-null float64\n", + " 6 monthly_premium_auto 1071 non-null float64\n", + " 7 number_of_open_complaints 1071 non-null object \n", + " 8 policy_type 1071 non-null object \n", + " 9 vehicle_class 1071 non-null object \n", + " 10 total_claim_amount 1071 non-null float64\n", + "dtypes: float64(4), object(7)\n", + "memory usage: 344.6+ KB\n", + "Info: None\n", + "Columns: Index(['customer', 'state', 'gender', 'education', 'customer_lifetime_value',\n", + " 'income', 'monthly_premium_auto', 'number_of_open_complaints',\n", + " 'policy_type', 'vehicle_class', 'total_claim_amount'],\n", + " dtype='object')\n", + "Missing Value: customer state gender education customer_lifetime_value income \\\n", + "0 False False True False True False \n", + "1 False False False False False False \n", + "2 False False False False False False \n", + "3 False False False False False False \n", + "4 False False False False False False \n", + "... ... ... ... ... ... ... \n", + "4003 True True True True True True \n", + "4004 True True True True True True \n", + "4005 True True True True True True \n", + "4006 True True True True True True \n", + "4007 True True True True True True \n", + "\n", + " monthly_premium_auto number_of_open_complaints policy_type \\\n", + "0 False False False \n", + "1 False False False \n", + "2 False False False \n", + "3 False False False \n", + "4 False False False \n", + "... ... ... ... \n", + "4003 True True True \n", + "4004 True True True \n", + "4005 True True True \n", + "4006 True True True \n", + "4007 True True True \n", + "\n", + " vehicle_class total_claim_amount \n", + "0 False False \n", + "1 False False \n", + "2 False False \n", + "3 False False \n", + "4 False False \n", + "... ... ... \n", + "4003 True True \n", + "4004 True True \n", + "4005 True True \n", + "4006 True True \n", + "4007 True True \n", + "\n", + "[4008 rows x 11 columns]\n", + "customer\n", + "True 2937\n", + "False 1071\n", + "Name: count, dtype: int64\n", + "state\n", + "True 2937\n", + "False 1071\n", + "Name: count, dtype: int64\n", + "gender\n", + "True 3054\n", + "False 954\n", + "Name: count, dtype: int64\n", + "education\n", + "True 2937\n", + "False 1071\n", + "Name: count, dtype: int64\n", + "customer_lifetime_value\n", + "True 2940\n", + "False 1068\n", + "Name: count, dtype: int64\n", + "income\n", + "True 2937\n", + "False 1071\n", + "Name: count, dtype: int64\n", + "monthly_premium_auto\n", + "True 2937\n", + "False 1071\n", + "Name: count, dtype: int64\n", + "number_of_open_complaints\n", + "True 2937\n", + "False 1071\n", + "Name: count, dtype: int64\n", + "policy_type\n", + "True 2937\n", + "False 1071\n", + "Name: count, dtype: int64\n", + "vehicle_class\n", + "True 2937\n", + "False 1071\n", + "Name: count, dtype: int64\n", + "total_claim_amount\n", + "True 2937\n", + "False 1071\n", + "Name: count, dtype: int64\n" + ] + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
customerstategendereducationcustomer_lifetime_valueincomemonthly_premium_autonumber_of_open_complaintspolicy_typevehicle_classtotal_claim_amount
0QZ44356ArizonaFBachelor697953.590.094.00Personal AutoFour-Door Car1131.464935
1AI49188NevadaFBachelor1288743.1748767.0108.00Personal AutoTwo-Door Car566.472247
2WW63253CaliforniaMBachelor764586.180.0106.00Corporate AutoSUV529.881344
3GA49547WashingtonMHigh School or Below536307.6536357.068.00Personal AutoFour-Door Car17.269323
4OC83172OregonFBachelor825629.7862902.069.00Personal AutoTwo-Door Car159.383042
....................................
947TM65736OregonMMaster305955.0338644.078.01Personal AutoFour-Door Car361.455219
948VJ51327CaliforniaFHigh School or Below2031499.7663209.0102.02Personal AutoSUV207.320041
949GS98873ArizonaFBachelor323912.4716061.088.00Personal AutoFour-Door Car633.600000
950CW49887CaliforniaFMaster462680.1179487.0114.00Special AutoSUV547.200000
951MY31220CaliforniaFCollege899704.0254230.0112.00Personal AutoTwo-Door Car537.600000
\n", + "

952 rows × 11 columns

\n", + "
" + ], + "text/plain": [ + " customer state gender education \\\n", + "0 QZ44356 Arizona F Bachelor \n", + "1 AI49188 Nevada F Bachelor \n", + "2 WW63253 California M Bachelor \n", + "3 GA49547 Washington M High School or Below \n", + "4 OC83172 Oregon F Bachelor \n", + ".. ... ... ... ... \n", + "947 TM65736 Oregon M Master \n", + "948 VJ51327 California F High School or Below \n", + "949 GS98873 Arizona F Bachelor \n", + "950 CW49887 California F Master \n", + "951 MY31220 California F College \n", + "\n", + " customer_lifetime_value income monthly_premium_auto \\\n", + "0 697953.59 0.0 94.0 \n", + "1 1288743.17 48767.0 108.0 \n", + "2 764586.18 0.0 106.0 \n", + "3 536307.65 36357.0 68.0 \n", + "4 825629.78 62902.0 69.0 \n", + ".. ... ... ... \n", + "947 305955.03 38644.0 78.0 \n", + "948 2031499.76 63209.0 102.0 \n", + "949 323912.47 16061.0 88.0 \n", + "950 462680.11 79487.0 114.0 \n", + "951 899704.02 54230.0 112.0 \n", + "\n", + " number_of_open_complaints policy_type vehicle_class \\\n", + "0 0 Personal Auto Four-Door Car \n", + "1 0 Personal Auto Two-Door Car \n", + "2 0 Corporate Auto SUV \n", + "3 0 Personal Auto Four-Door Car \n", + "4 0 Personal Auto Two-Door Car \n", + ".. ... ... ... \n", + "947 1 Personal Auto Four-Door Car \n", + "948 2 Personal Auto SUV \n", + "949 0 Personal Auto Four-Door Car \n", + "950 0 Special Auto SUV \n", + "951 0 Personal Auto Two-Door Car \n", + "\n", + " total_claim_amount \n", + "0 1131.464935 \n", + "1 566.472247 \n", + "2 529.881344 \n", + "3 17.269323 \n", + "4 159.383042 \n", + ".. ... \n", + "947 361.455219 \n", + "948 207.320041 \n", + "949 633.600000 \n", + "950 547.200000 \n", + "951 537.600000 \n", + "\n", + "[952 rows x 11 columns]" + ] + }, + "execution_count": 104, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cleaned_insurance_company_df_1 = cleaned_dataframe(insurance_company_df)\n", + "info_dataframe(insurance_company_df)\n", + "cleaned_insurance_company_df_1" + ] + }, + { + "cell_type": "code", + "execution_count": 105, + "id": "fa0e9d98-b848-4089-9bb2-ac85e1e7cdea", + "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", + "
CustomerSTGENDEREducationCustomer Lifetime ValueIncomeMonthly Premium AutoNumber of Open ComplaintsTotal Claim AmountPolicy TypeVehicle Class
0GS98873ArizonaFBachelor323912.47%16061881/0/00633.600000Personal AutoFour-Door Car
1CW49887CaliforniaFMaster462680.11%794871141/0/00547.200000Special AutoSUV
2MY31220CaliforniaFCollege899704.02%542301121/0/00537.600000Personal AutoTwo-Door Car
3UH35128OregonFCollege2580706.30%712102141/1/001027.200000Personal AutoLuxury Car
4WH52799ArizonaFCollege380812.21%94903941/0/00451.200000Corporate AutoTwo-Door Car
....................................
991HV85198ArizonaMMaster847141.75%63513701/0/00185.667213Personal AutoFour-Door Car
992BS91566ArizonaFCollege543121.91%58161681/0/00140.747286Corporate AutoFour-Door Car
993IL40123NevadaFCollege568964.41%83640701/0/00471.050488Corporate AutoTwo-Door Car
994MY32149CaliforniaFMaster368672.38%0961/0/0028.460568Personal AutoTwo-Door Car
995SA91515CaliforniaMBachelor399258.39%01111/0/00700.349052Personal AutoSUV
\n", + "

996 rows × 11 columns

\n", + "
" + ], + "text/plain": [ + " Customer ST GENDER Education Customer Lifetime Value Income \\\n", + "0 GS98873 Arizona F Bachelor 323912.47% 16061 \n", + "1 CW49887 California F Master 462680.11% 79487 \n", + "2 MY31220 California F College 899704.02% 54230 \n", + "3 UH35128 Oregon F College 2580706.30% 71210 \n", + "4 WH52799 Arizona F College 380812.21% 94903 \n", + ".. ... ... ... ... ... ... \n", + "991 HV85198 Arizona M Master 847141.75% 63513 \n", + "992 BS91566 Arizona F College 543121.91% 58161 \n", + "993 IL40123 Nevada F College 568964.41% 83640 \n", + "994 MY32149 California F Master 368672.38% 0 \n", + "995 SA91515 California M Bachelor 399258.39% 0 \n", + "\n", + " Monthly Premium Auto Number of Open Complaints Total Claim Amount \\\n", + "0 88 1/0/00 633.600000 \n", + "1 114 1/0/00 547.200000 \n", + "2 112 1/0/00 537.600000 \n", + "3 214 1/1/00 1027.200000 \n", + "4 94 1/0/00 451.200000 \n", + ".. ... ... ... \n", + "991 70 1/0/00 185.667213 \n", + "992 68 1/0/00 140.747286 \n", + "993 70 1/0/00 471.050488 \n", + "994 96 1/0/00 28.460568 \n", + "995 111 1/0/00 700.349052 \n", + "\n", + " Policy Type Vehicle Class \n", + "0 Personal Auto Four-Door Car \n", + "1 Special Auto SUV \n", + "2 Personal Auto Two-Door Car \n", + "3 Personal Auto Luxury Car \n", + "4 Corporate Auto Two-Door Car \n", + ".. ... ... \n", + "991 Personal Auto Four-Door Car \n", + "992 Corporate Auto Four-Door Car \n", + "993 Corporate Auto Two-Door Car \n", + "994 Personal Auto Two-Door Car \n", + "995 Personal Auto SUV \n", + "\n", + "[996 rows x 11 columns]" + ] + }, + "execution_count": 105, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Second table\n", + "url_2 = 'https://raw.githubusercontent.com/data-bootcamp-v4/data/main/file2.csv'\n", + "insurance_company_df_2 = pd.read_csv(url_2)\n", + "insurance_company_df_2" + ] + }, + { + "cell_type": "code", + "execution_count": 106, + "id": "8da3f79a-3431-4712-8999-73ca2d51b742", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['F' 'M' nan]\n", + "['Arizona' 'California' 'Oregon' 'Nevada' 'Washington']\n", + "['Bachelor' 'Master' 'College' 'Doctor' 'High School or Below']\n", + "['323912.47' '462680.11' '899704.02' '2580706.30' '380812.21' '761413.80'\n", + " '689845.53' '229837.92' '280669.61' '520611.82' '4570865.34' '800734.91'\n", + " '548254.94' '246323.68' '549894.07' '524382.80' '328045.73' '488654.43'\n", + " '512348.50' '547955.51' '476215.70' '828767.93' '988665.64' '271291.56'\n", + " '1047767.63' '343613.43' '259618.52' '1273195.16' '349414.79' '759791.07'\n", + " '401521.45' '2047710.84' '816068.98' '1229868.63' '871492.21' '485353.42'\n", + " '488094.64' '231138.21' '432709.89' '832353.33' '1017971.70' '776126.78'\n", + " '523989.09' '451790.88' '238977.41' '413062.88' '269156.90' '522776.64'\n", + " '618734.57' '511387.47' '1103931.62' '3222708.39' '261196.59'\n", + " '1337232.77' '483898.19' '472165.90' '387364.70' '471855.85' '1697979.76'\n", + " '1368171.18' '571722.19' '948659.64' '383914.37' '1121159.03' '379832.17'\n", + " '281656.74' '502929.70' '344496.75' '285940.86' '269205.76' '1143173.09'\n", + " '763588.33' '980582.96' '680361.56' '710765.54' '473518.45' '687432.67'\n", + " '241125.66' '241654.24' '2398154.34' '469216.52' '360093.43' '266522.25'\n", + " '766652.04' '1667589.62' '455085.60' '1176393.57' '1374253.72'\n", + " '1613841.63' '729858.36' '667373.77' '778212.68' '1939321.15' '397413.82'\n", + " '410558.10' '230847.21' '537291.45' '550831.55' '239833.32' '372883.01'\n", + " '275849.86' '370393.03' '937284.36' '499158.45' '503986.93' '275997.83'\n", + " '799300.40' '523557.35' '263301.18' '276480.23' '808484.64' '268517.77'\n", + " '1220812.00' '2009043.87' '513341.48' '249131.70' '631459.68'\n", + " '1622964.89' '516178.99' '398226.61' '1347318.57' '277832.39' '827644.42'\n", + " '1434985.99' '587819.93' '266605.45' '534568.10' '477712.16' '1697374.02'\n", + " '251811.21' '1916098.99' '3286440.46' '396481.30' '491177.31' '780531.29'\n", + " '720066.49' '538949.95' '324131.42' '552821.28' '299302.46' '707665.32'\n", + " '370038.50' '532883.59' '483887.71' '341720.50' '787992.90' '786943.24'\n", + " '258680.72' '728678.91' '1179799.21' '938675.30' '630892.24' '860915.82'\n", + " '1542801.04' '563079.30' '1813118.87' '808721.95' '1845357.63'\n", + " '521751.33' '483578.32' '559712.50' '892046.40' '599541.10' '3849694.70'\n", + " '838263.01' '244366.52' '247225.39' '540551.84' '935247.90' '433987.11'\n", + " '1772376.40' '750745.54' '604857.42' '1901447.63' '1008037.03'\n", + " '650339.70' '248772.97' '462039.01' '247152.84' '649424.40' '250490.76'\n", + " '490489.47' '480247.70' '795577.48' '694190.08' '838247.84' '353643.18'\n", + " '324481.66' '761121.28' '450539.83' '244584.48' '1647776.84' '354640.02'\n", + " '427727.01' '478477.35' '757223.77' '1176087.64' '393381.40' '570076.18'\n", + " '349863.48' '576809.13' '636195.40' '493519.00' '578522.35' '561968.91'\n", + " '259928.96' '673297.09' '1832186.65' '230069.15' '400285.76' '862099.74'\n", + " '1038898.60' '842717.25' '700727.42' '517657.91' '470000.75' '443494.14'\n", + " '1401052.74' '1235005.82' '816157.69' '1100913.05' '871704.98'\n", + " '591746.66' '250366.04' '501888.52' '433038.60' '1048774.33' '356750.38'\n", + " '1989642.23' '2142363.72' '694832.59' '351583.19' '1203662.05'\n", + " '360979.83' '1773246.49' '850985.09' '586642.43' '482550.09' '777800.56'\n", + " '2634608.58' '1486645.12' '832423.27' '923830.60' '2269329.08'\n", + " '623601.86' '501218.48' '1569553.94' '821460.24' '311898.11' '276403.21'\n", + " '688368.66' '221591.29' '485474.57' '2152294.75' '276169.17' '2256361.84'\n", + " '528591.83' '3506264.80' '591319.90' '259339.87' '1269267.09' '330911.97'\n", + " '518162.09' '241393.06' '216168.55' '552798.89' '1062921.79' '1182010.98'\n", + " '496463.15' '912292.56' '346066.50' '287298.08' '992787.77' '348268.70'\n", + " '399172.72' '551010.74' '541945.81' '581063.05' '394272.58' '312627.19'\n", + " '353000.77' '1099059.48' '477294.38' '220233.52' '245917.17' '1037388.88'\n", + " '258420.39' '430742.28' '304025.38' '817657.68' '528530.76' '802499.30'\n", + " '281046.44' '773955.04' '410979.36' '327516.20' '265269.53' '504822.62'\n", + " '336241.44' '485842.94' '214492.15' '604261.85' '338720.33' '1086427.49'\n", + " '884265.00' '261661.39' '3076325.64' '520022.78' '859130.54' '264657.38'\n", + " '460724.43' '486062.00' '258084.99' '529139.53' '840575.30' '309651.12'\n", + " '2941228.93' 'nan' '1749752.20' '321860.86' '2320726.97' '692197.40'\n", + " '1391853.48' '896630.98' '1198198.48' '553262.98' '1166057.30'\n", + " '288645.16' '1274184.75' '539809.81' '728503.10' '1765196.34'\n", + " '1702989.34' '249125.76' '403931.50' '261933.74' '504968.96' '498345.71'\n", + " '253063.94' '739671.97' '383289.85' '496140.59' '386148.63' '2265853.65'\n", + " '1040896.87' '483471.05' '825766.65' '305262.95' '401231.93' '1335548.64'\n", + " '236443.16' '248933.79' '475572.00' '1386438.50' '302042.48' '628530.52'\n", + " '250602.20' '282630.76' '436971.79' '1217458.80' '352804.43' '1043657.47'\n", + " '274612.14' '917517.19' '272752.08' '944974.59' '456881.94' '257402.04'\n", + " '878988.41' '250740.78' '252241.46' '754271.40' '600521.48' '2099825.95'\n", + " '234508.45' '878316.54' '452996.54' '603322.24' '530824.70' '267473.07'\n", + " '492980.75' '1413112.13' '438627.76' '1911656.81' '663166.55' '743229.99'\n", + " '292811.51' '4661187.38' '1651500.93' '1021356.34' '1004928.59'\n", + " '574614.83' '374675.16' '748606.84' '912006.52' '567804.67' '751708.38'\n", + " '453053.07' '269138.06' '806862.39' '247857.67' '911204.15' '277244.13'\n", + " '430579.32' '510335.76' '478496.05' '1054110.98' '528511.87' '761084.05'\n", + " '851052.59' '1617294.05' '242549.48' '289931.72' '363305.40' '345715.42'\n", + " '339472.03' '802106.71' '584152.81' '547985.42' '2045524.95' '831912.30'\n", + " '258286.23' '416379.34' '485310.03' '753169.73' '258593.70' '269596.39'\n", + " '268458.16' '810936.46' '903665.76' '535218.70' '1188096.62' '255709.43'\n", + " '791482.31' '984008.26' '435155.05' '2220782.62' '482525.86' '694783.88'\n", + " '334480.95' '235750.31' '3594471.05' '404816.13' '685200.19' '290302.42'\n", + " '1803911.42' '324204.39' '246762.08' '567438.34' '863435.60' '278019.69'\n", + " '2205600.50' '251459.20' '588622.11' '770603.63' '279045.82' '239703.61'\n", + " '883432.28' '1443567.37' '687196.66' '1536235.44' '483479.75'\n", + " '1089930.18' '528404.10' '289172.68' '490054.51' '2084259.63' '524605.72'\n", + " '663083.61' '389503.48' '1170106.99' '341910.87' '730277.51' '1968540.91'\n", + " '248606.49' '522432.88' '4922143.07' '316788.87' '1319792.89' '623430.59'\n", + " '753960.06' '815793.36' '1315674.90' '533938.84' '864917.50' '751913.36'\n", + " '429300.96' '253774.45' '1316033.89' '1323554.44' '374457.77'\n", + " '2848607.28' '264468.46' '507328.21' '427258.51' '1100301.65'\n", + " '1418164.28' '554803.19' '1107768.59' '243568.90' '874385.22' '240976.09'\n", + " '550001.25' '852828.87' '359199.61' '853982.69' '699091.78' '397938.82'\n", + " '2395037.44' '232105.25' '508702.05' '436293.12' '745746.81' '702775.96'\n", + " '283168.37' '421785.79' '759629.15' '836567.76' '272639.30' '342045.22'\n", + " '483910.72' '435855.35' '1242739.37' '2351585.33' '839632.76' '517097.64'\n", + " '558530.81' '863949.50' '528183.35' '838525.23' '463310.13' '248039.27'\n", + " '361868.69' '537584.28' '489329.15' '1073768.43' '260781.55' '1572525.05'\n", + " '955341.55' '732492.82' '533303.81' '1276723.06' '265933.80' '348363.04'\n", + " '463654.65' '1753003.66' '697871.98' '291224.84' '420927.93' '500980.89'\n", + " '1149033.62' '286454.40' '840391.02' '2039596.88' '529263.25'\n", + " '1672777.19' '580112.83' '947297.38' '1048491.54' '438731.09' '452288.35'\n", + " '541815.21' '1578529.69' '2211039.80' '1359619.97' '475612.62'\n", + " '244705.31' '567592.33' '739903.21' '730843.39' '3287174.78' '522892.01'\n", + " '2070086.45' '633303.08' '629273.54' '491788.96' '516581.00' '629159.00'\n", + " '458267.42' '606244.16' '497907.99' '583056.14' '374257.91' '384959.67'\n", + " '1526581.49' '531780.72' '237480.92' '553286.33' '571978.57' '451220.44'\n", + " '726480.39' '865886.38' '559938.29' '1522819.87' '364483.36' '369344.08'\n", + " '938816.29' '3116269.33' '928373.78' '255122.67' '581191.81' '406467.06'\n", + " '284144.31' '683213.39' '520197.14' '548458.82' '767268.14' '827248.54'\n", + " '333067.28' '556245.64' '245273.86' '792028.29' '576478.42' '259389.79'\n", + " '288235.06' '221318.79' '942962.94' '623925.75' '766880.96' '1377097.62'\n", + " '274284.43' '1346692.07' '885835.20' '848533.00' '774464.44' '589490.74'\n", + " '577068.41' '526111.75' '240353.95' '912460.00' '2618080.53' '1564125.86'\n", + " '531983.87' '749600.66' '1217458.96' '260557.08' '270720.85' '279490.75'\n", + " '881901.89' '534599.46' '816951.40' '770888.39' '1212844.67' '679684.48'\n", + " '286731.22' '239557.00' '709416.77' '412809.13' '404693.61' '486928.28'\n", + " '290215.19' '428294.80' '775012.03' '662717.46' '747460.58' '556129.14'\n", + " '609846.21' '285952.89' '599442.46' '563524.95' '506720.83' '226328.46'\n", + " '492839.71' '856476.82' '236188.39' '556569.33' '514680.98' '293808.03'\n", + " '1443274.64' '1302741.98' '245198.88' '466198.41' '560001.02' '401613.28'\n", + " '2219580.30' '734335.37' '480451.43' '273553.89' '694097.28' '239621.93'\n", + " '538089.86' '843281.57' '755650.75' '778743.17' '478781.29' '970764.76'\n", + " '255222.62' '522342.93' '501044.93' '560831.63' '445793.63' '820078.73'\n", + " '274608.01' '1021577.92' '245357.08' '587295.88' '311892.79' '556865.65'\n", + " '902971.47' '759182.72' '225531.29' '3261369.04' '944564.95' '680359.68'\n", + " '976621.71' '729484.61' '568251.53' '633294.18' '491657.70' '479824.09'\n", + " '564380.24' '924746.44' '732292.89' '827590.01' '563540.37' '1497028.51'\n", + " '933633.69' '4835696.08' '568691.53' '862283.54' '507967.48' '562331.45'\n", + " '527001.36' '862117.22' '791833.49' '2103401.82' '1541768.22' '869263.68'\n", + " '650314.39' '239619.24' '591495.18' '224844.96' '682679.77' '398218.07'\n", + " '288777.97' '225241.68' '845853.13' '747831.37' '378864.98' '522068.53'\n", + " '713029.48' '851359.27' '566013.38' '263814.01' '531889.66' '416016.26'\n", + " '223734.78' '346012.30' '1600550.51' '698660.37' '882696.15' '472686.93'\n", + " '2744347.48' '724731.35' '513785.21' '273905.72' '509279.39' '579982.68'\n", + " '550706.32' '850128.00' '293598.83' '4680522.31' '257532.37' '3711165.95'\n", + " '437119.04' '1679633.60' '798850.64' '226984.11' '499147.20' '292193.09'\n", + " '761319.31' '582740.97' '260064.12' '849146.57' '977873.36' '1000402.76'\n", + " '487277.44' '744481.46' '576111.12' '536677.91' '625947.78' '762358.07'\n", + " '1096395.72' '742784.51' '550413.90' '466512.96' '602184.25' '307410.55'\n", + " '495308.64' '778048.93' '799277.91' '417068.73' '2322823.67' '544581.70'\n", + " '455849.84' '1039066.65' '714254.91' '546954.30' '1162873.40'\n", + " '1018965.43' '273343.19' '401445.31' '711953.19' '1177279.07' '238179.08'\n", + " '520835.39' '501872.79' '1190054.48' '580017.19' '567438.12' '727143.40'\n", + " '316449.40' '266103.34' '1414055.89' '765422.71' '219973.95' '200435.07'\n", + " '1311111.32' '1576260.35' '278753.98' '271336.80' '1459024.58'\n", + " '665247.45' '244462.11' '289691.88' '1097206.78' '1935737.20' '722712.04'\n", + " '785730.39' '428106.22' '1151316.29' '514711.02' '866349.76' '253532.17'\n", + " '2150433.88' '734932.85' '429718.91' '1747664.14' '1047989.97'\n", + " '224257.44' '275445.68' '804120.06' '604291.19' '282743.89' '2204185.64'\n", + " '279680.22' '407284.94' '518246.23' '613166.32' '239213.11' '320966.30'\n", + " '280860.60' '688046.89' '359106.67' '520125.22' '552154.26' '507165.15'\n", + " '292168.14' '1580653.40' '574988.38' '416741.96' '651495.40' '918951.83'\n", + " '823122.34' '309517.54' '758211.38' '1634460.81' '1176315.25' '405337.38'\n", + " '331115.79' '559538.99' '508969.43' '2233716.31' '479283.05' '2778969.24'\n", + " '751166.06' '1876755.16' '498764.31' '512319.68' '598977.39' '242928.05'\n", + " '582818.22' '283158.77' '976793.69' '1209791.22' '226531.86' '571908.87'\n", + " '1017147.78' '1051715.64' '430347.14' '1192675.33' '1653170.38'\n", + " '305928.21' '543744.37' '510329.66' '458310.09' '640962.75' '899198.45'\n", + " '1223277.63' '512603.89' '1101416.36' '381961.95' '840439.51' '903567.11'\n", + " '545370.76' '376636.66' '728393.44' '274524.98' '262627.94' '245681.66'\n", + " '845367.77' '350856.95' '287735.43' '784016.58' '277104.50' '533948.83'\n", + " '809287.70' '864650.41' '565923.84' '553246.23' '794351.33' '977460.58'\n", + " '406700.47' '2320839.42' '732589.27' '417034.07' '887596.55' '1937890.78'\n", + " '597099.57' '914887.79' '2009689.34' '582168.43' '309580.34' '1059854.25'\n", + " '769512.30' '304179.16' '868982.25' '813177.92' '381532.16' '1163889.95'\n", + " '2280053.54' '446299.70' '1315183.20' '1401997.55' '293115.52'\n", + " '477475.17' '847141.75' '543121.91' '568964.41' '368672.38' '399258.39']\n", + "['Four-Door Car' 'SUV' 'Two-Door Car' 'Luxury']\n", + "['0' '1' '3' '5' '2' '4']\n", + "Head: customer state gender education customer_lifetime_value income \\\n", + "0 GS98873 Arizona F Bachelor 323912.47 16061 \n", + "1 CW49887 California F Master 462680.11 79487 \n", + "2 MY31220 California F College 899704.02 54230 \n", + "3 UH35128 Oregon F College 2580706.30 71210 \n", + "4 WH52799 Arizona F College 380812.21 94903 \n", + "\n", + " monthly_premium_auto number_of_open_complaints total_claim_amount \\\n", + "0 88 0 633.6 \n", + "1 114 0 547.2 \n", + "2 112 0 537.6 \n", + "3 214 1 1027.2 \n", + "4 94 0 451.2 \n", + "\n", + " policy_type vehicle_class \n", + "0 Personal Auto Four-Door Car \n", + "1 Special Auto SUV \n", + "2 Personal Auto Two-Door Car \n", + "3 Personal Auto Luxury \n", + "4 Corporate Auto Two-Door Car \n", + "Duplicates: 0\n", + "\n", + "RangeIndex: 996 entries, 0 to 995\n", + "Data columns (total 11 columns):\n", + " # Column Non-Null Count Dtype \n", + "--- ------ -------------- ----- \n", + " 0 customer 996 non-null object \n", + " 1 state 996 non-null object \n", + " 2 gender 991 non-null object \n", + " 3 education 996 non-null object \n", + " 4 customer_lifetime_value 992 non-null float64\n", + " 5 income 996 non-null int64 \n", + " 6 monthly_premium_auto 996 non-null int64 \n", + " 7 number_of_open_complaints 996 non-null object \n", + " 8 total_claim_amount 996 non-null float64\n", + " 9 policy_type 996 non-null object \n", + " 10 vehicle_class 996 non-null object \n", + "dtypes: float64(2), int64(2), object(7)\n", + "memory usage: 85.7+ KB\n", + "Info: None\n", + "Shape: (996, 11)\n", + "\n", + "RangeIndex: 996 entries, 0 to 995\n", + "Data columns (total 11 columns):\n", + " # Column Non-Null Count Dtype \n", + "--- ------ -------------- ----- \n", + " 0 customer 996 non-null object \n", + " 1 state 996 non-null object \n", + " 2 gender 991 non-null object \n", + " 3 education 996 non-null object \n", + " 4 customer_lifetime_value 992 non-null float64\n", + " 5 income 996 non-null int64 \n", + " 6 monthly_premium_auto 996 non-null int64 \n", + " 7 number_of_open_complaints 996 non-null object \n", + " 8 total_claim_amount 996 non-null float64\n", + " 9 policy_type 996 non-null object \n", + " 10 vehicle_class 996 non-null object \n", + "dtypes: float64(2), int64(2), object(7)\n", + "memory usage: 85.7+ KB\n", + "Info: None\n", + "Columns: Index(['customer', 'state', 'gender', 'education', 'customer_lifetime_value',\n", + " 'income', 'monthly_premium_auto', 'number_of_open_complaints',\n", + " 'total_claim_amount', 'policy_type', 'vehicle_class'],\n", + " dtype='object')\n", + "Missing Value: customer state gender education customer_lifetime_value income \\\n", + "0 False False False False False False \n", + "1 False False False False False False \n", + "2 False False False False False False \n", + "3 False False False False False False \n", + "4 False False False False False False \n", + ".. ... ... ... ... ... ... \n", + "991 False False False False False False \n", + "992 False False False False False False \n", + "993 False False False False False False \n", + "994 False False False False False False \n", + "995 False False False False False False \n", + "\n", + " monthly_premium_auto number_of_open_complaints total_claim_amount \\\n", + "0 False False False \n", + "1 False False False \n", + "2 False False False \n", + "3 False False False \n", + "4 False False False \n", + ".. ... ... ... \n", + "991 False False False \n", + "992 False False False \n", + "993 False False False \n", + "994 False False False \n", + "995 False False False \n", + "\n", + " policy_type vehicle_class \n", + "0 False False \n", + "1 False False \n", + "2 False False \n", + "3 False False \n", + "4 False False \n", + ".. ... ... \n", + "991 False False \n", + "992 False False \n", + "993 False False \n", + "994 False False \n", + "995 False False \n", + "\n", + "[996 rows x 11 columns]\n", + "customer\n", + "False 996\n", + "Name: count, dtype: int64\n", + "state\n", + "False 996\n", + "Name: count, dtype: int64\n", + "gender\n", + "False 991\n", + "True 5\n", + "Name: count, dtype: int64\n", + "education\n", + "False 996\n", + "Name: count, dtype: int64\n", + "customer_lifetime_value\n", + "False 992\n", + "True 4\n", + "Name: count, dtype: int64\n", + "income\n", + "False 996\n", + "Name: count, dtype: int64\n", + "monthly_premium_auto\n", + "False 996\n", + "Name: count, dtype: int64\n", + "number_of_open_complaints\n", + "False 996\n", + "Name: count, dtype: int64\n", + "policy_type\n", + "False 996\n", + "Name: count, dtype: int64\n", + "vehicle_class\n", + "False 996\n", + "Name: count, dtype: int64\n", + "total_claim_amount\n", + "False 996\n", + "Name: count, dtype: int64\n" + ] + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
customerstategendereducationcustomer_lifetime_valueincomemonthly_premium_autonumber_of_open_complaintstotal_claim_amountpolicy_typevehicle_class
0GS98873ArizonaFBachelor323912.4716061880633.600000Personal AutoFour-Door Car
1CW49887CaliforniaFMaster462680.11794871140547.200000Special AutoSUV
2MY31220CaliforniaFCollege899704.02542301120537.600000Personal AutoTwo-Door Car
3UH35128OregonFCollege2580706.307121021411027.200000Personal AutoLuxury
4WH52799ArizonaFCollege380812.2194903940451.200000Corporate AutoTwo-Door Car
....................................
983HV85198ArizonaMMaster847141.7563513700185.667213Personal AutoFour-Door Car
984BS91566ArizonaFCollege543121.9158161680140.747286Corporate AutoFour-Door Car
985IL40123NevadaFCollege568964.4183640700471.050488Corporate AutoTwo-Door Car
986MY32149CaliforniaFMaster368672.38096028.460568Personal AutoTwo-Door Car
987SA91515CaliforniaMBachelor399258.3901110700.349052Personal AutoSUV
\n", + "

988 rows × 11 columns

\n", + "
" + ], + "text/plain": [ + " customer state gender education customer_lifetime_value income \\\n", + "0 GS98873 Arizona F Bachelor 323912.47 16061 \n", + "1 CW49887 California F Master 462680.11 79487 \n", + "2 MY31220 California F College 899704.02 54230 \n", + "3 UH35128 Oregon F College 2580706.30 71210 \n", + "4 WH52799 Arizona F College 380812.21 94903 \n", + ".. ... ... ... ... ... ... \n", + "983 HV85198 Arizona M Master 847141.75 63513 \n", + "984 BS91566 Arizona F College 543121.91 58161 \n", + "985 IL40123 Nevada F College 568964.41 83640 \n", + "986 MY32149 California F Master 368672.38 0 \n", + "987 SA91515 California M Bachelor 399258.39 0 \n", + "\n", + " monthly_premium_auto number_of_open_complaints total_claim_amount \\\n", + "0 88 0 633.600000 \n", + "1 114 0 547.200000 \n", + "2 112 0 537.600000 \n", + "3 214 1 1027.200000 \n", + "4 94 0 451.200000 \n", + ".. ... ... ... \n", + "983 70 0 185.667213 \n", + "984 68 0 140.747286 \n", + "985 70 0 471.050488 \n", + "986 96 0 28.460568 \n", + "987 111 0 700.349052 \n", + "\n", + " policy_type vehicle_class \n", + "0 Personal Auto Four-Door Car \n", + "1 Special Auto SUV \n", + "2 Personal Auto Two-Door Car \n", + "3 Personal Auto Luxury \n", + "4 Corporate Auto Two-Door Car \n", + ".. ... ... \n", + "983 Personal Auto Four-Door Car \n", + "984 Corporate Auto Four-Door Car \n", + "985 Corporate Auto Two-Door Car \n", + "986 Personal Auto Two-Door Car \n", + "987 Personal Auto SUV \n", + "\n", + "[988 rows x 11 columns]" + ] + }, + "execution_count": 106, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cleaned_insurance_company_df_2 = cleaned_dataframe(insurance_company_df_2)\n", + "info_dataframe(insurance_company_df_2)\n", + "cleaned_insurance_company_df_2" + ] + }, + { + "cell_type": "code", + "execution_count": 107, + "id": "f9716415-02d7-45ed-8296-b5f33e7ef589", + "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", + "
CustomerStateCustomer Lifetime ValueEducationGenderIncomeMonthly Premium AutoNumber of Open ComplaintsPolicy TypeTotal Claim AmountVehicle Class
0SA25987Washington3479.137523High School or BelowM01040Personal Auto499.200000Two-Door Car
1TB86706Arizona2502.637401MasterM0660Personal Auto3.468912Two-Door Car
2ZL73902Nevada3265.156348BachelorF25820820Personal Auto393.600000Four-Door Car
3KX23516California4455.843406High School or BelowF01210Personal Auto699.615192SUV
4FN77294California7704.958480High School or BelowM303661012Personal Auto484.800000SUV
....................................
7065LA72316California23405.987980BachelorM71941730Personal Auto198.234764Four-Door Car
7066PK87824California3096.511217CollegeF21604790Corporate Auto379.200000Four-Door Car
7067TD14365California8163.890428BachelorM0853Corporate Auto790.784983Four-Door Car
7068UP19263California7524.442436CollegeM21941960Personal Auto691.200000Four-Door Car
7069Y167826California2611.836866CollegeM0770Corporate Auto369.600000Two-Door Car
\n", + "

7070 rows × 11 columns

\n", + "
" + ], + "text/plain": [ + " Customer State Customer Lifetime Value Education \\\n", + "0 SA25987 Washington 3479.137523 High School or Below \n", + "1 TB86706 Arizona 2502.637401 Master \n", + "2 ZL73902 Nevada 3265.156348 Bachelor \n", + "3 KX23516 California 4455.843406 High School or Below \n", + "4 FN77294 California 7704.958480 High School or Below \n", + "... ... ... ... ... \n", + "7065 LA72316 California 23405.987980 Bachelor \n", + "7066 PK87824 California 3096.511217 College \n", + "7067 TD14365 California 8163.890428 Bachelor \n", + "7068 UP19263 California 7524.442436 College \n", + "7069 Y167826 California 2611.836866 College \n", + "\n", + " Gender Income Monthly Premium Auto Number of Open Complaints \\\n", + "0 M 0 104 0 \n", + "1 M 0 66 0 \n", + "2 F 25820 82 0 \n", + "3 F 0 121 0 \n", + "4 M 30366 101 2 \n", + "... ... ... ... ... \n", + "7065 M 71941 73 0 \n", + "7066 F 21604 79 0 \n", + "7067 M 0 85 3 \n", + "7068 M 21941 96 0 \n", + "7069 M 0 77 0 \n", + "\n", + " Policy Type Total Claim Amount Vehicle Class \n", + "0 Personal Auto 499.200000 Two-Door Car \n", + "1 Personal Auto 3.468912 Two-Door Car \n", + "2 Personal Auto 393.600000 Four-Door Car \n", + "3 Personal Auto 699.615192 SUV \n", + "4 Personal Auto 484.800000 SUV \n", + "... ... ... ... \n", + "7065 Personal Auto 198.234764 Four-Door Car \n", + "7066 Corporate Auto 379.200000 Four-Door Car \n", + "7067 Corporate Auto 790.784983 Four-Door Car \n", + "7068 Personal Auto 691.200000 Four-Door Car \n", + "7069 Corporate Auto 369.600000 Two-Door Car \n", + "\n", + "[7070 rows x 11 columns]" + ] + }, + "execution_count": 107, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "url_3 = 'https://raw.githubusercontent.com/data-bootcamp-v4/data/main/file3.csv'\n", + "insurance_company_df_3 = pd.read_csv(url_3)\n", + "insurance_company_df_3" + ] + }, + { + "cell_type": "code", + "execution_count": 108, + "id": "96b75561-7886-4013-b4d0-88356b9c72a1", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['M' 'F']\n", + "['Washington' 'Arizona' 'Nevada' 'California' 'Oregon']\n", + "['High School or Below' 'Master' 'Bachelor' 'College' 'Doctor']\n", + "['3479.137523' '2502.637401' '3265.156348' ... '8163.890428' '7524.442436'\n", + " '2611.836866']\n", + "['Two-Door Car' 'Four-Door Car' 'SUV' 'Luxury']\n", + "[nan]\n", + "Head: customer state customer_lifetime_value education gender \\\n", + "0 SA25987 Washington 3479.137523 High School or Below M \n", + "1 TB86706 Arizona 2502.637401 Master M \n", + "2 ZL73902 Nevada 3265.156348 Bachelor F \n", + "3 KX23516 California 4455.843406 High School or Below F \n", + "4 FN77294 California 7704.958480 High School or Below M \n", + "\n", + " income monthly_premium_auto number_of_open_complaints policy_type \\\n", + "0 0 104 NaN Personal Auto \n", + "1 0 66 NaN Personal Auto \n", + "2 25820 82 NaN Personal Auto \n", + "3 0 121 NaN Personal Auto \n", + "4 30366 101 NaN Personal Auto \n", + "\n", + " total_claim_amount vehicle_class \n", + "0 499.200000 Two-Door Car \n", + "1 3.468912 Two-Door Car \n", + "2 393.600000 Four-Door Car \n", + "3 699.615192 SUV \n", + "4 484.800000 SUV \n", + "Duplicates: 0\n", + "\n", + "RangeIndex: 7070 entries, 0 to 7069\n", + "Data columns (total 11 columns):\n", + " # Column Non-Null Count Dtype \n", + "--- ------ -------------- ----- \n", + " 0 customer 7070 non-null object \n", + " 1 state 7070 non-null object \n", + " 2 customer_lifetime_value 7070 non-null float64\n", + " 3 education 7070 non-null object \n", + " 4 gender 7070 non-null object \n", + " 5 income 7070 non-null int64 \n", + " 6 monthly_premium_auto 7070 non-null int64 \n", + " 7 number_of_open_complaints 0 non-null float64\n", + " 8 policy_type 7070 non-null object \n", + " 9 total_claim_amount 7070 non-null float64\n", + " 10 vehicle_class 7070 non-null object \n", + "dtypes: float64(3), int64(2), object(6)\n", + "memory usage: 607.7+ KB\n", + "Info: None\n", + "Shape: (7070, 11)\n", + "\n", + "RangeIndex: 7070 entries, 0 to 7069\n", + "Data columns (total 11 columns):\n", + " # Column Non-Null Count Dtype \n", + "--- ------ -------------- ----- \n", + " 0 customer 7070 non-null object \n", + " 1 state 7070 non-null object \n", + " 2 customer_lifetime_value 7070 non-null float64\n", + " 3 education 7070 non-null object \n", + " 4 gender 7070 non-null object \n", + " 5 income 7070 non-null int64 \n", + " 6 monthly_premium_auto 7070 non-null int64 \n", + " 7 number_of_open_complaints 0 non-null float64\n", + " 8 policy_type 7070 non-null object \n", + " 9 total_claim_amount 7070 non-null float64\n", + " 10 vehicle_class 7070 non-null object \n", + "dtypes: float64(3), int64(2), object(6)\n", + "memory usage: 607.7+ KB\n", + "Info: None\n", + "Columns: Index(['customer', 'state', 'customer_lifetime_value', 'education', 'gender',\n", + " 'income', 'monthly_premium_auto', 'number_of_open_complaints',\n", + " 'policy_type', 'total_claim_amount', 'vehicle_class'],\n", + " dtype='object')\n", + "Missing Value: customer state customer_lifetime_value education gender income \\\n", + "0 False False False False False False \n", + "1 False False False False False False \n", + "2 False False False False False False \n", + "3 False False False False False False \n", + "4 False False False False False False \n", + "... ... ... ... ... ... ... \n", + "7065 False False False False False False \n", + "7066 False False False False False False \n", + "7067 False False False False False False \n", + "7068 False False False False False False \n", + "7069 False False False False False False \n", + "\n", + " monthly_premium_auto number_of_open_complaints policy_type \\\n", + "0 False True False \n", + "1 False True False \n", + "2 False True False \n", + "3 False True False \n", + "4 False True False \n", + "... ... ... ... \n", + "7065 False True False \n", + "7066 False True False \n", + "7067 False True False \n", + "7068 False True False \n", + "7069 False True False \n", + "\n", + " total_claim_amount vehicle_class \n", + "0 False False \n", + "1 False False \n", + "2 False False \n", + "3 False False \n", + "4 False False \n", + "... ... ... \n", + "7065 False False \n", + "7066 False False \n", + "7067 False False \n", + "7068 False False \n", + "7069 False False \n", + "\n", + "[7070 rows x 11 columns]\n", + "customer\n", + "False 7070\n", + "Name: count, dtype: int64\n", + "state\n", + "False 7070\n", + "Name: count, dtype: int64\n", + "gender\n", + "False 7070\n", + "Name: count, dtype: int64\n", + "education\n", + "False 7070\n", + "Name: count, dtype: int64\n", + "customer_lifetime_value\n", + "False 7070\n", + "Name: count, dtype: int64\n", + "income\n", + "False 7070\n", + "Name: count, dtype: int64\n", + "monthly_premium_auto\n", + "False 7070\n", + "Name: count, dtype: int64\n", + "number_of_open_complaints\n", + "True 7070\n", + "Name: count, dtype: int64\n", + "policy_type\n", + "False 7070\n", + "Name: count, dtype: int64\n", + "vehicle_class\n", + "False 7070\n", + "Name: count, dtype: int64\n", + "total_claim_amount\n", + "False 7070\n", + "Name: count, dtype: int64\n" + ] + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
customerstatecustomer_lifetime_valueeducationgenderincomemonthly_premium_autonumber_of_open_complaintspolicy_typetotal_claim_amountvehicle_class
\n", + "
" + ], + "text/plain": [ + "Empty DataFrame\n", + "Columns: [customer, state, customer_lifetime_value, education, gender, income, monthly_premium_auto, number_of_open_complaints, policy_type, total_claim_amount, vehicle_class]\n", + "Index: []" + ] + }, + "execution_count": 108, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cleaned_insurance_company_df_3 = cleaned_dataframe(insurance_company_df_3)\n", + "info_dataframe(insurance_company_df_3)\n", + "cleaned_insurance_company_df_3" + ] + }, + { + "cell_type": "code", + "execution_count": 114, + "id": "cac1367a-ec32-46e1-ab79-1c9c21d43026", + "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", + "
customerstategendereducationcustomer_lifetime_valueincomemonthly_premium_autonumber_of_open_complaintspolicy_typevehicle_classtotal_claim_amount
0QZ44356ArizonaFBachelor697953.590.094.00Personal AutoFour-Door Car1131.464935
1AI49188NevadaFBachelor1288743.1748767.0108.00Personal AutoTwo-Door Car566.472247
2WW63253CaliforniaMBachelor764586.180.0106.00Corporate AutoSUV529.881344
3GA49547WashingtonMHigh School or Below536307.6536357.068.00Personal AutoFour-Door Car17.269323
4OC83172OregonFBachelor825629.7862902.069.00Personal AutoTwo-Door Car159.383042
....................................
1935HV85198ArizonaMMaster847141.7563513.070.00Personal AutoFour-Door Car185.667213
1936BS91566ArizonaFCollege543121.9158161.068.00Corporate AutoFour-Door Car140.747286
1937IL40123NevadaFCollege568964.4183640.070.00Corporate AutoTwo-Door Car471.050488
1938MY32149CaliforniaFMaster368672.380.096.00Personal AutoTwo-Door Car28.460568
1939SA91515CaliforniaMBachelor399258.390.0111.00Personal AutoSUV700.349052
\n", + "

1940 rows × 11 columns

\n", + "
" + ], + "text/plain": [ + " customer state gender education \\\n", + "0 QZ44356 Arizona F Bachelor \n", + "1 AI49188 Nevada F Bachelor \n", + "2 WW63253 California M Bachelor \n", + "3 GA49547 Washington M High School or Below \n", + "4 OC83172 Oregon F Bachelor \n", + "... ... ... ... ... \n", + "1935 HV85198 Arizona M Master \n", + "1936 BS91566 Arizona F College \n", + "1937 IL40123 Nevada F College \n", + "1938 MY32149 California F Master \n", + "1939 SA91515 California M Bachelor \n", + "\n", + " customer_lifetime_value income monthly_premium_auto \\\n", + "0 697953.59 0.0 94.0 \n", + "1 1288743.17 48767.0 108.0 \n", + "2 764586.18 0.0 106.0 \n", + "3 536307.65 36357.0 68.0 \n", + "4 825629.78 62902.0 69.0 \n", + "... ... ... ... \n", + "1935 847141.75 63513.0 70.0 \n", + "1936 543121.91 58161.0 68.0 \n", + "1937 568964.41 83640.0 70.0 \n", + "1938 368672.38 0.0 96.0 \n", + "1939 399258.39 0.0 111.0 \n", + "\n", + " number_of_open_complaints policy_type vehicle_class \\\n", + "0 0 Personal Auto Four-Door Car \n", + "1 0 Personal Auto Two-Door Car \n", + "2 0 Corporate Auto SUV \n", + "3 0 Personal Auto Four-Door Car \n", + "4 0 Personal Auto Two-Door Car \n", + "... ... ... ... \n", + "1935 0 Personal Auto Four-Door Car \n", + "1936 0 Corporate Auto Four-Door Car \n", + "1937 0 Corporate Auto Two-Door Car \n", + "1938 0 Personal Auto Two-Door Car \n", + "1939 0 Personal Auto SUV \n", + "\n", + " total_claim_amount \n", + "0 1131.464935 \n", + "1 566.472247 \n", + "2 529.881344 \n", + "3 17.269323 \n", + "4 159.383042 \n", + "... ... \n", + "1935 185.667213 \n", + "1936 140.747286 \n", + "1937 471.050488 \n", + "1938 28.460568 \n", + "1939 700.349052 \n", + "\n", + "[1940 rows x 11 columns]" + ] + }, + "execution_count": 114, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "concat_cleaned_insurance_company_df = pd.concat([cleaned_insurance_company_df_1, cleaned_insurance_company_df_2, cleaned_insurance_company_df_3], axis=0, ignore_index=True)\n", + "concat_cleaned_insurance_company_df" ] }, { @@ -72,14 +2374,678 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 144, + "id": "7923d115-d970-49bb-989d-66939fdf0eac", + "metadata": {}, + "outputs": [], + "source": [ + "#1. You work at the marketing department and you want to know which sales channel brought the most sales in terms of total revenue. Using pivot, create a summary table showing the total revenue for each sales channel (branch, call center, web, and mail).\n", + "#Round the total revenue to 2 decimal points. Analyze the resulting table to draw insights." + ] + }, + { + "cell_type": "code", + "execution_count": 145, "id": "aa10d9b0-1c27-4d3f-a8e4-db6ab73bfd26", "metadata": { "id": "aa10d9b0-1c27-4d3f-a8e4-db6ab73bfd26" }, + "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_policiespolicy_typepolicyrenew_offer_typesales_channeltotal_claim_amountvehicle_classvehicle_sizevehicle_typemonth
00DK49336Arizona4809.216960NoBasicCollege2011-02-18EmployedM...9Corporate AutoCorporate L3Offer3Agent292.800000Four-Door CarMedsizeA2
11KX64629California2228.525238NoBasicCollege2011-01-18UnemployedF...1Personal AutoPersonal L3Offer4Call Center744.924331Four-Door CarMedsizeA1
22LZ68649Washington14947.917300NoBasicBachelor2011-02-10EmployedM...2Personal AutoPersonal L3Offer3Call Center480.000000SUVMedsizeA2
33XL78013Oregon22332.439460YesExtendedCollege2011-01-11EmployedM...2Corporate AutoCorporate L3Offer2Branch484.013411Four-Door CarMedsizeA1
44QA50777Oregon9025.067525NoPremiumBachelor2011-01-17Medical LeaveF...7Personal AutoPersonal L2Offer1Branch707.925645Four-Door CarMedsizeA1
..................................................................
1090510905FE99816Nevada15563.369440NoPremiumBachelor2011-01-19UnemployedF...7Personal AutoPersonal L1Offer3Web1214.400000Luxury CarMedsizeA1
1090610906KX53892Oregon5259.444853NoBasicCollege2011-01-06EmployedF...6Personal AutoPersonal L3Offer2Branch273.018929Four-Door CarMedsizeA1
1090710907TL39050Arizona23893.304100NoExtendedBachelor2011-02-06EmployedF...2Corporate AutoCorporate L3Offer1Web381.306996Luxury SUVMedsizeA2
1090810908WA60547California11971.977650NoPremiumCollege2011-02-13EmployedF...6Personal AutoPersonal L1Offer1Branch618.288849SUVMedsizeA2
1090910909IV32877California6857.519928NoBasicBachelor2011-01-08UnemployedM...3Personal AutoPersonal L1Offer4Web1021.719397SUVMedsizeA1
\n", + "

10910 rows × 27 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 California 6857.519928 No \n", + "\n", + " coverage education effective_to_date employmentstatus gender ... \\\n", + "0 Basic College 2011-02-18 Employed M ... \n", + "1 Basic College 2011-01-18 Unemployed F ... \n", + "2 Basic Bachelor 2011-02-10 Employed M ... \n", + "3 Extended College 2011-01-11 Employed M ... \n", + "4 Premium Bachelor 2011-01-17 Medical Leave F ... \n", + "... ... ... ... ... ... ... \n", + "10905 Premium Bachelor 2011-01-19 Unemployed F ... \n", + "10906 Basic College 2011-01-06 Employed F ... \n", + "10907 Extended Bachelor 2011-02-06 Employed F ... \n", + "10908 Premium College 2011-02-13 Employed F ... \n", + "10909 Basic Bachelor 2011-01-08 Unemployed M ... \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", + " vehicle_type month \n", + "0 A 2 \n", + "1 A 1 \n", + "2 A 2 \n", + "3 A 1 \n", + "4 A 1 \n", + "... ... ... \n", + "10905 A 1 \n", + "10906 A 1 \n", + "10907 A 2 \n", + "10908 A 2 \n", + "10909 A 1 \n", + "\n", + "[10910 rows x 27 columns]" + ] + }, + "execution_count": 145, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Your code goes here\n", + "import pandas as pd\n", + "import numpy as np\n", + "url_marketing = 'https://raw.githubusercontent.com/data-bootcamp-v4/data/main/marketing_customer_analysis_clean.csv'\n", + "marketing_df = pd.read_csv(url_marketing)\n", + "marketing_df" + ] + }, + { + "cell_type": "code", + "execution_count": 146, + "id": "cbece661-6dc0-4c71-84c7-2dfd9296853d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "RangeIndex: 10910 entries, 0 to 10909\n", + "Data columns (total 27 columns):\n", + " # Column Non-Null Count Dtype \n", + "--- ------ -------------- ----- \n", + " 0 unnamed:_0 10910 non-null int64 \n", + " 1 customer 10910 non-null object \n", + " 2 state 10910 non-null object \n", + " 3 customer_lifetime_value 10910 non-null float64\n", + " 4 response 10910 non-null object \n", + " 5 coverage 10910 non-null object \n", + " 6 education 10910 non-null object \n", + " 7 effective_to_date 10910 non-null object \n", + " 8 employmentstatus 10910 non-null object \n", + " 9 gender 10910 non-null object \n", + " 10 income 10910 non-null int64 \n", + " 11 location_code 10910 non-null object \n", + " 12 marital_status 10910 non-null object \n", + " 13 monthly_premium_auto 10910 non-null int64 \n", + " 14 months_since_last_claim 10910 non-null float64\n", + " 15 months_since_policy_inception 10910 non-null int64 \n", + " 16 number_of_open_complaints 10910 non-null float64\n", + " 17 number_of_policies 10910 non-null int64 \n", + " 18 policy_type 10910 non-null object \n", + " 19 policy 10910 non-null object \n", + " 20 renew_offer_type 10910 non-null object \n", + " 21 sales_channel 10910 non-null object \n", + " 22 total_claim_amount 10910 non-null float64\n", + " 23 vehicle_class 10910 non-null object \n", + " 24 vehicle_size 10910 non-null object \n", + " 25 vehicle_type 10910 non-null object \n", + " 26 month 10910 non-null int64 \n", + "dtypes: float64(4), int64(6), object(17)\n", + "memory usage: 2.2+ MB\n" + ] + } + ], + "source": [ + "marketing_df.info()" + ] + }, + { + "cell_type": "code", + "execution_count": 147, + "id": "2dbe66aa-f5bf-4cde-ad30-45ef02831332", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array(['Agent', 'Call Center', 'Branch', 'Web'], dtype=object)" + ] + }, + "execution_count": 147, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "marketing_df[\"sales_channel\"].unique()" + ] + }, + { + "cell_type": "code", + "execution_count": 148, + "id": "e910e345-1f49-46c0-87f1-868e400eb4ec", + "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", + "
sales_channelmonthly_premium_auto
0Agent61
1Call Center64
2Call Center100
3Branch97
4Branch117
.........
10905Web253
10906Branch65
10907Web201
10908Branch158
10909Web101
\n", + "

10910 rows × 2 columns

\n", + "
" + ], + "text/plain": [ + " sales_channel monthly_premium_auto\n", + "0 Agent 61\n", + "1 Call Center 64\n", + "2 Call Center 100\n", + "3 Branch 97\n", + "4 Branch 117\n", + "... ... ...\n", + "10905 Web 253\n", + "10906 Branch 65\n", + "10907 Web 201\n", + "10908 Branch 158\n", + "10909 Web 101\n", + "\n", + "[10910 rows x 2 columns]" + ] + }, + "execution_count": 148, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "marketing_df_sales_channel = marketing_df[[\"sales_channel\", \"monthly_premium_auto\"]]\n", + "marketing_df_sales_channel" + ] + }, + { + "cell_type": "code", + "execution_count": 150, + "id": "fc5abe10-bee7-44f4-ae01-34421dc5f260", + "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", + "
sales_channelAgentBranchCall CenterWeb
monthly_premium_auto386335.0280953.0197970.0151511.0
\n", + "
" + ], + "text/plain": [ + "sales_channel Agent Branch Call Center Web\n", + "monthly_premium_auto 386335.0 280953.0 197970.0 151511.0" + ] + }, + "execution_count": 150, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "marketing_df_sales_channel.pivot_table(index=None, columns=\"sales_channel\", values=\"monthly_premium_auto\", aggfunc='sum').astype(float).round(2)" + ] + }, + { + "cell_type": "code", + "execution_count": 151, + "id": "f25c8a22-127e-427d-8a24-9cf99220a8f0", + "metadata": {}, "outputs": [], "source": [ - "# Your code goes here" + "#The channel with the highest revenue is Agent and the one with less revenue is Web. " ] }, { @@ -103,6 +3069,250 @@ "2. Create a pivot table that shows the average customer lifetime value per gender and education level. Analyze the resulting table to draw insights." ] }, + { + "cell_type": "code", + "execution_count": 154, + "id": "5713b59d-feec-4a08-bebe-41dc9b3cc89e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['unnamed:_0', 'customer', 'state', 'customer_lifetime_value', 'response', 'coverage', 'education', 'effective_to_date', 'employmentstatus', 'gender', 'income', 'location_code', 'marital_status', 'monthly_premium_auto', 'months_since_last_claim', 'months_since_policy_inception', 'number_of_open_complaints', 'number_of_policies', 'policy_type', 'policy', 'renew_offer_type', 'sales_channel', 'total_claim_amount', 'vehicle_class', 'vehicle_size', 'vehicle_type', 'month']\n" + ] + } + ], + "source": [ + "print(marketing_df.columns.tolist())" + ] + }, + { + "cell_type": "code", + "execution_count": 158, + "id": "16e584f8-25ef-4810-a3be-02e9c7a548ff", + "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", + "
customer_lifetime_valuegendereducation
04809.216960MCollege
12228.525238FCollege
214947.917300MBachelor
322332.439460MCollege
49025.067525FBachelor
............
1090515563.369440FBachelor
109065259.444853FCollege
1090723893.304100FBachelor
1090811971.977650FCollege
109096857.519928MBachelor
\n", + "

10910 rows × 3 columns

\n", + "
" + ], + "text/plain": [ + " customer_lifetime_value gender education\n", + "0 4809.216960 M College\n", + "1 2228.525238 F College\n", + "2 14947.917300 M Bachelor\n", + "3 22332.439460 M College\n", + "4 9025.067525 F Bachelor\n", + "... ... ... ...\n", + "10905 15563.369440 F Bachelor\n", + "10906 5259.444853 F College\n", + "10907 23893.304100 F Bachelor\n", + "10908 11971.977650 F College\n", + "10909 6857.519928 M Bachelor\n", + "\n", + "[10910 rows x 3 columns]" + ] + }, + "execution_count": 158, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "marketing_df_costlifetime_gender_ed = marketing_df[[\"customer_lifetime_value\", \"gender\", \"education\"]]\n", + "marketing_df_costlifetime_gender_ed" + ] + }, + { + "cell_type": "code", + "execution_count": 159, + "id": "183d110f-ecf5-4007-8f52-593cdb1892d0", + "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", + "
genderFM
education
Bachelor7874.2694787703.601675
College7748.8233258052.459288
Doctor7328.5089167415.333638
High School or Below8675.2202018149.687783
Master8157.0531548168.832659
\n", + "
" + ], + "text/plain": [ + "gender F M\n", + "education \n", + "Bachelor 7874.269478 7703.601675\n", + "College 7748.823325 8052.459288\n", + "Doctor 7328.508916 7415.333638\n", + "High School or Below 8675.220201 8149.687783\n", + "Master 8157.053154 8168.832659" + ] + }, + "execution_count": 159, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "marketing_df_costlifetime_gender_ed.pivot_table(index='education', columns='gender', values='customer_lifetime_value', aggfunc='mean')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "73a0d694-2227-4107-af49-fda682e6013c", + "metadata": {}, + "outputs": [], + "source": [ + "#Apparently, there is no direct relation to the level of education to the customer lifetime value, as the amounts start high at the level \"High School or Below\", it descreases for Bachelors and College levels, it increases again to Master and decreases for Doctors. Also, sometimes the avarage for women and for men vary and sometimes are higher for women and lower for men, sometimes it is the opposite. " + ] + }, { "cell_type": "markdown", "id": "32c7f2e5-3d90-43e5-be33-9781b6069198", @@ -130,14 +3340,229 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 162, "id": "3a069e0b-b400-470e-904d-d17582191be4", "metadata": { "id": "3a069e0b-b400-470e-904d-d17582191be4" }, - "outputs": [], + "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", + "
monthpolicy_typenumber_of_open_complaints
02Corporate Auto0.000000
11Personal Auto0.000000
22Personal Auto0.000000
31Corporate Auto0.000000
41Personal Auto0.384256
............
109051Personal Auto0.384256
109061Personal Auto0.000000
109072Corporate Auto0.000000
109082Personal Auto4.000000
109091Personal Auto0.000000
\n", + "

10910 rows × 3 columns

\n", + "
" + ], + "text/plain": [ + " month policy_type number_of_open_complaints\n", + "0 2 Corporate Auto 0.000000\n", + "1 1 Personal Auto 0.000000\n", + "2 2 Personal Auto 0.000000\n", + "3 1 Corporate Auto 0.000000\n", + "4 1 Personal Auto 0.384256\n", + "... ... ... ...\n", + "10905 1 Personal Auto 0.384256\n", + "10906 1 Personal Auto 0.000000\n", + "10907 2 Corporate Auto 0.000000\n", + "10908 2 Personal Auto 4.000000\n", + "10909 1 Personal Auto 0.000000\n", + "\n", + "[10910 rows x 3 columns]" + ] + }, + "execution_count": 162, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Your code goes here\n", + "marketing_df_costlifetime_gender_ed = marketing_df[[\"month\", \"policy_type\", \"number_of_open_complaints\"]]\n", + "marketing_df_costlifetime_gender_ed" + ] + }, + { + "cell_type": "code", + "execution_count": 171, + "id": "c59dd400-d3dc-4821-9500-f1b03b4b0579", + "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", + "
monthpolicy_typenumber_of_open_complaints
01Corporate Auto443.434952
11Personal Auto1727.605722
21Special Auto87.074049
32Corporate Auto385.208135
42Personal Auto1453.684441
52Special Auto95.226817
\n", + "
" + ], + "text/plain": [ + " month policy_type number_of_open_complaints\n", + "0 1 Corporate Auto 443.434952\n", + "1 1 Personal Auto 1727.605722\n", + "2 1 Special Auto 87.074049\n", + "3 2 Corporate Auto 385.208135\n", + "4 2 Personal Auto 1453.684441\n", + "5 2 Special Auto 95.226817" + ] + }, + "execution_count": 171, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code goes here" + "marketing_df_costlifetime_gender_ed_sum = marketing_df_costlifetime_gender_ed.groupby(['month', 'policy_type'])['number_of_open_complaints'].sum().reset_index()\n", + "marketing_df_costlifetime_gender_ed_sum" ] } ], @@ -160,7 +3585,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4,