0% found this document useful (0 votes)
15 views13 pages

Upload and Analyze Automobile Data

Uploaded by

rimlums2021
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views13 pages

Upload and Analyze Automobile Data

Uploaded by

rimlums2021
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

{

"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "code",
"source": [
"from [Link] import files\n",
"uploaded = [Link] ()\n",
"import pandas as pd\n",
"df=pd.read_csv(\"Automobile_data.csv\")\n",
"[Link]()"
],
"metadata": {
"colab": {
"base_uri": "[Link]
"height": 356
},
"id": "NZJ2j-ZUFdvZ",
"outputId": "39216710-241d-4db7-9ba4-2f89513375a0"
},
"execution_count": null,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": [
"<[Link] object>"
],
"text/html": [
"\n",
" <input type=\"file\" id=\"files-4cd713c1-2402-4963-8a45-
3ba2e7f4f2cb\" name=\"files[]\" multiple disabled\n",
" style=\"border:none\" />\n",
" <output id=\"result-4cd713c1-2402-4963-8a45-3ba2e7f4f2cb\">\n",
" Upload widget is only available when the cell has been
executed in the\n",
" current browser session. Please rerun this cell to enable.\n",
" </output>\n",
" <script>// Copyright 2017 Google LLC\n",
"//\n",
"// Licensed under the Apache License, Version 2.0
(the \"License\");\n",
"// you may not use this file except in compliance with the License.\
n",
"// You may obtain a copy of the License at\n",
"//\n",
"// [Link]
"//\n",
"// Unless required by applicable law or agreed to in writing,
software\n",
"// distributed under the License is distributed on an \"AS IS\"
BASIS,\n",
"// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.\n",
"// See the License for the specific language governing permissions
and\n",
"// limitations under the License.\n",
"\n",
"/**\n",
" * @fileoverview Helpers for [Link] Python module.\n",
" */\n",
"(function(scope) {\n",
"function span(text, styleAttributes = {}) {\n",
" const element = [Link]('span');\n",
" [Link] = text;\n",
" for (const key of [Link](styleAttributes)) {\n",
" [Link][key] = styleAttributes[key];\n",
" }\n",
" return element;\n",
"}\n",
"\n",
"// Max number of bytes which will be uploaded at a time.\n",
"const MAX_PAYLOAD_SIZE = 100 * 1024;\n",
"\n",
"function _uploadFiles(inputId, outputId) {\n",
" const steps = uploadFilesStep(inputId, outputId);\n",
" const outputElement = [Link](outputId);\n",
" // Cache steps on the outputElement to make it available for the
next call\n",
" // to uploadFilesContinue from Python.\n",
" [Link] = steps;\n",
"\n",
" return _uploadFilesContinue(outputId);\n",
"}\n",
"\n",
"// This is roughly an async generator (not supported in the browser
yet),\n",
"// where there are multiple asynchronous steps and the Python side
is going\n",
"// to poll for completion of each step.\n",
"// This uses a Promise to block the python side on completion of
each step,\n",
"// then passes the result of the previous step as the input to the
next step.\n",
"function _uploadFilesContinue(outputId) {\n",
" const outputElement = [Link](outputId);\n",
" const steps = [Link];\n",
"\n",
" const next = [Link]([Link]);\n",
" return [Link]([Link]).then((value) => {\n",
" // Cache the last promise value to make it available to the
next\n",
" // step of the generator.\n",
" [Link] = value;\n",
" return [Link];\n",
" });\n",
"}\n",
"\n",
"/**\n",
" * Generator function which is called between each async step of the
upload\n",
" * process.\n",
" * @param {string} inputId Element ID of the input file picker
element.\n",
" * @param {string} outputId Element ID of the output display.\n",
" * @return {!Iterable<!Object>} Iterable of next steps.\n",
" */\n",
"function* uploadFilesStep(inputId, outputId) {\n",
" const inputElement = [Link](inputId);\n",
" [Link] = false;\n",
"\n",
" const outputElement = [Link](outputId);\n",
" [Link] = '';\n",
"\n",
" const pickedPromise = new Promise((resolve) => {\n",
" [Link]('change', (e) => {\n",
" resolve([Link]);\n",
" });\n",
" });\n",
"\n",
" const cancel = [Link]('button');\n",
" [Link](cancel);\n",
" [Link] = 'Cancel upload';\n",
" const cancelPromise = new Promise((resolve) => {\n",
" [Link] = () => {\n",
" resolve(null);\n",
" };\n",
" });\n",
"\n",
" // Wait for the user to pick the files.\n",
" const files = yield {\n",
" promise: [Link]([pickedPromise, cancelPromise]),\n",
" response: {\n",
" action: 'starting',\n",
" }\n",
" };\n",
"\n",
" [Link]();\n",
"\n",
" // Disable the input element since further picks are not allowed.\
n",
" [Link] = true;\n",
"\n",
" if (!files) {\n",
" return {\n",
" response: {\n",
" action: 'complete',\n",
" }\n",
" };\n",
" }\n",
"\n",
" for (const file of files) {\n",
" const li = [Link]('li');\n",
" [Link](span([Link], {fontWeight: 'bold'}));\n",
" [Link](span(\n",
" `(${[Link] || 'n/a'}) - ${[Link]} bytes, ` +\n",
" `last modified: ${\n",
" [Link] ?
[Link]() :\n",
" 'n/a'} - `));\n",
" const percent = span('0% done');\n",
" [Link](percent);\n",
"\n",
" [Link](li);\n",
"\n",
" const fileDataPromise = new Promise((resolve) => {\n",
" const reader = new FileReader();\n",
" [Link] = (e) => {\n",
" resolve([Link]);\n",
" };\n",
" [Link](file);\n",
" });\n",
" // Wait for the data to be ready.\n",
" let fileData = yield {\n",
" promise: fileDataPromise,\n",
" response: {\n",
" action: 'continue',\n",
" }\n",
" };\n",
"\n",
" // Use a chunked sending to avoid message size limits. See
b/62115660.\n",
" let position = 0;\n",
" do {\n",
" const length = [Link]([Link] - position,
MAX_PAYLOAD_SIZE);\n",
" const chunk = new Uint8Array(fileData, position, length);\n",
" position += length;\n",
"\n",
" const base64 = btoa([Link](null, chunk));\
n",
" yield {\n",
" response: {\n",
" action: 'append',\n",
" file: [Link],\n",
" data: base64,\n",
" },\n",
" };\n",
"\n",
" let percentDone = [Link] === 0 ?\n",
" 100 :\n",
" [Link]((position / [Link]) * 100);\n",
" [Link] = `${percentDone}% done`;\n",
"\n",
" } while (position < [Link]);\n",
" }\n",
"\n",
" // All done.\n",
" yield {\n",
" response: {\n",
" action: 'complete',\n",
" }\n",
" };\n",
"}\n",
"\n",
"[Link] = [Link] || {};\n",
"[Link] = [Link] || {};\n",
"[Link]._files = {\n",
" _uploadFiles,\n",
" _uploadFilesContinue,\n",
"};\n",
"})(self);\n",
"</script> "
]
},
"metadata": {}
},
{
"output_type": "stream",
"name": "stdout",
"text": [
"Saving Automobile_data.csv to Automobile_data (1).csv\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
" wheelbase length horsepower averagemileage
price\n",
"count 61.000000 61.000000 61.000000 61.000000
58.000000\n",
"mean 98.481967 173.098361 107.852459 25.803279
15387.000000\n",
"std 6.679234 14.021846 53.524398 8.129821
11320.259841\n",
"min 88.400000 141.100000 48.000000 13.000000
5151.000000\n",
"25% 94.500000 159.100000 68.000000 19.000000
6808.500000\n",
"50% 96.300000 171.200000 100.000000 25.000000
11095.000000\n",
"75% 101.200000 177.300000 123.000000 31.000000
18120.500000\n",
"max 120.900000 208.100000 288.000000 47.000000
45400.000000"
],
"text/html": [
"\n",
" <div id=\"df-2449ac60-253e-419a-b4c0-0cf1230c74ff\">\n",
" <div class=\"colab-df-container\">\n",
" <div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>wheelbase</th>\n",
" <th>length</th>\n",
" <th>horsepower</th>\n",
" <th>averagemileage</th>\n",
" <th>price</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>count</th>\n",
" <td>61.000000</td>\n",
" <td>61.000000</td>\n",
" <td>61.000000</td>\n",
" <td>61.000000</td>\n",
" <td>58.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>mean</th>\n",
" <td>98.481967</td>\n",
" <td>173.098361</td>\n",
" <td>107.852459</td>\n",
" <td>25.803279</td>\n",
" <td>15387.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>std</th>\n",
" <td>6.679234</td>\n",
" <td>14.021846</td>\n",
" <td>53.524398</td>\n",
" <td>8.129821</td>\n",
" <td>11320.259841</td>\n",
" </tr>\n",
" <tr>\n",
" <th>min</th>\n",
" <td>88.400000</td>\n",
" <td>141.100000</td>\n",
" <td>48.000000</td>\n",
" <td>13.000000</td>\n",
" <td>5151.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25%</th>\n",
" <td>94.500000</td>\n",
" <td>159.100000</td>\n",
" <td>68.000000</td>\n",
" <td>19.000000</td>\n",
" <td>6808.500000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>50%</th>\n",
" <td>96.300000</td>\n",
" <td>171.200000</td>\n",
" <td>100.000000</td>\n",
" <td>25.000000</td>\n",
" <td>11095.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>75%</th>\n",
" <td>101.200000</td>\n",
" <td>177.300000</td>\n",
" <td>123.000000</td>\n",
" <td>31.000000</td>\n",
" <td>18120.500000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>max</th>\n",
" <td>120.900000</td>\n",
" <td>208.100000</td>\n",
" <td>288.000000</td>\n",
" <td>47.000000</td>\n",
" <td>45400.000000</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>\n",
" <button class=\"colab-df-convert\"
onclick=\"convertToInteractive('df-2449ac60-253e-419a-b4c0-0cf1230c74ff')\"\n",
" title=\"Convert this dataframe to an interactive
table.\"\n",
" style=\"display:none;\">\n",
" \n",
" <svg xmlns=\"[Link]
height=\"24px\"viewBox=\"0 0 24 24\"\n",
" width=\"24px\">\n",
" <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
" <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-
2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-
2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94
2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-
1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.[Link]
[Link] 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4
18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
" </svg>\n",
" </button>\n",
" \n",
" <style>\n",
" .colab-df-container {\n",
" display:flex;\n",
" flex-wrap:wrap;\n",
" gap: 12px;\n",
" }\n",
"\n",
" .colab-df-convert {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-convert:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px
rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
"\n",
" <script>\n",
" const buttonEl =\n",
" [Link]('#df-2449ac60-253e-419a-b4c0-
0cf1230c74ff [Link]-df-convert');\n",
" [Link] =\n",
" [Link] ? 'block' : 'none';\n",
"\n",
" async function convertToInteractive(key) {\n",
" const element = [Link]('#df-2449ac60-253e-
419a-b4c0-0cf1230c74ff');\n",
" const dataTable =\n",
" await
[Link]('convertToInteractive',\n",
" [key], {});\n",
" if (!dataTable) return;\n",
"\n",
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
" '<a target=\"_blank\"
href=[Link] table
notebook</a>'\n",
" + ' to learn more about interactive tables.';\n",
" [Link] = '';\n",
" dataTable['output_type'] = 'display_data';\n",
" await [Link](dataTable,
element);\n",
" const docLink = [Link]('div');\n",
" [Link] = docLinkHtml;\n",
" [Link](docLink);\n",
" }\n",
" </script>\n",
" </div>\n",
" </div>\n",
" "
]
},
"metadata": {},
"execution_count": 32
}
]
},
{
"cell_type": "code",
"source": [
"#Find the most expensive car.\n",
"most_expensive_car = df[df['price'] == df['price'].max()]\n",
"print(most_expensive_car)"
],
"metadata": {
"colab": {
"base_uri": "[Link]
},
"id": "RGA6mhxEF6Ws",
"outputId": "6f2551f0-5e02-41a8-8224-603faaeb9a17"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
" company bodystyle wheelbase length enginetype
numofcylinders \\\n",
"35 mercedes-benz hardtop 112.0 199.2 ohcv
eight \n",
"\n",
" horsepower averagemileage price Country \n",
"35 184 14 45400.0 Germany \n"
]
}
]
},
{
"cell_type": "code",
"source": [
"#Find the car with highest horsepower.\n",
"most_powerful_car = df[df['horsepower'] == df['horsepower'].max()]\n",
"print(most_powerful_car)"
],
"metadata": {
"colab": {
"base_uri": "[Link]
},
"id": "vCucdFBfGS7A",
"outputId": "2f9e0a9a-17e6-4d22-b74a-8f5aa61e2dae"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
" company bodystyle wheelbase length enginetype
numofcylinders \\\n",
"47 porsche hatchback 98.4 175.7 dohcv
eight \n",
"\n",
" horsepower averagemileage price Country \n",
"47 288 17 NaN Germany \n"
]
}
]
},
{
"cell_type": "code",
"source": [
"#Print details of all “Sedan” cars\n",
"sedan= df[\"bodystyle\"].isin([\"sedan\"])\n",
"print(df[sedan])"
],
"metadata": {
"colab": {
"base_uri": "[Link]
},
"id": "vmfVIU1hGaqz",
"outputId": "4145053f-5c57-4b22-84d4-27fff4a34989"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
" company bodystyle wheelbase length enginetype
numofcylinders \\\n",
"3 audi sedan 99.8 176.6 ohc
four \n",
"4 audi sedan 99.4 176.6 ohc
five \n",
"5 audi sedan 99.8 177.3 ohc
five \n",
"7 bmw sedan 101.2 176.8 ohc
four \n",
"8 bmw sedan 101.2 176.8 ohc
four \n",
"9 bmw sedan 101.2 176.8 ohc
six \n",
"10 bmw sedan 103.5 189.0 ohc
six \n",
"11 bmw sedan 103.5 193.8 ohc
six \n",
"12 bmw sedan 110.0 197.0 ohc
six \n",
"15 chevrolet sedan 94.5 158.8 ohc
four \n",
"19 honda sedan 96.5 175.4 ohc
four \n",
"20 honda sedan 96.5 169.1 ohc
four \n",
"21 isuzu sedan 94.3 170.7 ohc
four \n",
"22 isuzu sedan 94.5 155.9 ohc
four \n",
"23 isuzu sedan 94.5 155.9 ohc
four \n",
"24 jaguar sedan 113.0 199.6 dohc
six \n",
"25 jaguar sedan 113.0 199.6 dohc
six \n",
"26 jaguar sedan 102.0 191.7 ohcv
twelve \n",
"31 mazda sedan 104.9 175.0 ohc
four \n",
"32 mercedes-benz sedan 110.0 190.9 ohc
five \n",
"34 mercedes-benz sedan 120.9 208.1 ohcv
eight \n",
"38 mitsubishi sedan 96.3 172.4 ohc
four \n",
"39 mitsubishi sedan 96.3 172.4 ohc
four \n",
"40 nissan sedan 94.5 165.3 ohc
four \n",
"41 nissan sedan 94.5 165.3 ohc
four \n",
"42 nissan sedan 94.5 165.3 ohc
four \n",
"44 nissan sedan 100.4 184.6 ohcv
six \n",
"55 volkswagen sedan 97.3 171.7 ohc
four \n",
"56 volkswagen sedan 97.3 171.7 ohc
four \n",
"57 volkswagen sedan 97.3 171.7 ohc
four \n",
"58 volkswagen sedan 97.3 171.7 ohc
four \n",
"59 volvo sedan 104.3 188.8 ohc
four \n",
"\n",
" horsepower averagemileage price Country \n",
"3 102 24 13950.0 Germany \n",
"4 115 18 17450.0 Germany \n",
"5 110 19 15250.0 Germany \n",
"7 101 23 16430.0 Germany \n",
"8 101 23 16925.0 Germany \n",
"9 121 21 20970.0 Germany \n",
"10 182 16 30760.0 Germany \n",
"11 182 16 41315.0 Germany \n",
"12 182 15 36880.0 Germany \n",
"15 70 38 6575.0 America \n",
"19 101 24 12945.0 Japan \n",
"20 100 25 10345.0 Japan \n",
"21 78 24 6785.0 Japan \n",
"22 70 38 NaN Japan \n",
"23 70 38 NaN Japan \n",
"24 176 15 32250.0 UK \n",
"25 176 15 35550.0 UK \n",
"26 262 13 36000.0 UK \n",
"31 72 31 18344.0 Japan \n",
"32 123 22 25552.0 Germany \n",
"34 184 14 40960.0 Germany \n",
"38 88 25 6989.0 Japan \n",
"39 88 25 8189.0 Japan \n",
"40 55 45 7099.0 Japan \n",
"41 69 31 6649.0 Japan \n",
"42 69 31 6849.0 Japan \n",
"44 152 19 13499.0 Japan \n",
"55 52 37 7775.0 Germany \n",
"56 85 27 7975.0 Germany \n",
"57 52 37 7995.0 Germany \n",
"58 100 26 9995.0 Germany \n",
"59 114 23 12940.0 Sweden \n"
]
}
]
},
{
"cell_type": "code",
"source": [
"#Find average-mileage of each car company.\n",
"average_mileage = [Link]('company')['averagemileage'].mean()\n",
"print(average_mileage)"
],
"metadata": {
"colab": {
"base_uri": "[Link]
},
"id": "PpiJ4JYUJ43M",
"outputId": "7228bab8-40ed-44c8-ef78-1892ca521e3b"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"company\n",
"alfa-romero 20.333333\n",
"audi 20.000000\n",
"bmw 19.000000\n",
"chevrolet 41.000000\n",
"dodge 31.000000\n",
"honda 26.333333\n",
"isuzu 33.333333\n",
"jaguar 14.333333\n",
"mazda 28.000000\n",
"mercedes-benz 18.000000\n",
"mitsubishi 29.500000\n",
"nissan 31.400000\n",
"porsche 17.000000\n",
"toyota 28.714286\n",
"volkswagen 31.750000\n",
"volvo 23.000000\n",
"Name: averagemileage, dtype: float64\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"#Find each company’s most expensive car.\n",
"most_expensive_car = [Link]('company')['price'].max()\n",
"print(most_expensive_car)"
],
"metadata": {
"colab": {
"base_uri": "[Link]
},
"id": "BOHuF4SsKg-r",
"outputId": "7e04868e-6194-46c0-bf1c-c7776a7bdcaa"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"company\n",
"alfa-romero 16500.0\n",
"audi 18920.0\n",
"bmw 41315.0\n",
"chevrolet 6575.0\n",
"dodge 6377.0\n",
"honda 12945.0\n",
"isuzu 6785.0\n",
"jaguar 36000.0\n",
"mazda 18344.0\n",
"mercedes-benz 45400.0\n",
"mitsubishi 8189.0\n",
"nissan 13499.0\n",
"porsche 37028.0\n",
"toyota 15750.0\n",
"volkswagen 9995.0\n",
"volvo 13415.0\n",
"Name: price, dtype: float64\n"
]
}
]
}
]
}

You might also like