From 197990185af1b80b864be9dc389abb0f5379e22a Mon Sep 17 00:00:00 2001 From: cleidenirlopes Date: Sat, 16 Nov 2024 10:46:38 +0000 Subject: [PATCH] lab-dw-pandas --- lab-dw-pandas.ipynb | 830 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 815 insertions(+), 15 deletions(-) diff --git a/lab-dw-pandas.ipynb b/lab-dw-pandas.ipynb index fbd468314..91a4ffebb 100644 --- a/lab-dw-pandas.ipynb +++ b/lab-dw-pandas.ipynb @@ -82,12 +82,183 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "dd4e8cd8-a6f6-486c-a5c4-1745b0c035f4", "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "import pandas as pd\n", + "\n", + "# Load the dataset\n", + "url = \"https://raw.githubusercontent.com/data-bootcamp-v4/data/main/file1.csv\"\n", + "Pandas_Int = pd.read_csv(url)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "1f4e20f3", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Customer ST 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 1/0/00 Personal Auto \n", + "1 0.0 94.0 1/0/00 Personal Auto \n", + "2 48767.0 108.0 1/0/00 Personal Auto \n", + "3 0.0 106.0 1/0/00 Corporate Auto \n", + "4 36357.0 68.0 1/0/00 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" + ] + } + ], + "source": [ + "print(Pandas_Int .head())" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "9e55aa66", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Index(['Customer', 'ST', '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", + "(4008, 11)\n" + ] + } + ], + "source": [ + "# Display the first 5 rows\n", + "print(Pandas_Int.columns)\n", + "print(Pandas_Int.shape)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "5e75b46c", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " The Dataframe has 4008 rows and 11 columns.\n" + ] + } + ], + "source": [ + "rows,columns = Pandas_Int.shape\n", + "print(f\" The Dataframe has {rows} rows and {columns} columns.\")" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "fa2b055d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Customer object\n", + "ST object\n", + "GENDER object\n", + "Education object\n", + "Customer Lifetime Value object\n", + "Income float64\n", + "Monthly Premium Auto float64\n", + "Number of Open Complaints object\n", + "Policy Type object\n", + "Vehicle Class object\n", + "Total Claim Amount float64\n", + "dtype: object\n" + ] + } + ], + "source": [ + "print(Pandas_Int.dtypes)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "cbd21f05", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Unique Values per Columns:\n", + " Customer 1071\n", + "ST 8\n", + "GENDER 5\n", + "Education 6\n", + "Customer Lifetime Value 1027\n", + "Income 774\n", + "Monthly Premium Auto 132\n", + "Number of Open Complaints 6\n", + "Policy Type 3\n", + "Vehicle Class 6\n", + "Total Claim Amount 761\n", + "dtype: int64\n" + ] + } + ], + "source": [ + "# Unique values in each column\n", + "unique_counts = Pandas_Int.nunique()\n", + "\n", + "# Separate categorical and numerical columns\n", + "categorical_columns = Pandas_Int.select_dtypes(include = [\"object\", \"category\"]).columns\n", + "numerical_columns = Pandas_Int.select_dtypes(include = ['int64', 'float64']).columns\n", + "print(\"Unique Values per Columns:\\n\", unique_counts)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "0b59362f", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Range of'Income' : 0.0 to 99960.0\n", + "Range of'Monthly Premium Auto' : 61.0 to 35354.0\n", + "Range of'Total Claim Amount' : 0.382107 to 2893.239678\n" + ] + } + ], + "source": [ + "# Describe unique values in categorical columns\n", + "for col in numerical_columns:\n", + " print(f\"Range of'{col}' : {Pandas_Int[col].min()} to {Pandas_Int[col].max()}\")" ] }, { @@ -98,6 +269,142 @@ "## Challenge 2: analyzing the data" ] }, + { + "cell_type": "code", + "execution_count": 14, + "id": "01038752", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Summary Statistics:\n", + " Income Monthly Premium Auto Total Claim Amount\n", + "count 724.000000 724.000000 724.000000\n", + "mean 52014.638122 226.349448 347.675170\n", + "std 24381.361877 1910.086258 270.301754\n", + "min 10269.000000 61.000000 0.382107\n", + "25% 29462.000000 68.000000 141.891985\n", + "50% 50540.500000 82.000000 321.600000\n", + "75% 71199.000000 109.000000 480.256879\n", + "max 99960.000000 35354.000000 2893.239678\n" + ] + } + ], + "source": [ + "#Calculate Summary Statistics\n", + "summary_stats = Pandas_Int.describe()\n", + "print(\"Summary Statistics:\\n\", summary_stats)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "93702e9d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Mode of 'Income':\n", + " [43860.]\n", + "Mode of 'Monthly Premium Auto':\n", + " [65.]\n", + "Mode of 'Total Claim Amount':\n", + " [321.6]\n" + ] + } + ], + "source": [ + "#Calculate Mode\n", + "for col in Pandas_Int.select_dtypes(include=['int64', 'float64']).columns:\n", + " print(f\"Mode of '{col}':\\n\", Pandas_Int[col].mode().values)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "eb182714", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Median:\n", + " Income 50540.5\n", + "Monthly Premium Auto 82.0\n", + "Total Claim Amount 321.6\n", + "dtype: float64\n" + ] + } + ], + "source": [ + "# Calculate the median for numerical columns only\n", + "numerical_columns = Pandas_Int.select_dtypes(include=['int64', 'float64'])\n", + "print(\"Median:\\n\", numerical_columns.median())" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "29323190", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Standard Deviation:\n", + " Income 24381.361877\n", + "Monthly Premium Auto 1910.086258\n", + "Total Claim Amount 270.301754\n", + "dtype: float64\n" + ] + } + ], + "source": [ + "# Filter numerical columns\n", + "numerical_columns = Pandas_Int.select_dtypes(include=['int64', 'float64'])\n", + "\n", + "# Compute the standard deviation for numerical columns\n", + "print(\"Standard Deviation:\\n\", numerical_columns.std())" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "c8b4d851", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Interquartile Range (IQR):\n", + " Income 41737.000000\n", + "Monthly Premium Auto 41.000000\n", + "Total Claim Amount 338.364894\n", + "dtype: float64\n" + ] + } + ], + "source": [ + "# Filter numerical columns\n", + "numerical_columns = Pandas_Int.select_dtypes(include=['int64', 'float64'])\n", + "\n", + "# Calculate the first and third quartiles for numerical columns\n", + "Q1 = numerical_columns.quantile(0.25)\n", + "Q3 = numerical_columns.quantile(0.75)\n", + "\n", + "# Calculate the Interquartile Range (IQR)\n", + "IQR = Q3 - Q1\n", + "\n", + "print(\"Interquartile Range (IQR):\\n\", IQR)" + ] + }, { "cell_type": "markdown", "id": "0776a403-c56a-452f-ac33-5fd4fdb06fc7", @@ -116,12 +423,95 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "id": "2dca5073-4520-4f42-9390-4b92733284ed", "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "+----+------------+------------+----------+----------------------+---------------------------+----------+------------------------+-----------------------------+----------------+-----------------+----------------------+---------------------+\n", + "| | Customer | States | GENDER | Education | Customer Lifetime Value | Income | Monthly Premium Auto | Number of Open Complaints | Policy Type | Vehicle Class | Total Claim Amount | Customer_Location |\n", + "+====+============+============+==========+======================+===========================+==========+========================+=============================+================+=================+======================+=====================+\n", + "| 2 | AI49188 | Nevada | F | Bachelor | 1288743.17% | 48767 | 108 | 1/0/00 | Personal Auto | Two-Door Car | 566.472 | Nevada |\n", + "+----+------------+------------+----------+----------------------+---------------------------+----------+------------------------+-----------------------------+----------------+-----------------+----------------------+---------------------+\n", + "| 4 | GA49547 | Washington | M | High School or Below | 536307.65% | 36357 | 68 | 1/0/00 | Personal Auto | Four-Door Car | 17.2693 | Washington |\n", + "+----+------------+------------+----------+----------------------+---------------------------+----------+------------------------+-----------------------------+----------------+-----------------+----------------------+---------------------+\n", + "| 5 | OC83172 | Oregon | F | Bachelor | 825629.78% | 62902 | 69 | 1/0/00 | Personal Auto | Two-Door Car | 159.383 | Oregon |\n", + "+----+------------+------------+----------+----------------------+---------------------------+----------+------------------------+-----------------------------+----------------+-----------------+----------------------+---------------------+\n", + "| 6 | XZ87318 | Oregon | F | College | 538089.86% | 55350 | 67 | 1/0/00 | Corporate Auto | Four-Door Car | 321.6 | Oregon |\n", + "+----+------------+------------+----------+----------------------+---------------------------+----------+------------------------+-----------------------------+----------------+-----------------+----------------------+---------------------+\n", + "| 8 | DY87989 | Oregon | M | Bachelor | 2412750.40% | 14072 | 71 | 1/0/00 | Corporate Auto | Four-Door Car | 511.2 | Oregon |\n", + "+----+------------+------------+----------+----------------------+---------------------------+----------+------------------------+-----------------------------+----------------+-----------------+----------------------+---------------------+\n", + "| 9 | BQ94931 | Oregon | F | College | 738817.81% | 28812 | 93 | 1/0/00 | Special Auto | Four-Door Car | 425.528 | Oregon |\n", + "+----+------------+------------+----------+----------------------+---------------------------+----------+------------------------+-----------------------------+----------------+-----------------+----------------------+---------------------+\n", + "| 21 | QK46697 | Washington | M | Bachelors | 617710.93% | 61040 | 79 | 1/1/00 | Personal Auto | Two-Door Car | 20.3829 | Washington |\n", + "+----+------------+------------+----------+----------------------+---------------------------+----------+------------------------+-----------------------------+----------------+-----------------+----------------------+---------------------+\n", + "| 27 | HS14476 | Washington | M | College | 916206.32% | 29723 | 80 | 1/0/00 | Personal Auto | Four-Door Car | 20.9851 | Washington |\n", + "+----+------------+------------+----------+----------------------+---------------------------+----------+------------------------+-----------------------------+----------------+-----------------+----------------------+---------------------+\n", + "| 44 | YD87931 | Washington | M | Doctor | 495165.61% | 46896 | 35354 | 1/1/00 | Personal Auto | Four-Door Car | 31.7073 | Washington |\n", + "+----+------------+------------+----------+----------------------+---------------------------+----------+------------------------+-----------------------------+----------------+-----------------+----------------------+---------------------+\n", + "| 53 | NW21079 | Washington | F | Master | 487938.48% | 67163 | 61 | 1/2/00 | Personal Auto | Two-Door Car | 33.1928 | Washington |\n", + "+----+------------+------------+----------+----------------------+---------------------------+----------+------------------------+-----------------------------+----------------+-----------------+----------------------+---------------------+\n" + ] + } + ], + "source": [ + "#Tabulate library\n", + "from tabulate import tabulate\n", + "\n", + "# Display the first 10 rows of the DataFrame with borders\n", + "print(tabulate(Pandas_Int.head(10), headers='keys', tablefmt='grid'))" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "367b27da", + "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "# Rename the 'ST' column to 'States'\n", + "Pandas_Int.rename(columns={'ST': 'States'}, inplace=True)\n", + "# Remove rows where any column has blank values or zeros\n", + "Pandas_Int = Pandas_Int[(Pandas_Int != 0).all(axis=1)] # Remove rows where any column is zero\n", + "Pandas_Int = Pandas_Int[(Pandas_Int != '').all(axis=1)] # Remove rows where any column is blank\n", + "# Drop rows with NaN or NULL values\n", + "Pandas_Int.dropna(inplace=True)\n", + "# Create a Column Customer Location\n", + "Pandas_Int['Customer_Location'] = Pandas_Int['States']" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "a6ec18be", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Top 5 Least Common Customer Locations:\n", + " Customer_Location\n", + "AZ 8\n", + "WA 20\n", + "Nevada 62\n", + "Washington 74\n", + "Cali 95\n", + "Name: count, dtype: int64\n" + ] + } + ], + "source": [ + "# Customer locations\n", + "location_counts = Pandas_Int['Customer_Location'].value_counts()\n", + "\n", + "# Sort the location counts in ascending order and retrieve the top 5 least common locations\n", + "top_5_least_common_locations = location_counts.sort_values(ascending=True).head(5)\n", + "\n", + "print(\"Top 5 Least Common Customer Locations:\\n\", top_5_least_common_locations)" ] }, { @@ -146,12 +536,38 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "id": "bcfad6c1-9af2-4b0b-9aa9-0dc5c17473c0", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Total policies sold for each type:\n", + " Policy Type\n", + "Personal Auto 519\n", + "Corporate Auto 161\n", + "Special Auto 44\n", + "Name: count, dtype: int64\n", + "\n", + "The policy type with the highest number of policies sold is 'Personal Auto' with 519 policies sold.\n" + ] + } + ], "source": [ - "# Your code here" + "# Count occurrences of each policy type\n", + "policy_sales = Pandas_Int['Policy Type'].value_counts()\n", + "\n", + "# Display the total number of policies sold for each type\n", + "print(\"Total policies sold for each type:\\n\", policy_sales)\n", + "\n", + "# Identify the policy type with the highest sales\n", + "top_policy = policy_sales.idxmax()\n", + "top_sales = policy_sales.max()\n", + "\n", + "# Print the results\n", + "print(f\"\\nThe policy type with the highest number of policies sold is '{top_policy}' with {top_sales} policies sold.\")" ] }, { @@ -176,12 +592,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "id": "0c0563cf-6f8b-463d-a321-651a972f82e5", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Average income of customers with Personal Auto policies: $51301.91\n", + "Average income of customers with Corporate Auto policies: $53778.14\n" + ] + } + ], "source": [ - "# Your code here" + "# Filter data for Personal Auto and Corporate Auto policies\n", + "personal_auto = Pandas_Int.loc[Pandas_Int['Policy Type'] == 'Personal Auto']\n", + "corporate_auto = Pandas_Int.loc[Pandas_Int['Policy Type'] == 'Corporate Auto']\n", + "\n", + "# Calculate average income for each policy type\n", + "avg_income_personal = personal_auto['Income'].mean()\n", + "avg_income_corporate = corporate_auto['Income'].mean()\n", + "\n", + "# Print the results\n", + "print(f\"Average income of customers with Personal Auto policies: ${avg_income_personal:.2f}\")\n", + "print(f\"Average income of customers with Corporate Auto policies: ${avg_income_corporate:.2f}\")" ] }, { @@ -226,18 +661,383 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "id": "b731bca6-a760-4860-a27b-a33efa712ce0", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Statistics for Total Claim Amount:\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", + "
 Total Claim Amount
count724.000000
mean347.675170
std270.301754
min0.382107
25%141.891985
50%321.600000
75%480.256879
max2893.239678
\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Top 25% customers based on Total Claim Amount:\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", + "
 CustomerStatesGENDEREducationCustomer Lifetime ValueIncomeMonthly Premium AutoNumber of Open ComplaintsPolicy TypeVehicle ClassTotal Claim AmountCustomer_Location
2AI49188NevadaFBachelor1288743.17%48767.000000108.0000001/0/00Personal AutoTwo-Door Car566.472247Nevada
8DY87989OregonMBachelor2412750.40%14072.00000071.0000001/0/00Corporate AutoFour-Door Car511.200000Oregon
152PD27940ArizonaMHigh School or Below488516.25%26372.000000126.0000001/0/00Personal AutoSUV604.800000Arizona
158KA61892ArizonaMCollege387364.70%28142.000000105.0000001/0/00Personal AutoSports Car701.708239Arizona
170TS19868CaliforniaMCollege241313.97%27501.00000063.0000001/0/00Personal AutoFour-Door Car542.319401California
174DX91392CaliforniaMHigh School or Below578018.22%51066.00000074.0000001/0/00Personal AutoFour-Door Car787.993313California
179HH90090CaliforniaFBachelor407663.47%29549.000000104.0000001/0/00Personal AutoSports Car710.433775California
181KC11055NevadaFBachelor1693627.15%39411.000000217.0000001/2/00Personal AutoLuxury Car1122.658899Nevada
185OZ97704CaliforniaFHigh School or Below1311752.22%84311.000000111.0000001/4/00Personal AutoSUV532.800000California
186UF46533CaliforniaFCollege457452.41%99316.000000114.0000001/0/00Corporate AutoSUV754.358929California
\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Summary statistics for high policy claim amount data:\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", + "
 IncomeMonthly Premium AutoTotal Claim Amount
count181.000000181.000000181.000000
mean43845.790055129.701657687.909080
std22709.21704079.491715284.490353
min10312.00000063.000000481.027516
25%24506.000000103.000000528.000000
50%38736.000000112.000000600.000000
75%58842.000000131.000000710.433775
max99316.0000001005.0000002893.239678
\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ - "# Your code here" + "from IPython.display import display\n", + "\n", + "\n", + "# Review statistics for Total Claim Amount\n", + "total_claim_stats = Pandas_Int['Total Claim Amount'].describe()\n", + "print(\"Statistics for Total Claim Amount:\")\n", + "display(total_claim_stats.to_frame().style.set_table_attributes(\"style='display:inline'\").set_table_styles(\n", + " [{'selector': 'table', 'props': [('border', '2px solid black')]}]))\n", + "\n", + "# Identify customers with high policy claim amount (greater than the 75th percentile)\n", + "q3 = Pandas_Int['Total Claim Amount'].quantile(0.75)\n", + "high_claim_customers = Pandas_Int.loc[Pandas_Int['Total Claim Amount'] > q3]\n", + "print(\"\\nTop 25% customers based on Total Claim Amount:\")\n", + "display(high_claim_customers.head(10).style.set_table_attributes(\"style='display:inline'\").set_table_styles(\n", + " [{'selector': 'table', 'props': [('border', '2px solid black')]}]))\n", + "\n", + "# Calculate summary statistics for high policy claim amount data\n", + "high_claim_summary = high_claim_customers.describe()\n", + "print(\"\\nSummary statistics for high policy claim amount data:\")\n", + "display(high_claim_summary.style.set_table_attributes(\"style='display:inline'\").set_table_styles(\n", + " [{'selector': 'table', 'props': [('border', '2px solid black')]}]))" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -251,7 +1051,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.0" } }, "nbformat": 4,