Files
fenago f3b24b4b7f added
2021-02-07 15:16:01 +05:00

153 lines
3.0 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "HEiOAwQPW0qb"
},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "j7whidfaYjns"
},
"outputs": [],
"source": [
"file_url = '../dataset/ames_iowa_housing.csv'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "nFMz2jNVt-xy"
},
"outputs": [],
"source": [
"df = pd.read_csv(file_url)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "qwSvQHzZhN2q"
},
"outputs": [],
"source": [
"obj_df = df.select_dtypes(include='object')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 187
},
"colab_type": "code",
"id": "vdBz2p9w6w4K",
"outputId": "d4769d6d-6956-4aa7-d026-472a54c9229c"
},
"outputs": [],
"source": [
"obj_cols = obj_df.columns\n",
"obj_cols"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "3yRUe0E7aJgk"
},
"outputs": [],
"source": [
"def describe_object(df, col_name):\n",
" print(f\"\\nCOLUMN: {col_name}\")\n",
" print(f\"{df[col_name].nunique()} different values\")\n",
" print(f\"List of values:\")\n",
" print(df[col_name].value_counts(dropna=False, normalize=True))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 187
},
"colab_type": "code",
"id": "QRLrQjc5bl5b",
"outputId": "0d9004f2-49b9-4934-b403-5539a8625a9e"
},
"outputs": [],
"source": [
"describe_object(df, 'MSZoning')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 1000
},
"colab_type": "code",
"id": "hv3qvtqZf-TL",
"outputId": "83c59b15-68b1-41c8-d590-08cbbf4529f2"
},
"outputs": [],
"source": [
"for col_name in obj_cols:\n",
" describe_object(df, col_name)"
]
}
],
"metadata": {
"colab": {
"collapsed_sections": [],
"name": "Exercise10_02.ipynb",
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.6"
}
},
"nbformat": 4,
"nbformat_minor": 1
}