You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
4241 lines
170 KiB
4241 lines
170 KiB
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "rQ8UhzFpgRra"
|
|
},
|
|
"source": [
|
|
"# ဒေတာပြင်ဆင်ခြင်း\n",
|
|
"\n",
|
|
"[မူရင်း Notebook အရင်းအမြစ် *Data Science: Introduction to Machine Learning for Data Science Python and Machine Learning Studio by Lee Stott*](https://github.com/leestott/intro-Datascience/blob/master/Course%20Materials/4-Cleaning_and_Manipulating-Reference.ipynb)\n",
|
|
"\n",
|
|
"## `DataFrame` အချက်အလက်များကို စူးစမ်းခြင်း\n",
|
|
"\n",
|
|
"> **သင်ယူရည်မှန်းချက်:** ဒီအခန်းငယ်ကို ပြီးဆုံးသွားတဲ့အခါမှာ pandas DataFrames ထဲမှာ သိမ်းဆည်းထားတဲ့ ဒေတာအကြောင်းကို အထွေထွေရှာဖွေတတ်ဖို့ သင်အဆင်ပြေဖြစ်နေပါလိမ့်မယ်။\n",
|
|
"\n",
|
|
"သင့်ဒေတာကို pandas ထဲသို့ load လုပ်ပြီးတာနဲ့, ဒါဟာ `DataFrame` အနေနဲ့ရှိနေမှာ မလွဲမသွေပါဘူး။ သို့သော်, သင့် `DataFrame` ထဲမှာ အတန်း 60,000 ရှိပြီး ကော်လံ 400 ရှိတဲ့ ဒေတာ set ရှိရင်, သင်ဘာတွေနဲ့လုပ်ဆောင်နေတယ်ဆိုတာကို ဘယ်လိုစတင်နားလည်ရမလဲ? ကံကောင်းစွာ, pandas က `DataFrame` အကြောင်းအရာကို အမြန်ကြည့်ရှုနိုင်ဖို့အတွက် အဆင်ပြေတဲ့ tools တွေကို ပေးထားပါတယ်၊ ဒါ့အပြင် ပထမအတန်းအချို့နဲ့ နောက်ဆုံးအတန်းအချို့ကိုလည်း ကြည့်ရှုနိုင်ပါတယ်။\n",
|
|
"\n",
|
|
"ဒီလုပ်ဆောင်ချက်ကို စူးစမ်းဖို့အတွက်, Python scikit-learn library ကို import လုပ်ပြီး ဒေတာသိပ္ပံပညာရှင်တိုင်းကြုံတွေ့ဖူးတဲ့ dataset တစ်ခုကို အသုံးပြုပါမယ်။ ဒါကတော့ 1936 ခုနှစ်မှာ ဗြိတိသျှဇီဝဗေဒပညာရှင် Ronald Fisher ရဲ့ *Iris* ဒေတာ set ဖြစ်ပြီး, သူ့ရဲ့စာတမ်း \"The use of multiple measurements in taxonomic problems\" မှာ အသုံးပြုခဲ့တာဖြစ်ပါတယ်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {
|
|
"collapsed": true,
|
|
"id": "hB1RofhdgRrp",
|
|
"trusted": false
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import pandas as pd\n",
|
|
"from sklearn.datasets import load_iris\n",
|
|
"\n",
|
|
"iris = load_iris()\n",
|
|
"iris_df = pd.DataFrame(data=iris['data'], columns=iris['feature_names'])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "AGA0A_Y8hMdz"
|
|
},
|
|
"source": [
|
|
"### `DataFrame.shape`\n",
|
|
"ကျွန်ုပ်တို့သည် Iris Dataset ကို `iris_df` အမည်ရှိ variable ထဲသို့ load လုပ်ထားပါသည်။ ဒေတာကို စတင်လေ့လာမည့်အခါ၊ ကျွန်ုပ်တို့တွင်ရှိသော datapoints အရေအတွက်နှင့် dataset ၏ စုစုပေါင်းအရွယ်အစားကို သိထားခြင်းသည် အရေးကြီးပါသည်။ ကျွန်ုပ်တို့ကိုယ်တိုင် handling လုပ်နေသော ဒေတာပမာဏကို ကြည့်ရှုခြင်းသည် အကျိုးရှိစေပါသည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
},
|
|
"id": "LOe5jQohhulf",
|
|
"outputId": "fb0577ac-3b4a-4623-cb41-20e1b264b3e9"
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"(150, 4)"
|
|
]
|
|
},
|
|
"execution_count": 2,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"iris_df.shape"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "smE7AGzOhxk2"
|
|
},
|
|
"source": [
|
|
"ဒါဆိုရင် ကျွန်တော်တို့ ၁၅၀ ရိုးနှင့် ၄ ကော်လံပါသော ဒေတာကို ကိုင်တွယ်နေရပါတယ်။ ရိုးတစ်ရိုးစီဟာ ဒေတာပွင့်တစ်ခုကို ကိုယ်စားပြုပြီး ကော်လံတစ်ခုစီဟာ ဒေတာဖရိမ်းနဲ့ဆက်စပ်နေတဲ့ အင်္ဂါရပ်တစ်ခုကို ကိုယ်စားပြုပါတယ်။ ဒါကြောင့် အခြေခံအားဖြင့် ၁၅၀ ဒေတာပွင့်ရှိပြီး တစ်ခုစီမှာ အင်္ဂါရပ် ၄ ခုပါဝင်ပါတယ်။\n",
|
|
"\n",
|
|
"`shape` ဟာ ဒီမှာ ဒေတာဖရိမ်းရဲ့ attribute ဖြစ်ပြီး function မဟုတ်ပါဘူး၊ ဒါကြောင့် parentheses တစ်စုံနဲ့ မဆုံးသွားတာပါ။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "d3AZKs0PinGP"
|
|
},
|
|
"source": [
|
|
"### `DataFrame.columns`\n",
|
|
"အခုတော့ ဒေတာရဲ့ ကော်လံ ၄ ခုဆီကို ရောက်ပါမယ်။ အဲဒီကော်လံတစ်ခုချင်းစီက တိတိကျကျ ဘာကို ကိုယ်စားပြုနေလဲဆိုတာကို ကြည့်ပါမယ်။ `columns` attribute က dataframe ထဲမှာရှိတဲ့ ကော်လံနာမည်တွေကို ပြပါလိမ့်မယ်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
},
|
|
"id": "YPGh_ziji-CY",
|
|
"outputId": "74e7a43a-77cc-4c80-da56-7f50767c37a0"
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"Index(['sepal length (cm)', 'sepal width (cm)', 'petal length (cm)',\n",
|
|
" 'petal width (cm)'],\n",
|
|
" dtype='object')"
|
|
]
|
|
},
|
|
"execution_count": 3,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"iris_df.columns"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "TsobcU_VjCC_"
|
|
},
|
|
"source": [
|
|
"ကျွန်တော်တို့မြင်နိုင်သည့်အတိုင်း၊ ကော်လံလေး(၄)ခုရှိပါတယ်။ `columns` attribute က ကော်လံများ၏နာမည်ကိုပြောပြပေးပြီး အခြားအချက်အလက်မပါဝင်ပါဘူး။ ဒီ attribute က dataset တစ်ခုမှာပါဝင်တဲ့ features တွေကိုဖော်ထုတ်ချင်တဲ့အခါမှာ အရေးပါလာပါတယ်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "2UTlvkjmgRrs"
|
|
},
|
|
"source": [
|
|
"### `DataFrame.info`\n",
|
|
"`shape` attribute ကပေးတဲ့ ဒေတာပမာဏနဲ့ `columns` attribute ကပေးတဲ့ feature တွေ၊ column အမည်တွေက dataset အကြောင်းအချို့ကို ပြောပြပေးပါတယ်။ အခုတော့ dataset ကို ပိုမိုနက်နက်ရှိုင်းရှိုင်း လေ့လာချင်ပါတယ်။ `DataFrame.info()` function က အရမ်းအသုံးဝင်ပါတယ်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
},
|
|
"id": "dHHRyG0_gRrt",
|
|
"outputId": "d8fb0c40-4f18-4e19-da48-c8db77d1d3a5",
|
|
"trusted": false
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"<class 'pandas.core.frame.DataFrame'>\n",
|
|
"RangeIndex: 150 entries, 0 to 149\n",
|
|
"Data columns (total 4 columns):\n",
|
|
" # Column Non-Null Count Dtype \n",
|
|
"--- ------ -------------- ----- \n",
|
|
" 0 sepal length (cm) 150 non-null float64\n",
|
|
" 1 sepal width (cm) 150 non-null float64\n",
|
|
" 2 petal length (cm) 150 non-null float64\n",
|
|
" 3 petal width (cm) 150 non-null float64\n",
|
|
"dtypes: float64(4)\n",
|
|
"memory usage: 4.8 KB\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"iris_df.info()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "1XgVMpvigRru"
|
|
},
|
|
"source": [
|
|
"ဒီနေရာကနေ အချို့အချက်အလက်တွေကို သတိပြုနိုင်ပါတယ်။\n",
|
|
"1. တစ်ခုချင်းကော်လံရဲ့ DataType: ဒီ dataset မှာ အချက်အလက်အားလုံးကို 64-bit floating-point နံပါတ်အနေနဲ့ သိမ်းဆည်းထားပါတယ်။\n",
|
|
"2. Non-Null အတန်းအရေအတွက်: Null values ကို ကိုင်တွယ်ဖို့က Data preparation အဆင့်မှာ အရေးကြီးတဲ့အဆင့်တစ်ခုဖြစ်ပါတယ်။ ဒါကို notebook ရဲ့ နောက်ပိုင်းမှာ ကိုင်တွယ်သွားမှာဖြစ်ပါတယ်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "IYlyxbpWFEF4"
|
|
},
|
|
"source": [
|
|
"### DataFrame.describe()\n",
|
|
"ကျွန်တော်တို့ dataset မှာ အရေအတွက်ဆိုင်ရာ ဒေတာများ များစွာရှိတယ်လို့ ဆိုပါစို့။ mean, median, quartiles စတဲ့ တစ်ခုချင်းစီ column တွေမှာ သီးသန့် အဆင့်တစ်ခုချင်းစီ ရှိတဲ့ စာရင်းဇယားဆိုင်ရာ တွက်ချက်မှုတွေကို ပြုလုပ်နိုင်ပါတယ်။ `DataFrame.describe()` function က dataset ရဲ့ အရေအတွက်ဆိုင်ရာ column တွေကို စာရင်းဇယားဆိုင်ရာ အကျဉ်းချုပ်ပေးပါတယ်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 5,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/",
|
|
"height": 297
|
|
},
|
|
"id": "tWV-CMstFIRA",
|
|
"outputId": "4fc49941-bc13-4b0c-a412-cb39e7d3f289"
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<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>sepal length (cm)</th>\n",
|
|
" <th>sepal width (cm)</th>\n",
|
|
" <th>petal length (cm)</th>\n",
|
|
" <th>petal width (cm)</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>count</th>\n",
|
|
" <td>150.000000</td>\n",
|
|
" <td>150.000000</td>\n",
|
|
" <td>150.000000</td>\n",
|
|
" <td>150.000000</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>mean</th>\n",
|
|
" <td>5.843333</td>\n",
|
|
" <td>3.057333</td>\n",
|
|
" <td>3.758000</td>\n",
|
|
" <td>1.199333</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>std</th>\n",
|
|
" <td>0.828066</td>\n",
|
|
" <td>0.435866</td>\n",
|
|
" <td>1.765298</td>\n",
|
|
" <td>0.762238</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>min</th>\n",
|
|
" <td>4.300000</td>\n",
|
|
" <td>2.000000</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" <td>0.100000</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>25%</th>\n",
|
|
" <td>5.100000</td>\n",
|
|
" <td>2.800000</td>\n",
|
|
" <td>1.600000</td>\n",
|
|
" <td>0.300000</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>50%</th>\n",
|
|
" <td>5.800000</td>\n",
|
|
" <td>3.000000</td>\n",
|
|
" <td>4.350000</td>\n",
|
|
" <td>1.300000</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>75%</th>\n",
|
|
" <td>6.400000</td>\n",
|
|
" <td>3.300000</td>\n",
|
|
" <td>5.100000</td>\n",
|
|
" <td>1.800000</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>max</th>\n",
|
|
" <td>7.900000</td>\n",
|
|
" <td>4.400000</td>\n",
|
|
" <td>6.900000</td>\n",
|
|
" <td>2.500000</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" sepal length (cm) sepal width (cm) petal length (cm) petal width (cm)\n",
|
|
"count 150.000000 150.000000 150.000000 150.000000\n",
|
|
"mean 5.843333 3.057333 3.758000 1.199333\n",
|
|
"std 0.828066 0.435866 1.765298 0.762238\n",
|
|
"min 4.300000 2.000000 1.000000 0.100000\n",
|
|
"25% 5.100000 2.800000 1.600000 0.300000\n",
|
|
"50% 5.800000 3.000000 4.350000 1.300000\n",
|
|
"75% 6.400000 3.300000 5.100000 1.800000\n",
|
|
"max 7.900000 4.400000 6.900000 2.500000"
|
|
]
|
|
},
|
|
"execution_count": 5,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"iris_df.describe()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "zjjtW5hPGMuM"
|
|
},
|
|
"source": [
|
|
"အထက်တွင် ဖော်ပြထားသော အထွက်သည် ကော်လံတစ်ခုချင်းစီ၏ ဒေတာအချက်အလက်စုစုပေါင်းအရေအတွက်၊ ပျမ်းမျှတန်ဖိုး၊ စံအလျားချုပ်၊ အနည်းဆုံးတန်ဖိုး၊ အောက်ပိုင်းတစ်စိတ် ၄ ပုံ ၁ (25%)၊ အလယ်တန်းတန်ဖိုး (50%)၊ အပေါ်ပိုင်းတစ်စိတ် ၄ ပုံ ၃ (75%) နှင့် အများဆုံးတန်ဖိုးတို့ကို ဖော်ပြထားသည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "-lviAu99gRrv"
|
|
},
|
|
"source": [
|
|
"### `DataFrame.head`\n",
|
|
"အထက်ပါ function တွေ၊ attribute တွေကို အသုံးပြုပြီးနောက်မှာ dataset ရဲ့ အထက်လွှာအမြင်ကို ရရှိခဲ့ပါပြီ။ အဲဒီ dataset မှာ data point အရေအတွက်ဘယ်လောက်ရှိသလဲ၊ feature အရေအတွက်ဘယ်လောက်ရှိသလဲ၊ feature တစ်ခုချင်းစီရဲ့ data type ဘယ်လိုလဲ၊ feature တစ်ခုချင်းစီမှာ non-null value အရေအတွက်ဘယ်လောက်ရှိသလဲဆိုတာကို သိရှိခဲ့ပါပြီ။\n",
|
|
"\n",
|
|
"အခုတော့ data ကို ကိုယ်တိုင်ကြည့်ဖို့အချိန်ရောက်ပါပြီ။ `DataFrame` ရဲ့ ပထမဆုံးအတန်းတွေ (ပထမဆုံး data point တွေ) ဘယ်လိုပုံစံရှိလဲဆိုတာ ကြည့်လိုက်ရအောင်:\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 6,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/",
|
|
"height": 204
|
|
},
|
|
"id": "DZMJZh0OgRrw",
|
|
"outputId": "d9393ee5-c106-4797-f815-218f17160e00",
|
|
"trusted": false
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<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>sepal length (cm)</th>\n",
|
|
" <th>sepal width (cm)</th>\n",
|
|
" <th>petal length (cm)</th>\n",
|
|
" <th>petal width (cm)</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>0</th>\n",
|
|
" <td>5.1</td>\n",
|
|
" <td>3.5</td>\n",
|
|
" <td>1.4</td>\n",
|
|
" <td>0.2</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>4.9</td>\n",
|
|
" <td>3.0</td>\n",
|
|
" <td>1.4</td>\n",
|
|
" <td>0.2</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>2</th>\n",
|
|
" <td>4.7</td>\n",
|
|
" <td>3.2</td>\n",
|
|
" <td>1.3</td>\n",
|
|
" <td>0.2</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>3</th>\n",
|
|
" <td>4.6</td>\n",
|
|
" <td>3.1</td>\n",
|
|
" <td>1.5</td>\n",
|
|
" <td>0.2</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>4</th>\n",
|
|
" <td>5.0</td>\n",
|
|
" <td>3.6</td>\n",
|
|
" <td>1.4</td>\n",
|
|
" <td>0.2</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" sepal length (cm) sepal width (cm) petal length (cm) petal width (cm)\n",
|
|
"0 5.1 3.5 1.4 0.2\n",
|
|
"1 4.9 3.0 1.4 0.2\n",
|
|
"2 4.7 3.2 1.3 0.2\n",
|
|
"3 4.6 3.1 1.5 0.2\n",
|
|
"4 5.0 3.6 1.4 0.2"
|
|
]
|
|
},
|
|
"execution_count": 6,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"iris_df.head()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "EBHEimZuEFQK"
|
|
},
|
|
"source": [
|
|
"ဒီအထွက်မှာ၊ ဒေတာစနစ်ရဲ့ အချက်အလက်ငါး(၅) ခုကို မြင်နိုင်ပါတယ်။ ဘယ်ဘက်မှာရှိတဲ့ အညွှန်းကိုကြည့်မယ်ဆိုရင်၊ ဒါတွေဟာ ပထမ ငါးတန်းအတန်းတွေဖြစ်တယ်ဆိုတာ သိနိုင်ပါတယ်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "oj7GkrTdgRry"
|
|
},
|
|
"source": [
|
|
"### လေ့ကျင့်ခန်း:\n",
|
|
"\n",
|
|
"အထက်မှာပေးထားတဲ့ ဥပမာအရ `DataFrame.head` က `DataFrame` ရဲ့ ပထမဆုံးအတန်း ၅ ခုကို ပုံမှန်အတိုင်း ပြန်ပေးတယ်ဆိုတာ သိရပါတယ်။ အောက်မှာရှိတဲ့ code cell မှာ အတန်း ၅ ခုထက်ပိုပြီး ပြသနိုင်တဲ့ နည်းလမ်းကို ရှာဖွေနိုင်မလား?\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 7,
|
|
"metadata": {
|
|
"collapsed": true,
|
|
"id": "EKRmRFFegRrz",
|
|
"trusted": false
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Hint: Consult the documentation by using iris_df.head?"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "BJ_cpZqNgRr1"
|
|
},
|
|
"source": [
|
|
"### `DataFrame.tail`\n",
|
|
"ဒေတာကိုကြည့်ရှုခြင်းအခြားနည်းလမ်းတစ်ခုမှာ အစမဟုတ်ဘဲ အဆုံးမှစပြီးကြည့်ရှုခြင်းဖြစ်နိုင်ပါတယ်။ `DataFrame.head` ရဲ့ အတိမ်းအနောက်မှာ `DataFrame.tail` ရှိပြီး၊ ဒါဟာ `DataFrame` ရဲ့ နောက်ဆုံးအတန်း ၅ ခုကို ပြန်ပေးပါသည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 8,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/",
|
|
"height": 0
|
|
},
|
|
"id": "heanjfGWgRr2",
|
|
"outputId": "6ae09a21-fe09-4110-b0d7-1a1fbf34d7f3",
|
|
"trusted": false
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<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>sepal length (cm)</th>\n",
|
|
" <th>sepal width (cm)</th>\n",
|
|
" <th>petal length (cm)</th>\n",
|
|
" <th>petal width (cm)</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>145</th>\n",
|
|
" <td>6.7</td>\n",
|
|
" <td>3.0</td>\n",
|
|
" <td>5.2</td>\n",
|
|
" <td>2.3</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>146</th>\n",
|
|
" <td>6.3</td>\n",
|
|
" <td>2.5</td>\n",
|
|
" <td>5.0</td>\n",
|
|
" <td>1.9</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>147</th>\n",
|
|
" <td>6.5</td>\n",
|
|
" <td>3.0</td>\n",
|
|
" <td>5.2</td>\n",
|
|
" <td>2.0</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>148</th>\n",
|
|
" <td>6.2</td>\n",
|
|
" <td>3.4</td>\n",
|
|
" <td>5.4</td>\n",
|
|
" <td>2.3</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>149</th>\n",
|
|
" <td>5.9</td>\n",
|
|
" <td>3.0</td>\n",
|
|
" <td>5.1</td>\n",
|
|
" <td>1.8</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" sepal length (cm) sepal width (cm) petal length (cm) petal width (cm)\n",
|
|
"145 6.7 3.0 5.2 2.3\n",
|
|
"146 6.3 2.5 5.0 1.9\n",
|
|
"147 6.5 3.0 5.2 2.0\n",
|
|
"148 6.2 3.4 5.4 2.3\n",
|
|
"149 5.9 3.0 5.1 1.8"
|
|
]
|
|
},
|
|
"execution_count": 8,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"iris_df.tail()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "31kBWfyLgRr3"
|
|
},
|
|
"source": [
|
|
"အလေ့အကျင့်အရ၊ အစီအစဉ်တကျထားရှိသော ဒေတာများတွင် အထူးသဖြင့် အထူးအချက်အလက်များကို ရှာဖွေနေစဉ် `DataFrame` ၏ အစပိုင်းအတန်းများ သို့မဟုတ် အဆုံးပိုင်းအတန်းများကို လွယ်ကူစွာ ကြည့်ရှုနိုင်ခြင်းသည် အကျိုးရှိစေပါသည်။\n",
|
|
"\n",
|
|
"ကုဒ်နမူနာများ၏ အကူအညီဖြင့် ပြသထားသော အထက်ပါ လုပ်ဆောင်ချက်များနှင့် အင်္ဂါရပ်များသည် ဒေတာ၏ ပုံစံနှင့် ခံစားမှုကို ရရှိစေပါသည်။\n",
|
|
"\n",
|
|
"> **အရေးကြီးသောအချက်:** `DataFrame` တစ်ခု၏ အချက်အလက်များနှင့် ပတ်သက်သော metadata သို့မဟုတ် အစပိုင်းနှင့် အဆုံးပိုင်းတန်ဖိုးများကို ကြည့်ရှုခြင်းဖြင့် သင်လုပ်ဆောင်နေသော ဒေတာ၏ အရွယ်အစား၊ ပုံစံနှင့် အကြောင်းအရာကို ချက်ချင်းနားလည်နိုင်စေပါသည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "TvurZyLSDxq_"
|
|
},
|
|
"source": [
|
|
"### မရှိသော ဒေတာ\n",
|
|
"မရှိသော ဒေတာအကြောင်းကို ဆွေးနွေးကြမယ်။ ဒေတာမရှိတာဆိုတာ အချို့ကော်လံတွေမှာ တန်ဖိုးမရှိတဲ့အခါ ဖြစ်ပေါ်လာတာပါ။\n",
|
|
"\n",
|
|
"ဥပမာတစ်ခုကို ယူကြည့်ရအောင်။ တစ်ဦးတစ်ယောက်ဟာ သူ့ရဲ့အလေးချိန်ကို အလွန်ဂရုစိုက်ပြီး စစ်တမ်းမှာ အလေးချိန်ကွက်လပ်ကို မဖြည့်ဘူးဆိုပါစို့။ ဒီလိုဆိုရင် အဲ့ဒီလူရဲ့ အလေးချိန်တန်ဖိုးက မရှိတော့ပါဘူး။\n",
|
|
"\n",
|
|
"အများအားဖြင့် အမှန်တကယ်ကမ္ဘာ့ဒေတာအစုအဝေးတွေမှာ တန်ဖိုးမရှိတာတွေ ဖြစ်ပေါ်လေ့ရှိပါတယ်။\n",
|
|
"\n",
|
|
"**Pandas က မရှိသော ဒေတာကို ဘယ်လိုကိုင်တွယ်သလဲ**\n",
|
|
"\n",
|
|
"Pandas က မရှိသော တန်ဖိုးတွေကို နှစ်မျိုးနည်းနဲ့ ကိုင်တွယ်ပါတယ်။ ပထမနည်းကတော့ အရင်ပိုင်းက အပိုင်းတွေမှာ တွေ့ဖူးတဲ့ `NaN` (Not a Number) ပါ။ ဒါဟာ IEEE floating-point specification ရဲ့ အထူးတန်ဖိုးတစ်ခုဖြစ်ပြီး floating-point တန်ဖိုးမရှိတဲ့အခါကို ဖော်ပြဖို့ သီးသန့်အသုံးပြုပါတယ်။\n",
|
|
"\n",
|
|
"Floating-point တန်ဖိုးတွေမရှိတဲ့အခြေအနေအပြင် အခြားတန်ဖိုးမရှိတဲ့အခါမှာတော့ pandas က Python ရဲ့ `None` object ကို အသုံးပြုပါတယ်။ `None` နဲ့ `NaN` ဟာ အဓိပ္ပါယ်တူတူပေမယ့် နှစ်မျိုးနည်းနဲ့ ကိုင်တွယ်ရတာဟာ အစီအစဉ်ရေးသားမှုအရ အကြောင်းပြချက်ရှိပြီး၊ အများဆုံးအခြေအနေတွေမှာ pandas က အကောင်းဆုံးဖြေရှင်းနည်းကို ပေးနိုင်ဖို့ ဒီနည်းလမ်းကို သုံးတာပါ။ ဒါပေမယ့် `None` နဲ့ `NaN` နှစ်ခုလုံးမှာ သတ်မှတ်ချက်တွေရှိပြီး၊ အဲ့ဒီအရာတွေကို ဘယ်လိုအသုံးပြုရမလဲဆိုတာ သတိထားဖို့ လိုအပ်ပါတယ်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "lOHqUlZFgRr5"
|
|
},
|
|
"source": [
|
|
"### `None`: non-float missing data\n",
|
|
"`None` သည် Python မှလာသောကြောင့် `'object'` data type မဟုတ်သော NumPy နှင့် pandas arrays တွင် အသုံးမပြုနိုင်ပါ။ NumPy arrays (နှင့် pandas တွင်ပါဝင်သော data structures) သည် data အမျိုးအစားတစ်မျိုးသာ ပါဝင်နိုင်သည်ကို မှတ်ထားပါ။ ၎င်းသည် အကြီးစား data နှင့် တွက်ချက်မှုလုပ်ငန်းများအတွက် အလွန်အစွမ်းထက်သောစွမ်းရည်ကို ပေးစွမ်းနိုင်သော်လည်း, flexibility ကို ကန့်သတ်ထားသည်။ ထို arrays များသည် array အတွင်းရှိ အရာအားလုံးကို အကျုံးဝင်စေမည့် “lowest common denominator” data type သို့ အလိုအလျောက်ပြောင်းလဲရမည်ဖြစ်သည်။ `None` သည် array အတွင်းရှိနေသည်ဆိုပါက, သင်သည် Python objects များနှင့်အလုပ်လုပ်နေသည်ကို ဆိုလိုသည်။\n",
|
|
"\n",
|
|
"ဤအရာကို လက်တွေ့ကြည့်ရှုရန်, အောက်ပါ ဥပမာ array ကို စဉ်းစားပါ (၎င်း၏ `dtype` ကို သတိပြုပါ):\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 9,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
},
|
|
"id": "QIoNdY4ngRr7",
|
|
"outputId": "92779f18-62f4-4a03-eca2-e9a101604336",
|
|
"trusted": false
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"array([2, None, 6, 8], dtype=object)"
|
|
]
|
|
},
|
|
"execution_count": 9,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"import numpy as np\n",
|
|
"\n",
|
|
"example1 = np.array([2, None, 6, 8])\n",
|
|
"example1"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "pdlgPNbhgRr7"
|
|
},
|
|
"source": [
|
|
"အမြင့်တင်ထားသော ဒေတာအမျိုးအစားများ၏ အမှန်တရားသည် အကျိုးသက်ရောက်မှုနှစ်ခုကို လိုက်ပါလာသည်။ ပထမတစ်ခုမှာ လုပ်ဆောင်မှုများကို NumPy ကုဒ်ကို စုစည်းထားသောအဆင့်မဟုတ်ဘဲ Python ကုဒ်ကို အဓိကထားသောအဆင့်တွင် ဆောင်ရွက်မည်ဖြစ်သည်။ အဓိကအားဖြင့် ဒါက `Series` သို့မဟုတ် `DataFrames` တွင် `None` ပါဝင်သော လုပ်ဆောင်မှုများသည် ပိုနှေးကွေးမည်ဖြစ်သည်ဟု ဆိုလိုသည်။ သင်သည် ဒီစွမ်းဆောင်ရည်ကျဆင်းမှုကို မသိသာနိုင်လောက်ပေမယ့်၊ ဒေတာအစုအဝေးများအတွက်တော့ ဒါဟာ ပြဿနာတစ်ခုဖြစ်လာနိုင်သည်။\n",
|
|
"\n",
|
|
"ဒုတိယအကျိုးသက်ရောက်မှုသည် ပထမအကျိုးသက်ရောက်မှုမှ ဆင်းသက်လာသည်။ `None` သည် `Series` သို့မဟုတ် `DataFrame`s ကို သာမန် Python ကမ္ဘာသို့ ပြန်ဆွဲခေါ်သည့်အတွက်၊ `sum()` သို့မဟုတ် `min()` ကဲ့သို့သော NumPy/pandas အစုချုပ်မှုများကို `None` တန်ဖိုးပါဝင်သော array များပေါ်တွင် အသုံးပြုပါက အများအားဖြင့် အမှားတစ်ခုကို ဖြစ်ပေါ်စေမည်ဖြစ်သည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 10,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/",
|
|
"height": 292
|
|
},
|
|
"id": "gWbx-KB9gRr8",
|
|
"outputId": "ecba710a-22ec-41d5-a39c-11f67e645b50",
|
|
"trusted": false
|
|
},
|
|
"outputs": [
|
|
{
|
|
"ename": "TypeError",
|
|
"evalue": "ignored",
|
|
"output_type": "error",
|
|
"traceback": [
|
|
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
|
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
|
|
"\u001b[0;32m<ipython-input-10-ce9901ad18bd>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mexample1\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msum\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
|
|
"\u001b[0;32m/usr/local/lib/python3.7/dist-packages/numpy/core/_methods.py\u001b[0m in \u001b[0;36m_sum\u001b[0;34m(a, axis, dtype, out, keepdims, initial, where)\u001b[0m\n\u001b[1;32m 45\u001b[0m def _sum(a, axis=None, dtype=None, out=None, keepdims=False,\n\u001b[1;32m 46\u001b[0m initial=_NoValue, where=True):\n\u001b[0;32m---> 47\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mumr_sum\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mout\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkeepdims\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minitial\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mwhere\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 48\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 49\u001b[0m def _prod(a, axis=None, dtype=None, out=None, keepdims=False,\n",
|
|
"\u001b[0;31mTypeError\u001b[0m: unsupported operand type(s) for +: 'int' and 'NoneType'"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"example1.sum()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "LcEwO8UogRr9"
|
|
},
|
|
"source": [
|
|
"**အဓိကအချက်**: အင်တဂါများနှင့် `None` အတန်ဖိုးများအကြား တွက်ချက်မှု (နှင့်အခြားလုပ်ဆောင်မှုများ) သတ်မှတ်ထားခြင်းမရှိပါ၊ ဒါကြောင့် ၎င်းတို့ပါဝင်သော ဒေတာစုများနှင့်လုပ်ဆောင်နိုင်သည့်အရာများကို ကန့်သတ်နိုင်ပါသည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "pWvVHvETgRr9"
|
|
},
|
|
"source": [
|
|
"### `NaN`: မရှိသော float တန်ဖိုးများ\n",
|
|
"\n",
|
|
"`None` နှင့်မတူဘဲ NumPy (အထူးသဖြင့် pandas) သည် `NaN` ကို ၎င်း၏ အမြန်နှုန်းမြင့်သော vectorized လုပ်ဆောင်မှုများနှင့် ufuncs များအတွက် ပံ့ပိုးပေးသည်။ သို့သော် မကောင်းသောအချက်မှာ `NaN` ပေါ်တွင် အရေအတွက်ဆိုင်ရာ လုပ်ဆောင်မှုများကို ပြုလုပ်သည့်အခါ အမြဲတမ်း `NaN` ဖြစ်သွားမည်ဖြစ်သည်။ ဥပမာ:\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 11,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
},
|
|
"id": "rcFYfMG9gRr9",
|
|
"outputId": "699e81b7-5c11-4b46-df1d-06071768690f",
|
|
"trusted": false
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"nan"
|
|
]
|
|
},
|
|
"execution_count": 11,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"np.nan + 1"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 12,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
},
|
|
"id": "BW3zQD2-gRr-",
|
|
"outputId": "4525b6c4-495d-4f7b-a979-efce1dae9bd0",
|
|
"trusted": false
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"nan"
|
|
]
|
|
},
|
|
"execution_count": 12,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"np.nan * 0"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "fU5IPRcCgRr-"
|
|
},
|
|
"source": [
|
|
"အကြောင်းကောင်းတစ်ခုကတော့ `NaN` ပါဝင်တဲ့ array တွေမှာ aggregation တွေ run လုပ်တဲ့အခါ error မပေါက်ပါဘူး။ အကြောင်းမကောင်းတစ်ခုကတော့ ရလဒ်တွေဟာ အတူတူအသုံးဝင်တဲ့အရာမဟုတ်ပါဘူး။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 13,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
},
|
|
"id": "LCInVgSSgRr_",
|
|
"outputId": "fa06495a-0930-4867-87c5-6023031ea8b5",
|
|
"trusted": false
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"(nan, nan, nan)"
|
|
]
|
|
},
|
|
"execution_count": 13,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"example2 = np.array([2, np.nan, 6, 8]) \n",
|
|
"example2.sum(), example2.min(), example2.max()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "nhlnNJT7gRr_"
|
|
},
|
|
"source": [
|
|
"### လေ့ကျင့်မှု:\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 11,
|
|
"metadata": {
|
|
"collapsed": true,
|
|
"id": "yan3QRaOgRr_",
|
|
"trusted": false
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# What happens if you add np.nan and None together?\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "_iDvIRC8gRsA"
|
|
},
|
|
"source": [
|
|
"မှတ်ထားပါ။ `NaN` သည် မရှိသော floating-point အတန်းများအတွက်သာ ဖြစ်ပြီး၊ integers, strings, သို့မဟုတ် Booleans အတွက် `NaN` နှင့် ညီမျှသော အရာမရှိပါ။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "kj6EKdsAgRsA"
|
|
},
|
|
"source": [
|
|
"### `NaN` နှင့် `None`: pandas တွင် null အတန်တန်များ\n",
|
|
"\n",
|
|
"`NaN` နှင့် `None` တို့သည် အချို့အခါ အပြုအမူကွဲပြားနိုင်သော်လည်း pandas သည် အတူတူအသုံးပြုနိုင်ရန် ဖန်တီးထားသည်။ ဥပမာအားဖြင့် အောက်ပါ `Series` အတွက် ကြည့်ပါ:\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 15,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
},
|
|
"id": "Nji-KGdNgRsA",
|
|
"outputId": "36aa14d2-8efa-4bfd-c0ed-682991288822",
|
|
"trusted": false
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"0 1\n",
|
|
"1 2\n",
|
|
"2 3\n",
|
|
"dtype: int64"
|
|
]
|
|
},
|
|
"execution_count": 15,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"int_series = pd.Series([1, 2, 3], dtype=int)\n",
|
|
"int_series"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "WklCzqb8gRsB"
|
|
},
|
|
"source": [
|
|
"### လေ့ကျင့်မှု:\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 16,
|
|
"metadata": {
|
|
"collapsed": true,
|
|
"id": "Cy-gqX5-gRsB",
|
|
"trusted": false
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Now set an element of int_series equal to None.\n",
|
|
"# How does that element show up in the Series?\n",
|
|
"# What is the dtype of the Series?\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "WjMQwltNgRsB"
|
|
},
|
|
"source": [
|
|
"`Series` နှင့် `DataFrame` များတွင် ဒေတာအမျိုးအစားများကို တူညီမှုရှိစေရန်အတွက် အမျိုးအစားမြှင့်တင်ခြင်းလုပ်ငန်းစဉ်တွင် pandas သည် `None` နှင့် `NaN` အကြား ပျောက်ဆုံးနေသောတန်ဖိုးများကို အလွယ်တကူ ပြောင်းလဲပေးပါသည်။ ဒီဒီဇိုင်းအင်္ဂါရပ်ကြောင့် pandas တွင် `None` နှင့် `NaN` ကို \"null\" အမျိုးအစားနှစ်မျိုးအဖြစ် စဉ်းစားရတာ အကျိုးရှိနိုင်ပါတယ်။ အမှန်တကယ်တော့ pandas တွင် ပျောက်ဆုံးနေသောတန်ဖိုးများကို ကိုင်တွယ်ရန် သုံးသော အခြေခံနည်းလမ်းများသည် ဒီအယူအဆကို သူတို့နာမည်များတွင် ထင်ဟပ်စေပါသည်။\n",
|
|
"\n",
|
|
"- `isnull()`: ပျောက်ဆုံးနေသောတန်ဖိုးများကို ဖော်ပြသော Boolean mask တစ်ခုကို ဖန်တီးသည်\n",
|
|
"- `notnull()`: `isnull()` ၏ ဆန့်ကျင်ဘက်\n",
|
|
"- `dropna()`: ဒေတာကို စစ်ထုတ်ထားသော ဗားရှင်းတစ်ခု ပြန်ပေးသည်\n",
|
|
"- `fillna()`: ပျောက်ဆုံးနေသောတန်ဖိုးများကို ဖြည့်စွက်ထားသော ဒေတာ၏ မိတ္တူတစ်ခု ပြန်ပေးသည်\n",
|
|
"\n",
|
|
"ဒီနည်းလမ်းများသည် အရေးကြီးပြီး ကျွမ်းကျင်စွာ အသုံးပြုနိုင်ရန် လေ့လာသင့်သော နည်းလမ်းများဖြစ်သည်။ အခုတော့ တစ်ခုချင်းစီကို အသေးစိတ် သွားလေ့လာကြမယ်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "Yh5ifd9FgRsB"
|
|
},
|
|
"source": [
|
|
"### Null တန်ဖိုးများကို ရှာဖွေခြင်း\n",
|
|
"\n",
|
|
"အခု Missing Values ရဲ့ အရေးကြီးမှုကို နားလည်ပြီးတဲ့အခါမှာ Missing Values တွေကို ကိုင်တွယ်ဖို့မတိုင်ခင် Dataset ထဲမှာ ရှာဖွေဖို့လိုအပ်ပါတယ်။\n",
|
|
"`isnull()` နဲ့ `notnull()` နှစ်ခုလုံးဟာ Null Data ကို ရှာဖွေဖို့အတွက် အဓိက Method တွေဖြစ်ပါတယ်။ Method နှစ်ခုလုံးဟာ သင့် Data အပေါ် Boolean Mask တွေကို ပြန်ပေးပါမယ်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 17,
|
|
"metadata": {
|
|
"collapsed": true,
|
|
"id": "e-vFp5lvgRsC",
|
|
"trusted": false
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"example3 = pd.Series([0, np.nan, '', None])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 18,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
},
|
|
"id": "1XdaJJ7PgRsC",
|
|
"outputId": "92fc363a-1874-471f-846d-f4f9ce1f51d0",
|
|
"trusted": false
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"0 False\n",
|
|
"1 True\n",
|
|
"2 False\n",
|
|
"3 True\n",
|
|
"dtype: bool"
|
|
]
|
|
},
|
|
"execution_count": 18,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"example3.isnull()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "PaSZ0SQygRsC"
|
|
},
|
|
"source": [
|
|
"အထွေထွေကြည့်လိုက်ပါ။ အဲဒီအထဲမှာ အံ့ဩစရာတစ်ခုခုရှိပါသလား။ `0` ဟာ သင်္ချာအရ null ဖြစ်ပေမယ့်၊ ဒါဟာ ကောင်းမွန်တဲ့ integer တစ်ခုဖြစ်ပြီး pandas က အဲဒီအတိုင်းကို လက်ခံပါတယ်။ `''` ကတော့ နည်းနည်းပိုမရှင်းလင်းပါ။ ဒါကို Section 1 မှာ အလွတ် string တန်ဖိုးကို ကိုယ်စားပြုဖို့ အသုံးပြုခဲ့ပေမယ့်၊ pandas အရတော့ ဒါဟာ null ကို ကိုယ်စားပြုတာမဟုတ်ဘဲ string object တစ်ခုဖြစ်ပါတယ်။\n",
|
|
"\n",
|
|
"အခုတော့ ဒီအရာတွေကို ပြန်လှည့်ပြီး သင်အမှန်တကယ် အသုံးပြုမယ့်ပုံစံနဲ့ ပိုဆင်တူတဲ့နည်းလမ်းတွေကို အသုံးပြုကြည့်ရအောင်။ Boolean masks ကို တိုက်ရိုက် ``Series`` ဒါမှမဟုတ် ``DataFrame`` index အနေနဲ့ အသုံးပြုနိုင်ပြီး၊ အဲဒါက အလွတ် (ဒါမှမဟုတ် ရှိနေတဲ့) တန်ဖိုးတွေကို သီးသန့်လုပ်ဆောင်ဖို့ အသုံးဝင်ပါတယ်။\n",
|
|
"\n",
|
|
"မရှိတဲ့တန်ဖိုးတွေ စုစုပေါင်းကို သိချင်ရင် `isnull()` method က ထုတ်ပေးတဲ့ mask ကို အပေါ်မှာ sum လုပ်လိုက်ရုံနဲ့ ရနိုင်ပါတယ်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 19,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
},
|
|
"id": "JCcQVoPkHDUv",
|
|
"outputId": "001daa72-54f8-4bd5-842a-4df627a79d4d"
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"2"
|
|
]
|
|
},
|
|
"execution_count": 19,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"example3.isnull().sum()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "PlBqEo3mgRsC"
|
|
},
|
|
"source": [
|
|
"### လေ့ကျင့်မှု:\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 20,
|
|
"metadata": {
|
|
"collapsed": true,
|
|
"id": "ggDVf5uygRsD",
|
|
"trusted": false
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Try running example3[example3.notnull()].\n",
|
|
"# Before you do so, what do you expect to see?\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "D_jWN7mHgRsD"
|
|
},
|
|
"source": [
|
|
"**အဓိကအချက်**: `isnull()` နှင့် `notnull()` နည်းလမ်းများကို DataFrames တွင် အသုံးပြုသောအခါ၊ ၎င်းတို့သည် ရလဒ်များနှင့် ၎င်းရလဒ်များ၏ အညွှန်းကို ပြသပေးပါသည်။ ၎င်းသည် သင့်ဒေတာနှင့် အလုပ်လုပ်နေစဉ်တွင် အလွန်အကျိုးရှိစေပါမည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "BvnoojWsgRr4"
|
|
},
|
|
"source": [
|
|
"### မရှိသောဒေတာကို ကိုင်တွယ်ခြင်း\n",
|
|
"\n",
|
|
"> **သင်ယူရန်ရည်မှန်းချက်:** ဒီအပိုင်းလေးအဆုံးသတ်ချိန်မှာ DataFrames ထဲက null values တွေကို ဘယ်အချိန်မှာ ဘယ်လိုအစားထိုးမလဲ၊ ဖယ်ရှားမလဲဆိုတာကို သိရှိနားလည်နိုင်ပါမည်။\n",
|
|
"\n",
|
|
"Machine Learning မော်ဒယ်တွေဟာ မရှိတဲ့ဒေတာတွေကို ကိုယ်တိုင်ကိုင်တွယ်နိုင်တာမဟုတ်ပါဘူး။ ဒါကြောင့် မော်ဒယ်ထဲကို ဒေတာတွေကို ထည့်မယ့်အခါမှာ ဒီမရှိတဲ့တန်ဖိုးတွေကို ကိုင်တွယ်ဖို့လိုအပ်ပါတယ်။\n",
|
|
"\n",
|
|
"မရှိတဲ့ဒေတာကို ကိုင်တွယ်ပုံဟာ သေးငယ်တဲ့ အကျိုးဆက်တွေကိုပါ ပါဝင်စေပြီး၊ သင့်ရဲ့ analysis နောက်ဆုံးရလဒ်နဲ့ အမှန်တကယ်ဖြစ်ပျက်မယ့်အခြေအနေတွေကိုလည်း သက်ရောက်စေပါတယ်။\n",
|
|
"\n",
|
|
"မရှိတဲ့ဒေတာကို ကိုင်တွယ်ဖို့နည်းလမ်းတွေမှာ အဓိကအားဖြင့် နှစ်မျိုးရှိပါတယ် -\n",
|
|
"\n",
|
|
"1. မရှိတဲ့တန်ဖိုးပါဝင်တဲ့ row ကို ဖျက်ပစ်ခြင်း\n",
|
|
"2. မရှိတဲ့တန်ဖိုးကို တခြားတန်ဖိုးတစ်ခုနဲ့ အစားထိုးခြင်း\n",
|
|
"\n",
|
|
"ဒီနည်းလမ်းနှစ်ခုကို အကျိုးကျိုးနဲ့ အနုတ်ကျိုးတွေကို အသေးစိတ်ဆွေးနွေးသွားပါမယ်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "3VaYC1TvgRsD"
|
|
},
|
|
"source": [
|
|
"### Null အချက်အလက်များကို ဖယ်ရှားခြင်း\n",
|
|
"\n",
|
|
"ကျွန်ုပ်တို့၏မော်ဒယ်သို့ ပေးပို့သောအချက်အလက်ပမာဏသည် ၎င်း၏စွမ်းဆောင်ရည်ကို တိုက်ရိုက်သက်ရောက်စေပါသည်။ Null အချက်အလက်များကို ဖယ်ရှားခြင်းသည် အချက်အလက်အချက်ပြများ၏အရေအတွက်ကို လျှော့ချခြင်းဖြစ်ပြီး၊ dataset ၏အရွယ်အစားကိုလည်း လျှော့ချခြင်းဖြစ်သည်။ ထို့ကြောင့် dataset ကြီးမားလွန်းသောအခါတွင် Null အချက်အလက်များပါဝင်သော အတန်းများကို ဖယ်ရှားရန် အကြံပြုပါသည်။\n",
|
|
"\n",
|
|
"တစ်ခြားအခြေအနေတစ်ခုမှာ အတန်းတစ်ခု သို့မဟုတ် ကော်လံတစ်ခုတွင် အချက်အလက်ပျောက်ဆုံးမှုများစွာရှိနေသည်။ ထိုအခါ၎င်းတို့ကို ဖယ်ရှားနိုင်ပါသည်၊ အကြောင်းကတော့ အတန်း/ကော်လံအတွက် အချက်အလက်များအများစုပျောက်ဆုံးနေသောကြောင့် ကျွန်ုပ်တို့၏ခွဲခြမ်းစိတ်ဖြာမှုတွင် တန်ဖိုးများမပေးနိုင်ပါ။\n",
|
|
"\n",
|
|
"Missing values ကို ရှာဖွေခြင်းအပြင် pandas သည် `Series` နှင့် `DataFrame` များမှ Null အချက်အလက်များကို ဖယ်ရှားရန် အဆင်ပြေသောနည်းလမ်းကို ပေးသည်။ ၎င်းကို လက်တွေ့အသုံးပြုမှုအနေဖြင့် `example3` သို့ ပြန်သွားကြည့်ပါ။ `DataFrame.dropna()` function သည် Null အချက်အလက်များပါဝင်သော အတန်းများကို ဖယ်ရှားရန် အထောက်အကူပြုပါသည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 21,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
},
|
|
"id": "7uIvS097gRsD",
|
|
"outputId": "c13fc117-4ca1-4145-a0aa-42ac89e6e218",
|
|
"trusted": false
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"0 0\n",
|
|
"2 \n",
|
|
"dtype: object"
|
|
]
|
|
},
|
|
"execution_count": 21,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"example3 = example3.dropna()\n",
|
|
"example3"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "hil2cr64gRsD"
|
|
},
|
|
"source": [
|
|
"ဤအရာသည် `example3[example3.notnull()]` မှ သင့်ရဲ့ output နမူနာလိုပဲ ဖြစ်ရမည်ကို မှတ်ထားပါ။ ဒီမှာ ကွာခြားချက်ကတော့ masked values တွေကို index လုပ်တာမဟုတ်ဘဲ `dropna` က `Series` `example3` မှ ပျောက်ဆုံးနေတဲ့ values တွေကို ဖယ်ရှားလိုက်တာဖြစ်ပါတယ်။\n",
|
|
"\n",
|
|
"DataFrames တွေမှာ dimension နှစ်ခုရှိတဲ့အတွက် ဒေတာတွေကို ဖယ်ရှားဖို့ အခြားရွေးချယ်မှုများကို ပေးစွမ်းနိုင်ပါတယ်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 22,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/",
|
|
"height": 142
|
|
},
|
|
"id": "an-l74sPgRsE",
|
|
"outputId": "340876a0-63ad-40f6-bd54-6240cdae50ab",
|
|
"trusted": false
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<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>0</th>\n",
|
|
" <th>1</th>\n",
|
|
" <th>2</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>0</th>\n",
|
|
" <td>1.0</td>\n",
|
|
" <td>NaN</td>\n",
|
|
" <td>7</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>2.0</td>\n",
|
|
" <td>5.0</td>\n",
|
|
" <td>8</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>2</th>\n",
|
|
" <td>NaN</td>\n",
|
|
" <td>6.0</td>\n",
|
|
" <td>9</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" 0 1 2\n",
|
|
"0 1.0 NaN 7\n",
|
|
"1 2.0 5.0 8\n",
|
|
"2 NaN 6.0 9"
|
|
]
|
|
},
|
|
"execution_count": 22,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"example4 = pd.DataFrame([[1, np.nan, 7], \n",
|
|
" [2, 5, 8], \n",
|
|
" [np.nan, 6, 9]])\n",
|
|
"example4"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "66wwdHZrgRsE"
|
|
},
|
|
"source": [
|
|
"(သင် pandas က `NaN` တွေကို accommodate လုပ်ဖို့အတွက် ကော်လံနှစ်ခုကို float အဖြစ် upcast လုပ်ထားတာသတိထားမိပါသလား?)\n",
|
|
"\n",
|
|
"သင် `DataFrame` ထဲကတစ်ခုတည်းသောတန်ဖိုးကို drop လုပ်လို့မရပါဘူး၊ ဒါကြောင့် အပြည့်အစုံသော row သို့မဟုတ် column ကို drop လုပ်ရပါမယ်။ သင်လုပ်ဆောင်နေတဲ့အရာပေါ်မူတည်ပြီး၊ တစ်ခုခုကိုရွေးချယ်နိုင်ဖို့လိုအပ်နိုင်ပြီး၊ pandas က နှစ်မျိုးလုံးအတွက်ရွေးချယ်စရာပေးထားပါတယ်။ ဒေတာသိပ္ပံမှာ column တွေက variables ကိုယ်စားပြုပြီး row တွေက observations ကိုယ်စားပြုတာကြောင့်၊ row တွေကို drop လုပ်ဖို့ပိုမိုဖြစ်နိုင်ပါတယ်။ `dropna()` ရဲ့ default setting က null values ပါဝင်တဲ့ row တွေကိုအားလုံး drop လုပ်ဖို့ဖြစ်ပါတယ်:\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 23,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/",
|
|
"height": 80
|
|
},
|
|
"id": "jAVU24RXgRsE",
|
|
"outputId": "0b5e5aee-7187-4d3f-b583-a44136ae5f80",
|
|
"trusted": false
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<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>0</th>\n",
|
|
" <th>1</th>\n",
|
|
" <th>2</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>2.0</td>\n",
|
|
" <td>5.0</td>\n",
|
|
" <td>8</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" 0 1 2\n",
|
|
"1 2.0 5.0 8"
|
|
]
|
|
},
|
|
"execution_count": 23,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"example4.dropna()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "TrQRBuTDgRsE"
|
|
},
|
|
"source": [
|
|
"လိုအပ်ပါက၊ ကော်လံများမှ NA အချက်အလက်များကို ဖယ်ရှားနိုင်ပါသည်။ `axis=1` ကို အသုံးပြုပါ:\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 24,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/",
|
|
"height": 142
|
|
},
|
|
"id": "GrBhxu9GgRsE",
|
|
"outputId": "ff4001f3-2e61-4509-d60e-0093d1068437",
|
|
"trusted": false
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<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>2</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>0</th>\n",
|
|
" <td>7</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>8</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>2</th>\n",
|
|
" <td>9</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" 2\n",
|
|
"0 7\n",
|
|
"1 8\n",
|
|
"2 9"
|
|
]
|
|
},
|
|
"execution_count": 24,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"example4.dropna(axis='columns')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "KWXiKTfMgRsF"
|
|
},
|
|
"source": [
|
|
"ဤအချက်ကို သတိပြုပါ၊ သင်ထိန်းသိမ်းလိုသော ဒေတာများစွာကို အထူးသဖြင့် သေးငယ်သော ဒေတာအစုများတွင် ပျောက်ဆုံးစေနိုင်သည်။ သင်သည် null တန်ဖိုးများစွာပါဝင်သော (သို့မဟုတ်) null တန်ဖိုးများအားလုံးပါဝင်သော အတန်းများ သို့မဟုတ် ကော်လံများကိုသာ ဖယ်ရှားလိုပါက အဘယ်သို့လုပ်မည်နည်း? `dropna` တွင် `how` နှင့် `thresh` parameters များကို သတ်မှတ်ခြင်းဖြင့် သင်လိုအပ်သော အဆင့်ဆင့်များကို ပြုလုပ်နိုင်သည်။\n",
|
|
"\n",
|
|
"ပုံမှန်အားဖြင့် `how='any'` သတ်မှတ်ထားသည် (သင်ကိုယ်တိုင်စစ်ဆေးလိုပါက သို့မဟုတ် method တွင်ရှိသော အခြား parameters များကို ကြည့်လိုပါက `example4.dropna?` ကို code cell တစ်ခုတွင် run လိုက်ပါ။) အခြားနည်းလမ်းတစ်ခုအနေဖြင့် `how='all'` ကို သတ်မှတ်နိုင်ပြီး null တန်ဖိုးများအားလုံးပါဝင်သော အတန်းများ သို့မဟုတ် ကော်လံများကိုသာ ဖယ်ရှားနိုင်သည်။ နောက် exercise တွင် ဤအရာကို လက်တွေ့ကျကျကြည့်ရှုနိုင်ရန် `DataFrame` ကို ကျယ်ပြန့်စေကြမည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 25,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/",
|
|
"height": 142
|
|
},
|
|
"id": "Bcf_JWTsgRsF",
|
|
"outputId": "72e0b1b8-52fa-4923-98ce-b6fbed6e44b1",
|
|
"trusted": false
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<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>0</th>\n",
|
|
" <th>1</th>\n",
|
|
" <th>2</th>\n",
|
|
" <th>3</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>0</th>\n",
|
|
" <td>1.0</td>\n",
|
|
" <td>NaN</td>\n",
|
|
" <td>7</td>\n",
|
|
" <td>NaN</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>2.0</td>\n",
|
|
" <td>5.0</td>\n",
|
|
" <td>8</td>\n",
|
|
" <td>NaN</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>2</th>\n",
|
|
" <td>NaN</td>\n",
|
|
" <td>6.0</td>\n",
|
|
" <td>9</td>\n",
|
|
" <td>NaN</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" 0 1 2 3\n",
|
|
"0 1.0 NaN 7 NaN\n",
|
|
"1 2.0 5.0 8 NaN\n",
|
|
"2 NaN 6.0 9 NaN"
|
|
]
|
|
},
|
|
"execution_count": 25,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"example4[3] = np.nan\n",
|
|
"example4"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "pNZer7q9JPNC"
|
|
},
|
|
"source": [
|
|
"> အဓိကအချက်များ:\n",
|
|
"1. Null တန်ဖိုးများကို ဖယ်ရှားခြင်းသည် dataset ကြီးလုံလောက်မှသာ ကောင်းမွန်သော အကြံဉာဏ်ဖြစ်သည်။\n",
|
|
"2. အချက်အလက်များအများစုပျောက်ဆုံးနေသော အတန်းများ သို့မဟုတ် ကော်လံများကို အပြည့်အဝ ဖယ်ရှားနိုင်သည်။\n",
|
|
"3. Null တန်ဖိုးများကို ဖယ်ရှားရန် `DataFrame.dropna(axis=)` method ကို အသုံးပြုနိုင်သည်။ `axis` argument သည် အတန်းများကို ဖယ်ရှားမည်လား၊ ကော်လံများကို ဖယ်ရှားမည်လား ဆိုတာကို ဖော်ပြသည်။\n",
|
|
"4. `how` argument ကိုလည်း အသုံးပြုနိုင်သည်။ ပုံမှန်အားဖြင့် `any` အဖြစ် သတ်မှတ်ထားသည်။ ထို့ကြောင့် Null တန်ဖိုးများ ပါဝင်သော အတန်း/ကော်လံများကိုသာ ဖယ်ရှားသည်။ Null တန်ဖိုးများအားလုံးပါဝင်သော အတန်း/ကော်လံများကိုသာ ဖယ်ရှားရန် `all` အဖြစ် သတ်မှတ်နိုင်သည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "oXXSfQFHgRsF"
|
|
},
|
|
"source": [
|
|
"### လေ့ကျင့်မှု:\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 22,
|
|
"metadata": {
|
|
"collapsed": true,
|
|
"id": "ExUwQRxpgRsF",
|
|
"trusted": false
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# How might you go about dropping just column 3?\n",
|
|
"# Hint: remember that you will need to supply both the axis parameter and the how parameter.\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "38kwAihWgRsG"
|
|
},
|
|
"source": [
|
|
"`thresh` ပရမီတာသည် သင့်အား ပိုမိုသေးငယ်သော ထိန်းချုပ်မှုကို ပေးသည်။ အတန်းတစ်ခု သို့မဟုတ် ကော်လံတစ်ခုကို ထိန်းသိမ်းထားရန် လိုအပ်သော *null မဟုတ်သော* အချက်အလက်အရေအတွက်ကို သင် သတ်မှတ်နိုင်သည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 27,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/",
|
|
"height": 80
|
|
},
|
|
"id": "M9dCNMaagRsG",
|
|
"outputId": "8093713a-54d2-4e54-c73f-4eea315cb6f2",
|
|
"trusted": false
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<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>0</th>\n",
|
|
" <th>1</th>\n",
|
|
" <th>2</th>\n",
|
|
" <th>3</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>2.0</td>\n",
|
|
" <td>5.0</td>\n",
|
|
" <td>8</td>\n",
|
|
" <td>NaN</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" 0 1 2 3\n",
|
|
"1 2.0 5.0 8 NaN"
|
|
]
|
|
},
|
|
"execution_count": 27,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"example4.dropna(axis='rows', thresh=3)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "fmSFnzZegRsG"
|
|
},
|
|
"source": [
|
|
"ဒီမှာ ပထမတန်းနှင့် နောက်ဆုံးတန်းကို ဖယ်ရှားထားပြီးဖြစ်သည်၊ အကြောင်းမှာ ၎င်းတို့တွင် null မဟုတ်သောတန်ဖိုးနှစ်ခုသာပါဝင်သောကြောင့်ဖြစ်သည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "mCcxLGyUgRsG"
|
|
},
|
|
"source": [
|
|
"### Null Value များကို ဖြည့်ခြင်း\n",
|
|
"\n",
|
|
"တစ်ခါတစ်ရံတွင် မရှိသည့်တန်ဖိုးများကို သက်ဆိုင်ရာတန်ဖိုးများဖြင့် ဖြည့်သွင်းခြင်းသည် သင့်လျော်နိုင်ပါသည်။ Null Value များကို ဖြည့်သွင်းရန် နည်းလမ်းအချို့ရှိပါသည်။ ပထမနည်းလမ်းမှာ Domain Knowledge (အချက်အလက်များအပေါ် အခြေခံထားသော အကြောင်းအရာ၏ အသိပညာ) ကို အသုံးပြု၍ မရှိသည့်တန်ဖိုးများကို ခန့်မှန်းဖြည့်သွင်းခြင်းဖြစ်သည်။\n",
|
|
"\n",
|
|
"သင်သည် `isnull` ကို အသုံးပြု၍ Null Value များကို တိုက်ရိုက်ဖြည့်နိုင်ပါသည်၊ သို့သော် အတော်လေး အလုပ်ရှုပ်နိုင်ပါသည်၊ အထူးသဖြင့် ဖြည့်ရန်တန်ဖိုးများ များစွာရှိပါက။ ဒါကြောင့် Data Science တွင် အလွန်ရိုးရှင်းသော အလုပ်တစ်ခုဖြစ်သောကြောင့် pandas သည် `fillna` ကို ပံ့ပိုးပေးပါသည်၊ ၎င်းသည် သင့်ရွေးချယ်မှုတစ်ခုဖြင့် မရှိသည့်တန်ဖိုးများကို အစားထိုးထားသော `Series` သို့မဟုတ် `DataFrame` ၏ မိတ္တူတစ်ခုကို ပြန်ပေးပါသည်။ ၎င်းကို လက်တွေ့အသုံးပြုပုံကို ကြည့်ရန် နောက်ထပ် `Series` ကို ဖန်တီးကြည့်ပါ။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "CE8S7louLezV"
|
|
},
|
|
"source": [
|
|
"### အမျိုးအစားအချက်အလက် (Non-numeric)\n",
|
|
"ပထမဆုံး Non-numeric အချက်အလက်ကို စဉ်းစားကြည့်ရအောင်။ ဒေတာစုပေါင်းများတွင် အမျိုးအစားအချက်အလက်ပါသော ကော်လံများရှိပါသည်။ ဥပမာ - ကျား/မ၊ True or False စသည်တို့။\n",
|
|
"\n",
|
|
"ဤအခြေအနေများအများစုတွင် ကော်လံ၏ `mode` ဖြင့် ပျောက်ဆုံးနေသောတန်ဖိုးများကို အစားထိုးလေ့ရှိသည်။ ဥပမာအားဖြင့် 100 ဒေတာပွင့်များရှိပြီး 90 ခုက True ဟုဆိုထားသည်၊ 8 ခုက False ဟုဆိုထားပြီး 2 ခုက မဖြည့်ထားပါ။ ထို့ကြောင့် ကော်လံတစ်ခုလုံးကို စဉ်းစားပြီး 2 ခုကို True ဖြင့် ဖြည့်နိုင်ပါသည်။\n",
|
|
"\n",
|
|
"ထပ်ပြီးတော့ ဒီမှာ domain knowledge ကိုလည်း အသုံးပြုနိုင်ပါတယ်။ Mode ဖြင့် ဖြည့်သည့် ဥပမာတစ်ခုကို စဉ်းစားကြည့်ရအောင်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 28,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/",
|
|
"height": 204
|
|
},
|
|
"id": "MY5faq4yLdpQ",
|
|
"outputId": "19ab472e-1eed-4de8-f8a7-db2a3af3cb1a"
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<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>0</th>\n",
|
|
" <th>1</th>\n",
|
|
" <th>2</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>0</th>\n",
|
|
" <td>1</td>\n",
|
|
" <td>2</td>\n",
|
|
" <td>True</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>3</td>\n",
|
|
" <td>4</td>\n",
|
|
" <td>None</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>2</th>\n",
|
|
" <td>5</td>\n",
|
|
" <td>6</td>\n",
|
|
" <td>False</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>3</th>\n",
|
|
" <td>7</td>\n",
|
|
" <td>8</td>\n",
|
|
" <td>True</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>4</th>\n",
|
|
" <td>9</td>\n",
|
|
" <td>10</td>\n",
|
|
" <td>True</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" 0 1 2\n",
|
|
"0 1 2 True\n",
|
|
"1 3 4 None\n",
|
|
"2 5 6 False\n",
|
|
"3 7 8 True\n",
|
|
"4 9 10 True"
|
|
]
|
|
},
|
|
"execution_count": 28,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"fill_with_mode = pd.DataFrame([[1,2,\"True\"],\n",
|
|
" [3,4,None],\n",
|
|
" [5,6,\"False\"],\n",
|
|
" [7,8,\"True\"],\n",
|
|
" [9,10,\"True\"]])\n",
|
|
"\n",
|
|
"fill_with_mode"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "MLAoMQOfNPlA"
|
|
},
|
|
"source": [
|
|
"အခုတော့ `None` အဖြစ်တန်ဖိုးကို mode နဲ့ဖြည့်မည့်အခါ mode ကိုအရင်ရှာဖွေကြမယ်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 29,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
},
|
|
"id": "WKy-9Y2tN5jv",
|
|
"outputId": "8da9fa16-e08c-447e-dea1-d4b1db2feebf"
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"True 3\n",
|
|
"False 1\n",
|
|
"Name: 2, dtype: int64"
|
|
]
|
|
},
|
|
"execution_count": 29,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"fill_with_mode[2].value_counts()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "6iNz_zG_OKrx"
|
|
},
|
|
"source": [
|
|
"ဒါဆိုရင် None ကို True နဲ့အစားထိုးပါမယ်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 30,
|
|
"metadata": {
|
|
"id": "TxPKteRvNPOs"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"fill_with_mode[2].fillna('True',inplace=True)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 31,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/",
|
|
"height": 204
|
|
},
|
|
"id": "tvas7c9_OPWE",
|
|
"outputId": "ec3c8e44-d644-475e-9e22-c65101965850"
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<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>0</th>\n",
|
|
" <th>1</th>\n",
|
|
" <th>2</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>0</th>\n",
|
|
" <td>1</td>\n",
|
|
" <td>2</td>\n",
|
|
" <td>True</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>3</td>\n",
|
|
" <td>4</td>\n",
|
|
" <td>True</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>2</th>\n",
|
|
" <td>5</td>\n",
|
|
" <td>6</td>\n",
|
|
" <td>False</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>3</th>\n",
|
|
" <td>7</td>\n",
|
|
" <td>8</td>\n",
|
|
" <td>True</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>4</th>\n",
|
|
" <td>9</td>\n",
|
|
" <td>10</td>\n",
|
|
" <td>True</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" 0 1 2\n",
|
|
"0 1 2 True\n",
|
|
"1 3 4 True\n",
|
|
"2 5 6 False\n",
|
|
"3 7 8 True\n",
|
|
"4 9 10 True"
|
|
]
|
|
},
|
|
"execution_count": 31,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"fill_with_mode"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "SktitLxxOR16"
|
|
},
|
|
"source": [
|
|
"ကျွန်တော်တို့မြင်နိုင်သည့်အတိုင်း null တန်ဖိုးကို အစားထိုးပြီးဖြစ်ပါသည်။ ပြောစရာမလိုအပ်ပါဘူး၊ `'True'` အစားထိုးနေရာတွင် အခြားတစ်ခုခုရေးနိုင်ပြီး အစားထိုးခံရနိုင်ပါသည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "heYe1I0dOmQ_"
|
|
},
|
|
"source": [
|
|
"### ကိန်းဂဏန်းဆိုင်ရာ ဒေတာ\n",
|
|
"အခုတော့ ကိန်းဂဏန်းဆိုင်ရာ ဒေတာကို ဆွေးနွေးကြမယ်။ ဒီမှာ မရှိတဲ့တန်ဖိုးတွေကို အစားထိုးဖို့အတွက် အများဆုံးအသုံးပြုတဲ့နည်းလမ်းနှစ်ခုရှိပါတယ်။\n",
|
|
"\n",
|
|
"1. အတန်းရဲ့ အလယ်တန်းတန်ဖိုး (Median) နဲ့ အစားထိုးခြင်း\n",
|
|
"2. အတန်းရဲ့ ပျမ်းမျှတန်ဖိုး (Mean) နဲ့ အစားထိုးခြင်း\n",
|
|
"\n",
|
|
"အလယ်တန်းတန်ဖိုး (Median) နဲ့ အစားထိုးတာက အချက်အလက်တွေ skewed ဖြစ်ပြီး outliers ရှိတဲ့အခါမှာ အသုံးပြုပါတယ်။ အကြောင်းကတော့ အလယ်တန်းတန်ဖိုးက outliers တွေကို သက်သာစေတဲ့ အကျိုးရှိလို့ပါ။\n",
|
|
"\n",
|
|
"ဒေတာကို အဆင်ပြေစွာ ချိန်ညှိထားတဲ့အခါမှာတော့ ပျမ်းမျှတန်ဖိုး (Mean) ကို အသုံးပြုနိုင်ပါတယ်။ အဲဒီအချိန်မှာတော့ ပျမ်းမျှတန်ဖိုးနဲ့ အလယ်တန်းတန်ဖိုးဟာ အတော်နီးစပ်နေမှာပါ။\n",
|
|
"\n",
|
|
"ပထမဆုံး အတန်းတစ်ခုကို ယူပြီး အဲဒီအတန်းဟာ သာမန်ဖြန့်ဝေမှုရှိနေတဲ့အခြေအနေမှာ မရှိတဲ့တန်ဖိုးတွေကို အတန်းရဲ့ ပျမ်းမျှတန်ဖိုးနဲ့ ဖြည့်စွက်ကြည့်ရအောင်။ \n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 32,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/",
|
|
"height": 204
|
|
},
|
|
"id": "09HM_2feOj5Y",
|
|
"outputId": "7e309013-9acb-411c-9b06-4de795bbeeff"
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<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>0</th>\n",
|
|
" <th>1</th>\n",
|
|
" <th>2</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>0</th>\n",
|
|
" <td>-2.0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>1</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>-1.0</td>\n",
|
|
" <td>2</td>\n",
|
|
" <td>3</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>2</th>\n",
|
|
" <td>NaN</td>\n",
|
|
" <td>4</td>\n",
|
|
" <td>5</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>3</th>\n",
|
|
" <td>1.0</td>\n",
|
|
" <td>6</td>\n",
|
|
" <td>7</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>4</th>\n",
|
|
" <td>2.0</td>\n",
|
|
" <td>8</td>\n",
|
|
" <td>9</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" 0 1 2\n",
|
|
"0 -2.0 0 1\n",
|
|
"1 -1.0 2 3\n",
|
|
"2 NaN 4 5\n",
|
|
"3 1.0 6 7\n",
|
|
"4 2.0 8 9"
|
|
]
|
|
},
|
|
"execution_count": 32,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"fill_with_mean = pd.DataFrame([[-2,0,1],\n",
|
|
" [-1,2,3],\n",
|
|
" [np.nan,4,5],\n",
|
|
" [1,6,7],\n",
|
|
" [2,8,9]])\n",
|
|
"\n",
|
|
"fill_with_mean"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "ka7-wNfzSxbx"
|
|
},
|
|
"source": [
|
|
"ကော်လံ၏ ပျမ်းမျှတန်ဖိုးမှာ\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 33,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
},
|
|
"id": "XYtYEf5BSxFL",
|
|
"outputId": "68a78d18-f0e5-4a9a-a959-2c3676a57c70"
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"0.0"
|
|
]
|
|
},
|
|
"execution_count": 33,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"np.mean(fill_with_mean[0])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "oBSRGxKRS39K"
|
|
},
|
|
"source": [
|
|
"အလယ်တန်းတန်ဖိုးဖြင့် ဖြည့်ခြင်း\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 34,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/",
|
|
"height": 204
|
|
},
|
|
"id": "FzncQLmuS5jh",
|
|
"outputId": "00f74fff-01f4-4024-c261-796f50f01d2e"
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<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>0</th>\n",
|
|
" <th>1</th>\n",
|
|
" <th>2</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>0</th>\n",
|
|
" <td>-2.0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>1</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>-1.0</td>\n",
|
|
" <td>2</td>\n",
|
|
" <td>3</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>2</th>\n",
|
|
" <td>0.0</td>\n",
|
|
" <td>4</td>\n",
|
|
" <td>5</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>3</th>\n",
|
|
" <td>1.0</td>\n",
|
|
" <td>6</td>\n",
|
|
" <td>7</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>4</th>\n",
|
|
" <td>2.0</td>\n",
|
|
" <td>8</td>\n",
|
|
" <td>9</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" 0 1 2\n",
|
|
"0 -2.0 0 1\n",
|
|
"1 -1.0 2 3\n",
|
|
"2 0.0 4 5\n",
|
|
"3 1.0 6 7\n",
|
|
"4 2.0 8 9"
|
|
]
|
|
},
|
|
"execution_count": 34,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"fill_with_mean[0].fillna(np.mean(fill_with_mean[0]),inplace=True)\n",
|
|
"fill_with_mean"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "CwpVFCrPTC5z"
|
|
},
|
|
"source": [
|
|
"ကျွန်တော်တို့မြင်နိုင်သည့်အတိုင်း၊ ပျောက်ဆုံးနေသောတန်ဖိုးကို ၎င်း၏ပျမ်းမျှတန်ဖိုးဖြင့် အစားထိုးထားပါသည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "jIvF13a1i00Z"
|
|
},
|
|
"source": [
|
|
"အခုတော့ နောက်ထပ် dataframe တစ်ခုကို စမ်းကြည့်ရအောင်၊ ဒီတစ်ခါမှာတော့ None အဖြစ်တန်ဖိုးတွေကို ကော်လံရဲ့ အလယ်တန်းတန်ဖိုးနဲ့ အစားထိုးပါမယ်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 35,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/",
|
|
"height": 204
|
|
},
|
|
"id": "DA59Bqo3jBYZ",
|
|
"outputId": "85dae6ec-7394-4c36-fda0-e04769ec4a32"
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<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>0</th>\n",
|
|
" <th>1</th>\n",
|
|
" <th>2</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>0</th>\n",
|
|
" <td>-2</td>\n",
|
|
" <td>0.0</td>\n",
|
|
" <td>1</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>-1</td>\n",
|
|
" <td>2.0</td>\n",
|
|
" <td>3</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>2</th>\n",
|
|
" <td>0</td>\n",
|
|
" <td>NaN</td>\n",
|
|
" <td>5</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>3</th>\n",
|
|
" <td>1</td>\n",
|
|
" <td>6.0</td>\n",
|
|
" <td>7</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>4</th>\n",
|
|
" <td>2</td>\n",
|
|
" <td>8.0</td>\n",
|
|
" <td>9</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" 0 1 2\n",
|
|
"0 -2 0.0 1\n",
|
|
"1 -1 2.0 3\n",
|
|
"2 0 NaN 5\n",
|
|
"3 1 6.0 7\n",
|
|
"4 2 8.0 9"
|
|
]
|
|
},
|
|
"execution_count": 35,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"fill_with_median = pd.DataFrame([[-2,0,1],\n",
|
|
" [-1,2,3],\n",
|
|
" [0,np.nan,5],\n",
|
|
" [1,6,7],\n",
|
|
" [2,8,9]])\n",
|
|
"\n",
|
|
"fill_with_median"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "mM1GpXYmjHnc"
|
|
},
|
|
"source": [
|
|
"ဒုတိယကော်လံ၏အလယ်တန်းတန်ဖိုးမှာ\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 36,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
},
|
|
"id": "uiDy5v3xjHHX",
|
|
"outputId": "564b6b74-2004-4486-90d4-b39330a64b88"
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"4.0"
|
|
]
|
|
},
|
|
"execution_count": 36,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"fill_with_median[1].median()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "z9PLF75Jj_1s"
|
|
},
|
|
"source": [
|
|
"မီဒီယန်းဖြင့်ဖြည့်ခြင်း\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 37,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/",
|
|
"height": 204
|
|
},
|
|
"id": "lFKbOxCMkBbg",
|
|
"outputId": "a8bd18fb-2765-47d4-e5fe-e965f57ed1f4"
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<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>0</th>\n",
|
|
" <th>1</th>\n",
|
|
" <th>2</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>0</th>\n",
|
|
" <td>-2</td>\n",
|
|
" <td>0.0</td>\n",
|
|
" <td>1</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>-1</td>\n",
|
|
" <td>2.0</td>\n",
|
|
" <td>3</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>2</th>\n",
|
|
" <td>0</td>\n",
|
|
" <td>4.0</td>\n",
|
|
" <td>5</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>3</th>\n",
|
|
" <td>1</td>\n",
|
|
" <td>6.0</td>\n",
|
|
" <td>7</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>4</th>\n",
|
|
" <td>2</td>\n",
|
|
" <td>8.0</td>\n",
|
|
" <td>9</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" 0 1 2\n",
|
|
"0 -2 0.0 1\n",
|
|
"1 -1 2.0 3\n",
|
|
"2 0 4.0 5\n",
|
|
"3 1 6.0 7\n",
|
|
"4 2 8.0 9"
|
|
]
|
|
},
|
|
"execution_count": 37,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"fill_with_median[1].fillna(fill_with_median[1].median(),inplace=True)\n",
|
|
"fill_with_median"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "8JtQ53GSkKWC"
|
|
},
|
|
"source": [
|
|
"ကျွန်တော်တို့မြင်နိုင်သည့်အတိုင်း NaN တန်ဖိုးကို ကော်လံ၏အလယ်တန်းတန်ဖိုးဖြင့် အစားထိုးထားပါသည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 38,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
},
|
|
"id": "0ybtWLDdgRsG",
|
|
"outputId": "b8c238ef-6024-4ee2-be2b-aa1f0fcac61d",
|
|
"trusted": false
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"a 1.0\n",
|
|
"b NaN\n",
|
|
"c 2.0\n",
|
|
"d NaN\n",
|
|
"e 3.0\n",
|
|
"dtype: float64"
|
|
]
|
|
},
|
|
"execution_count": 38,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"example5 = pd.Series([1, np.nan, 2, None, 3], index=list('abcde'))\n",
|
|
"example5"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "yrsigxRggRsH"
|
|
},
|
|
"source": [
|
|
"သင်သည် null အချက်အလက်များအားလုံးကို `0` ကဲ့သို့သောတစ်ခုတည်းသောတန်ဖိုးဖြင့်ဖြည့်နိုင်သည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 39,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
},
|
|
"id": "KXMIPsQdgRsH",
|
|
"outputId": "aeedfa0a-a421-4c2f-cb0d-183ce8f0c91d",
|
|
"trusted": false
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"a 1.0\n",
|
|
"b 0.0\n",
|
|
"c 2.0\n",
|
|
"d 0.0\n",
|
|
"e 3.0\n",
|
|
"dtype: float64"
|
|
]
|
|
},
|
|
"execution_count": 39,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"example5.fillna(0)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "RRlI5f_hkfKe"
|
|
},
|
|
"source": [
|
|
"> အဓိကအချက်များ:\n",
|
|
"1. အချက်အလက်နည်းပါးသောအခါ သို့မဟုတ် မရှိသည့်အချက်အလက်များကို ဖြည့်စွက်ရန် မဟာဗျူဟာတစ်ခုရှိသောအခါ မရှိသည့်တန်ဖိုးများကို ဖြည့်စွက်သင့်သည်။\n",
|
|
"2. မရှိသည့်တန်ဖိုးများကို ခန့်မှန်းဖြည့်စွက်ရန် အကျိုးအမြတ်ဆိုင်ရာ အသိပညာကို အသုံးပြုနိုင်သည်။\n",
|
|
"3. အမျိုးအစားဆိုင်ရာ အချက်အလက်များအတွက် မရှိသည့်တန်ဖိုးများကို အများအားဖြင့် ကော်လံ၏ mode ဖြင့် အစားထိုးသည်။\n",
|
|
"4. ကိန်းဂဏန်းဆိုင်ရာ အချက်အလက်များအတွက် မရှိသည့်တန်ဖိုးများကို အများအားဖြင့် mean (normalized datasets များအတွက်) သို့မဟုတ် ကော်လံ၏ median ဖြင့် ဖြည့်စွက်သည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "FI9MmqFJgRsH"
|
|
},
|
|
"source": [
|
|
"### လေ့ကျင့်မှု:\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 40,
|
|
"metadata": {
|
|
"collapsed": true,
|
|
"id": "af-ezpXdgRsH",
|
|
"trusted": false
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# What happens if you try to fill null values with a string, like ''?\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "kq3hw1kLgRsI"
|
|
},
|
|
"source": [
|
|
"သင်သည် null တန်ဖိုးများကို **forward-fill** လုပ်နိုင်ပြီး၊ ၎င်းသည် နောက်ဆုံးတရားဝင်တန်ဖိုးကို null ဖြည့်ရန် အသုံးပြုခြင်းဖြစ်သည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 41,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
},
|
|
"id": "vO3BuNrggRsI",
|
|
"outputId": "e2bc591b-0b48-4e88-ee65-754f2737c196",
|
|
"trusted": false
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"a 1.0\n",
|
|
"b 1.0\n",
|
|
"c 2.0\n",
|
|
"d 2.0\n",
|
|
"e 3.0\n",
|
|
"dtype: float64"
|
|
]
|
|
},
|
|
"execution_count": 41,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"example5.fillna(method='ffill')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "nDXeYuHzgRsI"
|
|
},
|
|
"source": [
|
|
"သင်သည် null ကို ဖြည့်ရန် နောက်ဆုံးမှန်ကန်သောတန်ဖိုးကို နောက်သို့ပြန်လည်ဖြည့်ရန် **back-fill** ကိုလည်း အသုံးပြုနိုင်သည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 42,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
},
|
|
"id": "4M5onHcEgRsI",
|
|
"outputId": "8f32b185-40dd-4a9f-bd85-54d6b6a414fe",
|
|
"trusted": false
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"a 1.0\n",
|
|
"b 2.0\n",
|
|
"c 2.0\n",
|
|
"d 3.0\n",
|
|
"e 3.0\n",
|
|
"dtype: float64"
|
|
]
|
|
},
|
|
"execution_count": 42,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"example5.fillna(method='bfill')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"collapsed": true,
|
|
"id": "MbBzTom5gRsI"
|
|
},
|
|
"source": [
|
|
"သင်ခန့်မှန်းနိုင်သလို၊ ဒါဟာ DataFrames တွေနဲ့လည်း အတူတူအလုပ်လုပ်ပါတယ်၊ ဒါပေမယ့် null values တွေကို ဖြည့်စွက်ဖို့ `axis` ကိုလည်း သတ်မှတ်နိုင်ပါတယ်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 43,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/",
|
|
"height": 142
|
|
},
|
|
"id": "aRpIvo4ZgRsI",
|
|
"outputId": "905a980a-a808-4eca-d0ba-224bd7d85955",
|
|
"trusted": false
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<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>0</th>\n",
|
|
" <th>1</th>\n",
|
|
" <th>2</th>\n",
|
|
" <th>3</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>0</th>\n",
|
|
" <td>1.0</td>\n",
|
|
" <td>NaN</td>\n",
|
|
" <td>7</td>\n",
|
|
" <td>NaN</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>2.0</td>\n",
|
|
" <td>5.0</td>\n",
|
|
" <td>8</td>\n",
|
|
" <td>NaN</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>2</th>\n",
|
|
" <td>NaN</td>\n",
|
|
" <td>6.0</td>\n",
|
|
" <td>9</td>\n",
|
|
" <td>NaN</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" 0 1 2 3\n",
|
|
"0 1.0 NaN 7 NaN\n",
|
|
"1 2.0 5.0 8 NaN\n",
|
|
"2 NaN 6.0 9 NaN"
|
|
]
|
|
},
|
|
"execution_count": 43,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"example4"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 44,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/",
|
|
"height": 142
|
|
},
|
|
"id": "VM1qtACAgRsI",
|
|
"outputId": "71f2ad28-9b4e-4ff4-f5c3-e731eb489ade",
|
|
"trusted": false
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<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>0</th>\n",
|
|
" <th>1</th>\n",
|
|
" <th>2</th>\n",
|
|
" <th>3</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>0</th>\n",
|
|
" <td>1.0</td>\n",
|
|
" <td>1.0</td>\n",
|
|
" <td>7.0</td>\n",
|
|
" <td>7.0</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>2.0</td>\n",
|
|
" <td>5.0</td>\n",
|
|
" <td>8.0</td>\n",
|
|
" <td>8.0</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>2</th>\n",
|
|
" <td>NaN</td>\n",
|
|
" <td>6.0</td>\n",
|
|
" <td>9.0</td>\n",
|
|
" <td>9.0</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" 0 1 2 3\n",
|
|
"0 1.0 1.0 7.0 7.0\n",
|
|
"1 2.0 5.0 8.0 8.0\n",
|
|
"2 NaN 6.0 9.0 9.0"
|
|
]
|
|
},
|
|
"execution_count": 44,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"example4.fillna(method='ffill', axis=1)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "ZeMc-I1EgRsI"
|
|
},
|
|
"source": [
|
|
"သတိပြုပါ၊ ယခင်တန်ဖိုးကို ရှေ့သို့ဖြည့်စွက်ရန် မရရှိနိုင်သောအခါတွင် null တန်ဖိုးသည် ကျန်ရှိနေသည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "eeAoOU0RgRsJ"
|
|
},
|
|
"source": [
|
|
"### လေ့ကျင့်မှု:\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 45,
|
|
"metadata": {
|
|
"collapsed": true,
|
|
"id": "e8S-CjW8gRsJ",
|
|
"trusted": false
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# What output does example4.fillna(method='bfill', axis=1) produce?\n",
|
|
"# What about example4.fillna(method='ffill') or example4.fillna(method='bfill')?\n",
|
|
"# Can you think of a longer code snippet to write that can fill all of the null values in example4?\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "YHgy0lIrgRsJ"
|
|
},
|
|
"source": [
|
|
"သင်သည် `fillna` ကို အသုံးပြုပုံအပေါ်တွင် ဖန်တီးမှုရှိနိုင်သည်။ ဥပမာအားဖြင့်၊ `example4` ကို ထပ်မံကြည့်ရှုကြမည်၊ သို့သော် ဒီတစ်ခါမှာတော့ `DataFrame` ထဲရှိ တန်ဖိုးအားလုံး၏ ပျမ်းမျှတန်ဖိုးဖြင့် မရှိသည့်တန်ဖိုးများကို ဖြည့်စွက်ကြည့်ပါမည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 46,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/",
|
|
"height": 142
|
|
},
|
|
"id": "OtYVErEygRsJ",
|
|
"outputId": "708b1e67-45ca-44bf-a5ee-8b2de09ece73",
|
|
"trusted": false
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<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>0</th>\n",
|
|
" <th>1</th>\n",
|
|
" <th>2</th>\n",
|
|
" <th>3</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>0</th>\n",
|
|
" <td>1.0</td>\n",
|
|
" <td>5.5</td>\n",
|
|
" <td>7</td>\n",
|
|
" <td>NaN</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>2.0</td>\n",
|
|
" <td>5.0</td>\n",
|
|
" <td>8</td>\n",
|
|
" <td>NaN</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>2</th>\n",
|
|
" <td>1.5</td>\n",
|
|
" <td>6.0</td>\n",
|
|
" <td>9</td>\n",
|
|
" <td>NaN</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" 0 1 2 3\n",
|
|
"0 1.0 5.5 7 NaN\n",
|
|
"1 2.0 5.0 8 NaN\n",
|
|
"2 1.5 6.0 9 NaN"
|
|
]
|
|
},
|
|
"execution_count": 46,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"example4.fillna(example4.mean())"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "zpMvCkLSgRsJ"
|
|
},
|
|
"source": [
|
|
"သတိပြုပါ၊ အတန်း ၃ သည် အတန်တန်ဖွယ်မရှိသေးပါ။ ပုံမှန်အတိုင်း တန်ဖိုးများကို အတန်းလိုက်ဖြည့်သွင်းသည်။\n",
|
|
"\n",
|
|
"> **သင်ခန်းစာ:** သင့်ဒေတာများတွင် ပျောက်ဆုံးနေသောတန်ဖိုးများကို ကိုင်တွယ်ရန် နည်းလမ်းများစွာရှိသည်။ သင့်အသုံးပြုမည့်နည်းလမ်း (ဖယ်ရှားခြင်း၊ အစားထိုးခြင်း၊ သို့မဟုတ် အစားထိုးပုံစံ) သည် အဆိုပါဒေတာ၏အသေးစိတ်အချက်အလက်များအပေါ်မူတည်သင့်သည်။ ဒေတာများကို ပိုမိုကိုင်တွယ်ပြီး အလုပ်လုပ်သည့်အခါ ပျောက်ဆုံးနေသောတန်ဖိုးများကို ဘယ်လိုကိုင်တွယ်ရမည်ဆိုသည်ကို ပိုမိုနားလည်လာမည်ဖြစ်သည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "bauDnESIl9FH"
|
|
},
|
|
"source": [
|
|
"### ကဏ္ဍအချက်အလက်များကို Encoding လုပ်ခြင်း\n",
|
|
"\n",
|
|
"Machine learning မော်ဒယ်များသည် ကိန်းဂဏန်းများနှင့် ကိန်းဂဏန်းပုံစံအချက်အလက်များကိုသာ ကိုင်တွယ်နိုင်သည်။ မော်ဒယ်သည် Yes နှင့် No အကြားကွာခြားမှုကို မသိနိုင်ပေမယ့် 0 နှင့် 1 အကြားကွာခြားမှုကို သိနိုင်ပါမည်။ ထို့ကြောင့် အချက်အလက်များတွင် ပျောက်နေသောတန်ဖိုးများကို ဖြည့်ပြီးနောက် မော်ဒယ်အနားမှာ နားလည်နိုင်ရန် ကဏ္ဍအချက်အလက်များကို ကိန်းဂဏန်းပုံစံတစ်ခုခုအဖြစ် encode လုပ်ရန် လိုအပ်ပါသည်။\n",
|
|
"\n",
|
|
"Encoding ကို လုပ်နိုင်သောနည်းလမ်းနှစ်မျိုးရှိပြီး၊ အောက်တွင် ဆွေးနွေးသွားမည်ဖြစ်သည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "uDq9SxB7mu5i"
|
|
},
|
|
"source": [
|
|
"**LABEL ENCODING**\n",
|
|
"\n",
|
|
"Label encoding သည် အမျိုးအစားတစ်ခုချင်းစီကို နံပါတ်တစ်ခုအဖြစ် ပြောင်းလဲခြင်းဖြစ်သည်။ ဥပမာအားဖြင့်၊ ကျွန်ုပ်တို့တွင် လေကြောင်းခရီးသည်များ၏ dataset ရှိပြီး ['business class', 'economy class', 'first class'] အမျိုးအစားများပါဝင်သော column တစ်ခုရှိသည်ဟု ဆိုပါစို့။ Label encoding ပြုလုပ်ပါက၊ ၎င်းသည် [0,1,2] အဖြစ် ပြောင်းလဲသွားမည်ဖြစ်သည်။ Code ဖြင့် ဥပမာကို ကြည့်ကြမည်။ ကျွန်ုပ်တို့သည် နောက်ထပ် notebooks များတွင် `scikit-learn` ကို သင်ယူမည်ဖြစ်သဖြင့်၊ ဒီနေရာတွင် မသုံးပါ။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 47,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/",
|
|
"height": 235
|
|
},
|
|
"id": "1vGz7uZyoWHL",
|
|
"outputId": "9e252855-d193-4103-a54d-028ea7787b34"
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<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>ID</th>\n",
|
|
" <th>class</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>0</th>\n",
|
|
" <td>10</td>\n",
|
|
" <td>business class</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>20</td>\n",
|
|
" <td>first class</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>2</th>\n",
|
|
" <td>30</td>\n",
|
|
" <td>economy class</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>3</th>\n",
|
|
" <td>40</td>\n",
|
|
" <td>economy class</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>4</th>\n",
|
|
" <td>50</td>\n",
|
|
" <td>economy class</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>5</th>\n",
|
|
" <td>60</td>\n",
|
|
" <td>business class</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" ID class\n",
|
|
"0 10 business class\n",
|
|
"1 20 first class\n",
|
|
"2 30 economy class\n",
|
|
"3 40 economy class\n",
|
|
"4 50 economy class\n",
|
|
"5 60 business class"
|
|
]
|
|
},
|
|
"execution_count": 47,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"label = pd.DataFrame([\n",
|
|
" [10,'business class'],\n",
|
|
" [20,'first class'],\n",
|
|
" [30, 'economy class'],\n",
|
|
" [40, 'economy class'],\n",
|
|
" [50, 'economy class'],\n",
|
|
" [60, 'business class']\n",
|
|
"],columns=['ID','class'])\n",
|
|
"label"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "IDHnkwTYov-h"
|
|
},
|
|
"source": [
|
|
"ပထမတန်းကော်လံတွင် label encoding ပြုလုပ်ရန်၊ အရင်ဆုံး တစ်ခုချင်းစီ၏အတန်းကို နံပါတ်တစ်ခုနှင့်ဆက်စပ်ထားသော mapping ကို ဖော်ပြရမည်၊ ထို့နောက် အစားထိုးရန်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 48,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/",
|
|
"height": 235
|
|
},
|
|
"id": "ZC5URJG3o1ES",
|
|
"outputId": "aab0f1e7-e0f3-4c14-8459-9f9168c85437"
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<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>ID</th>\n",
|
|
" <th>class</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>0</th>\n",
|
|
" <td>10</td>\n",
|
|
" <td>0</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>20</td>\n",
|
|
" <td>2</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>2</th>\n",
|
|
" <td>30</td>\n",
|
|
" <td>1</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>3</th>\n",
|
|
" <td>40</td>\n",
|
|
" <td>1</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>4</th>\n",
|
|
" <td>50</td>\n",
|
|
" <td>1</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>5</th>\n",
|
|
" <td>60</td>\n",
|
|
" <td>0</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" ID class\n",
|
|
"0 10 0\n",
|
|
"1 20 2\n",
|
|
"2 30 1\n",
|
|
"3 40 1\n",
|
|
"4 50 1\n",
|
|
"5 60 0"
|
|
]
|
|
},
|
|
"execution_count": 48,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"class_labels = {'business class':0,'economy class':1,'first class':2}\n",
|
|
"label['class'] = label['class'].replace(class_labels)\n",
|
|
"label"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "ftnF-TyapOPt"
|
|
},
|
|
"source": [
|
|
"ကျွန်တော်တို့မြင်နိုင်သည့်အတိုင်း၊ အထွက်သည် ကျွန်တော်တို့ထင်ထားသည့်အတိုင်းကိုက်ညီနေသည်။ ဒါဆိုရင် label encoding ကို ဘယ်အချိန်မှာသုံးမလဲ? Label encoding ကို အောက်ပါအခြေအနေများအနက် တစ်ခုသို့မဟုတ် နှစ်ခုလုံးတွင်သုံးပါသည်။\n",
|
|
"1. အမျိုးအစားများရဲ့ အရေအတွက်များသောအခါ\n",
|
|
"2. အမျိုးအစားများသည် အစီအစဉ်အတိုင်းရှိသောအခါ\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "eQPAPVwsqWT7"
|
|
},
|
|
"source": [
|
|
"**ONE HOT ENCODING**\n",
|
|
"\n",
|
|
"One Hot Encoding ဆိုတာ Encoding အမျိုးအစားတစ်ခုဖြစ်ပါတယ်။ ဒီ Encoding အမျိုးအစားမှာ Column ရဲ့ Category တစ်ခုချင်းစီကို သီးသန့် Column အဖြစ် ထည့်ပေးပြီး၊ Data Point တစ်ခုချင်းစီမှာ အဲဒီ Category ပါဝင်မပါဝင်ပေါ်မူတည်ပြီး 0 သို့မဟုတ် 1 ကို ထည့်ပေးပါတယ်။ ဒါကြောင့် Category မျိုးစုံ n ခုရှိရင် Dataframe မှာ Column n ခုကို ထပ်ထည့်ပေးရပါမယ်။\n",
|
|
"\n",
|
|
"ဥပမာအနေနဲ့ အရင်က သုံးခဲ့တဲ့ လေယာဉ်အတန်း (Aeroplane Class) ဥပမာကို ပြန်ယူကြည့်ရအောင်။ Categories တွေက ['business class', 'economy class', 'first class'] ဖြစ်ပါတယ်။ ဒါကြောင့် One Hot Encoding လုပ်မယ်ဆိုရင် Dataset မှာ ['class_business class', 'class_economy class', 'class_first class'] ဆိုတဲ့ Column သုံးခုကို ထည့်ပေးရပါမယ်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 49,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/",
|
|
"height": 235
|
|
},
|
|
"id": "ZM0eVh0ArKUL",
|
|
"outputId": "83238a76-b3a5-418d-c0b6-605b02b6891b"
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<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>ID</th>\n",
|
|
" <th>class</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>0</th>\n",
|
|
" <td>10</td>\n",
|
|
" <td>business class</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>20</td>\n",
|
|
" <td>first class</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>2</th>\n",
|
|
" <td>30</td>\n",
|
|
" <td>economy class</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>3</th>\n",
|
|
" <td>40</td>\n",
|
|
" <td>economy class</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>4</th>\n",
|
|
" <td>50</td>\n",
|
|
" <td>economy class</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>5</th>\n",
|
|
" <td>60</td>\n",
|
|
" <td>business class</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" ID class\n",
|
|
"0 10 business class\n",
|
|
"1 20 first class\n",
|
|
"2 30 economy class\n",
|
|
"3 40 economy class\n",
|
|
"4 50 economy class\n",
|
|
"5 60 business class"
|
|
]
|
|
},
|
|
"execution_count": 49,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"one_hot = pd.DataFrame([\n",
|
|
" [10,'business class'],\n",
|
|
" [20,'first class'],\n",
|
|
" [30, 'economy class'],\n",
|
|
" [40, 'economy class'],\n",
|
|
" [50, 'economy class'],\n",
|
|
" [60, 'business class']\n",
|
|
"],columns=['ID','class'])\n",
|
|
"one_hot"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "aVnZ7paDrWmb"
|
|
},
|
|
"source": [
|
|
"အရင်ကော်လံကို One Hot Encoding ပြုလုပ်ကြပါစို့\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 50,
|
|
"metadata": {
|
|
"id": "RUPxf7egrYKr"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"one_hot_data = pd.get_dummies(one_hot,columns=['class'])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 51,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/",
|
|
"height": 235
|
|
},
|
|
"id": "TM37pHsFr4ge",
|
|
"outputId": "7be15f53-79b2-447a-979c-822658339a9e"
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<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>ID</th>\n",
|
|
" <th>class_business class</th>\n",
|
|
" <th>class_economy class</th>\n",
|
|
" <th>class_first class</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>0</th>\n",
|
|
" <td>10</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>0</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>20</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>1</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>2</th>\n",
|
|
" <td>30</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>0</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>3</th>\n",
|
|
" <td>40</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>0</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>4</th>\n",
|
|
" <td>50</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>0</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>5</th>\n",
|
|
" <td>60</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>0</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" ID class_business class class_economy class class_first class\n",
|
|
"0 10 1 0 0\n",
|
|
"1 20 0 0 1\n",
|
|
"2 30 0 1 0\n",
|
|
"3 40 0 1 0\n",
|
|
"4 50 0 1 0\n",
|
|
"5 60 1 0 0"
|
|
]
|
|
},
|
|
"execution_count": 51,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"one_hot_data"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "_zXRLOjXujdA"
|
|
},
|
|
"source": [
|
|
"တစ်ခုချင်းစီသော hot encoded ကော်လံတွင် 0 သို့မဟုတ် 1 ပါဝင်ပြီး၊ အဲဒီအမျိုးအစားသည် အဲဒီဒေတာပွိုင့်အတွက် ရှိမရှိကို သတ်မှတ်ပေးသည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "bDnC4NQOu0qr"
|
|
},
|
|
"source": [
|
|
"One hot encoding ကို ဘယ်အချိန်မှာ အသုံးပြုသင့်သလဲ? One hot encoding ကို အောက်ပါအခြေအနေများတွင် အသုံးပြုနိုင်သည် -\n",
|
|
"\n",
|
|
"1. အမျိုးအစားများရဲ့ အရေအတွက်နဲ့ dataset ရဲ့ အရွယ်အစားက သေးငယ်တဲ့အခါ။\n",
|
|
"2. အမျိုးအစားများမှာ အထူးအစီအစဉ်မရှိတဲ့အခါ။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "XnUmci_4uvyu"
|
|
},
|
|
"source": [
|
|
"> အဓိကအချက်များ:\n",
|
|
"1. အနက်ရှိုင်းမဟုတ်သောဒေတာများကို နံပါတ်ပုံစံဒေတာများအဖြစ် ပြောင်းလဲရန် Encoding ကို အသုံးပြုသည်။\n",
|
|
"2. Encoding အမျိုးအစားနှစ်မျိုးရှိသည် - Label encoding နှင့် One Hot encoding ဖြစ်ပြီး၊ ဒေတာစနစ်၏လိုအပ်ချက်များအပေါ်မူတည်၍ အဆိုပါ encoding များကို ပြုလုပ်နိုင်သည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "K8UXOJYRgRsJ"
|
|
},
|
|
"source": [
|
|
"## အချက်အလက်ထပ်နေမှုများကို ဖယ်ရှားခြင်း\n",
|
|
"\n",
|
|
"> **သင်ယူရမည့်ရည်ရွယ်ချက်:** ဒီအခန်းခွဲအဆုံးတွင် DataFrames မှ ထပ်နေသောတန်ဖိုးများကို ရှာဖွေပြီး ဖယ်ရှားနိုင်ရန် သင်ကျွမ်းကျင်လာရမည်။\n",
|
|
"\n",
|
|
"ပျောက်နေသောအချက်အလက်များအပြင်၊ အမှန်တကယ်ရှိသောဒေတာများတွင် အချက်အလက်ထပ်နေမှုများကိုလည်း မကြာခဏတွေ့ရပါမည်။ ကံကောင်းစွာ pandas သည် ထပ်နေသောအချက်အလက်များကို ရှာဖွေပြီး ဖယ်ရှားရန် လွယ်ကူသောနည်းလမ်းကို ပံ့ပိုးပေးထားပါသည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "qrEG-Wa0gRsJ"
|
|
},
|
|
"source": [
|
|
"### အတူတူဖြစ်သောတန်ဖိုးများကိုရှာဖွေခြင်း: `duplicated`\n",
|
|
"\n",
|
|
"pandas မှာ `duplicated` method ကိုအသုံးပြုပြီး အတူတူဖြစ်သောတန်ဖိုးများကို လွယ်ကူစွာရှာဖွေနိုင်ပါတယ်။ ဒီ method က Boolean mask ကိုပြန်ပေးပြီး `DataFrame` ထဲမှာ ရှိနေတဲ့ entry တစ်ခုဟာ အရင်တစ်ခုနဲ့ အတူတူဖြစ်ကြောင်းကို ဖော်ပြပေးပါတယ်။ ဒီကို လက်တွေ့အသုံးပြုကြည့်ဖို့ `DataFrame` တစ်ခုကို ပြန်ဖန်တီးကြည့်ရအောင်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 52,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/",
|
|
"height": 204
|
|
},
|
|
"id": "ZLu6FEnZgRsJ",
|
|
"outputId": "376512d1-d842-4db1-aea3-71052aeeecaf",
|
|
"trusted": false
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<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>letters</th>\n",
|
|
" <th>numbers</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>0</th>\n",
|
|
" <td>A</td>\n",
|
|
" <td>1</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>B</td>\n",
|
|
" <td>2</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>2</th>\n",
|
|
" <td>A</td>\n",
|
|
" <td>1</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>3</th>\n",
|
|
" <td>B</td>\n",
|
|
" <td>3</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>4</th>\n",
|
|
" <td>B</td>\n",
|
|
" <td>3</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" letters numbers\n",
|
|
"0 A 1\n",
|
|
"1 B 2\n",
|
|
"2 A 1\n",
|
|
"3 B 3\n",
|
|
"4 B 3"
|
|
]
|
|
},
|
|
"execution_count": 52,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"example6 = pd.DataFrame({'letters': ['A','B'] * 2 + ['B'],\n",
|
|
" 'numbers': [1, 2, 1, 3, 3]})\n",
|
|
"example6"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 53,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
},
|
|
"id": "cIduB5oBgRsK",
|
|
"outputId": "3da27b3d-4d69-4e1d-bb52-0af21bae87f2",
|
|
"trusted": false
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"0 False\n",
|
|
"1 False\n",
|
|
"2 True\n",
|
|
"3 False\n",
|
|
"4 True\n",
|
|
"dtype: bool"
|
|
]
|
|
},
|
|
"execution_count": 53,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"example6.duplicated()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "0eDRJD4SgRsK"
|
|
},
|
|
"source": [
|
|
"### အတူတူထပ်နေသောအချက်အလက်များကို ဖယ်ရှားခြင်း: `drop_duplicates`\n",
|
|
"`drop_duplicates` သည် `duplicated` အဖြစ် `False` ဖြစ်နေသော အချက်အလက်များကိုသာ ထုတ်ပေးသော copy ကို ပြန်ပေးသည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 54,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/",
|
|
"height": 142
|
|
},
|
|
"id": "w_YPpqIqgRsK",
|
|
"outputId": "ac66bd2f-8671-4744-87f5-8b8d96553dea",
|
|
"trusted": false
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<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>letters</th>\n",
|
|
" <th>numbers</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>0</th>\n",
|
|
" <td>A</td>\n",
|
|
" <td>1</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>B</td>\n",
|
|
" <td>2</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>3</th>\n",
|
|
" <td>B</td>\n",
|
|
" <td>3</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" letters numbers\n",
|
|
"0 A 1\n",
|
|
"1 B 2\n",
|
|
"3 B 3"
|
|
]
|
|
},
|
|
"execution_count": 54,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"example6.drop_duplicates()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "69AqoCZAgRsK"
|
|
},
|
|
"source": [
|
|
"`duplicated` နှင့် `drop_duplicates` နှစ်ခုစလုံးသည် အကုန်လုံးကို default အနေနဲ့ စဉ်းစားပေးသော်လည်း သင့် `DataFrame` မှာ column အချို့ကိုသာ စစ်ဆေးစေလိုပါက သတ်မှတ်ပေးနိုင်သည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 55,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/",
|
|
"height": 111
|
|
},
|
|
"id": "BILjDs67gRsK",
|
|
"outputId": "ef6dcc08-db8b-4352-c44e-5aa9e2bec0d3",
|
|
"trusted": false
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<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>letters</th>\n",
|
|
" <th>numbers</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>0</th>\n",
|
|
" <td>A</td>\n",
|
|
" <td>1</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>B</td>\n",
|
|
" <td>2</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" letters numbers\n",
|
|
"0 A 1\n",
|
|
"1 B 2"
|
|
]
|
|
},
|
|
"execution_count": 55,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"example6.drop_duplicates(['letters'])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "GvX4og1EgRsL"
|
|
},
|
|
"source": [
|
|
"> **အဓိကအချက်:** အတူတူထပ်နေသောဒေတာများကိုဖယ်ရှားခြင်းသည် ဒေတာသိပ္ပံပညာစီမံကိန်းများ၏ အရေးကြီးသောအပိုင်းတစ်ခုဖြစ်သည်။ အတူတူထပ်နေသောဒေတာများသည် သင့်၏ခန့်မှန်းချက်ရလဒ်များကို ပြောင်းလဲစေပြီး မမှန်ကန်သောရလဒ်များကိုရရှိစေနိုင်ပါသည်!\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## အမှန်တကယ်ရှိသော ဒေတာအရည်အသွေး စစ်ဆေးမှုများ\n",
|
|
"\n",
|
|
"> **သင်ယူရည်မှန်းချက်:** ဒီအပိုင်းအဆုံးသတ်ချိန်မှာ အမျိုးအစားတူတူမညီညွတ်သောတန်ဖိုးများ၊ အဆမတန်နံပါတ်တန်ဖိုးများ (outliers)၊ နည်းနည်းကွဲပြားမှုရှိသော အတူတူသောအရာများကို ရှာဖွေပြီး ပြင်ဆင်နိုင်ရန် သင်အဆင်ပြေဖြစ်ရမည်။\n",
|
|
"\n",
|
|
"ပျောက်ဆုံးနေသောတန်ဖိုးများနှင့် တိကျသောအတူတူမှုများသည် အများအားဖြင့်တွေ့ရသောပြဿနာများဖြစ်သော်လည်း အမှန်တကယ်ရှိသောဒေတာများတွင် ပိုမိုသိသာသောပြဿနာများပါဝင်နိုင်သည်။\n",
|
|
"\n",
|
|
"1. **အမျိုးအစားတူတူမညီညွတ်သောတန်ဖိုးများ**: တူညီသောအမျိုးအစားကို အခြားအခြားပုံစံဖြင့် ရေးသားထားခြင်း (ဥပမာ - \"USA\", \"U.S.A\", \"United States\")\n",
|
|
"2. **အဆမတန်နံပါတ်တန်ဖိုးများ**: ဒေတာထည့်သွင်းမှုမှားယွင်းမှုများကို ဖော်ပြသော အလွန်အမင်းသော outliers (ဥပမာ - အသက် = 999)\n",
|
|
"3. **နီးကပ်သောအတူတူသောအတန်းများ**: နည်းနည်းကွဲပြားမှုရှိသော်လည်း တူညီသော entity ကို ကိုယ်စားပြုသော မှတ်တမ်းများ\n",
|
|
"\n",
|
|
"ဒီပြဿနာများကို ရှာဖွေပြီး ကိုင်တွယ်နိုင်ရန် နည်းလမ်းများကို လေ့လာကြမည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### \"ညစ်ပတ်\" ဒေတာစနစ်တစ်ခုကို စမ်းသပ်ဖန်တီးခြင်း\n",
|
|
"\n",
|
|
"ပထမဦးဆုံး၊ အမှန်တကယ်ဒေတာများတွင် မကြုံရခဲသော ပြဿနာအမျိုးမျိုးပါဝင်သော စမ်းသပ်ဒေတာစနစ်တစ်ခုကို ဖန်တီးကြမယ်:\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import pandas as pd\n",
|
|
"import numpy as np\n",
|
|
"\n",
|
|
"# Create a sample dataset with quality issues\n",
|
|
"dirty_data = pd.DataFrame({\n",
|
|
" 'customer_id': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],\n",
|
|
" 'name': ['John Smith', 'Jane Doe', 'John Smith', 'Bob Johnson', \n",
|
|
" 'Alice Williams', 'Charlie Brown', 'John Smith', 'Eva Martinez',\n",
|
|
" 'Bob Johnson', 'Diana Prince', 'Frank Castle', 'Alice Williams'],\n",
|
|
" 'age': [25, 32, 25, 45, 28, 199, 25, 31, 45, 27, -5, 28],\n",
|
|
" 'country': ['USA', 'UK', 'U.S.A', 'Canada', 'USA', 'United Kingdom',\n",
|
|
" 'United States', 'Mexico', 'canada', 'USA', 'UK', 'usa'],\n",
|
|
" 'purchase_amount': [100.50, 250.00, 105.00, 320.00, 180.00, 90.00,\n",
|
|
" 102.00, 275.00, 325.00, 195.00, 410.00, 185.00]\n",
|
|
"})\n",
|
|
"\n",
|
|
"print(\"Sample 'Dirty' Dataset:\")\n",
|
|
"print(dirty_data)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### 1. မတူညီသော အမျိုးအစားတန်ဖိုးများကို ရှာဖွေခြင်း\n",
|
|
"\n",
|
|
"`country` ကော်လံတွင် တစ်နိုင်ငံတည်းအတွက် အမျိုးမျိုးသော ကိုယ်စားပြုမှုများရှိနေသည်ကို သတိပြုပါ။ အဆိုပါ မတူညီမှုများကို ရှာဖွေကြမည်:\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Check unique values in the country column\n",
|
|
"print(\"Unique country values:\")\n",
|
|
"print(dirty_data['country'].unique())\n",
|
|
"print(f\"\\nTotal unique values: {dirty_data['country'].nunique()}\")\n",
|
|
"\n",
|
|
"# Count occurrences of each variation\n",
|
|
"print(\"\\nValue counts:\")\n",
|
|
"print(dirty_data['country'].value_counts())"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"#### Categorized Values များကို စံပြုခြင်း\n",
|
|
"\n",
|
|
"ဤတန်ဖိုးများကို စံပြုရန်အတွက် mapping တစ်ခုကို ဖန်တီးနိုင်ပါသည်။ ရိုးရှင်းသောနည်းလမ်းတစ်ခုမှာ lowercase သို့ ပြောင်းပြီး mapping dictionary တစ်ခုကို ဖန်တီးခြင်းဖြစ်သည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Create a standardization mapping\n",
|
|
"country_mapping = {\n",
|
|
" 'usa': 'USA',\n",
|
|
" 'u.s.a': 'USA',\n",
|
|
" 'united states': 'USA',\n",
|
|
" 'uk': 'UK',\n",
|
|
" 'united kingdom': 'UK',\n",
|
|
" 'canada': 'Canada',\n",
|
|
" 'mexico': 'Mexico'\n",
|
|
"}\n",
|
|
"\n",
|
|
"# Standardize the country column\n",
|
|
"dirty_data['country_clean'] = dirty_data['country'].str.lower().map(country_mapping)\n",
|
|
"\n",
|
|
"print(\"Before standardization:\")\n",
|
|
"print(dirty_data['country'].value_counts())\n",
|
|
"print(\"\\nAfter standardization:\")\n",
|
|
"print(dirty_data[['country_clean']].value_counts())"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"**အခြားနည်းလမ်း: Fuzzy Matching ကို အသုံးပြုခြင်း**\n",
|
|
"\n",
|
|
"ပိုမိုရှုပ်ထွေးသောအခြေအနေများအတွက် `rapidfuzz` စာကြောင်းကိုက်ညီမှု စနစ်ကို အသုံးပြု၍ တူညီသော စာကြောင်းများကို အလိုအလျောက် ရှာဖွေနိုင်ပါသည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"try:\n",
|
|
" from rapidfuzz import process, fuzz\n",
|
|
"except ImportError:\n",
|
|
" print(\"rapidfuzz is not installed. Please install it with 'pip install rapidfuzz' to use fuzzy matching.\")\n",
|
|
" process = None\n",
|
|
" fuzz = None\n",
|
|
"\n",
|
|
"# Get unique countries\n",
|
|
"unique_countries = dirty_data['country'].unique()\n",
|
|
"\n",
|
|
"# For each country, find similar matches\n",
|
|
"if process is not None and fuzz is not None:\n",
|
|
" print(\"Finding similar country names (similarity > 70%):\")\n",
|
|
" for country in unique_countries:\n",
|
|
" matches = process.extract(country, unique_countries, scorer=fuzz.ratio, limit=3)\n",
|
|
" # Filter matches with similarity > 70 and not identical\n",
|
|
" similar = [m for m in matches if m[1] > 70 and m[0] != country]\n",
|
|
" if similar:\n",
|
|
" print(f\"\\n'{country}' is similar to:\")\n",
|
|
" for match, score, _ in similar:\n",
|
|
" print(f\" - '{match}' (similarity: {score}%)\")\n",
|
|
"else:\n",
|
|
" print(\"Skipping fuzzy matching because rapidfuzz is not available.\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### 2. အဆင့်မမှန်သော ကိန်းဂဏန်းတန်ဖိုးများ (Outliers) ကို ရှာဖွေခြင်း\n",
|
|
"\n",
|
|
"`age` ကော်လံကိုကြည့်လိုက်ရင် 199 နဲ့ -5 လို သံသယရှိတဲ့တန်ဖိုးတွေရှိပါတယ်။ ဒီ outliers တွေကို ရှာဖွေဖို့ စာရင်းကိုင်နည်းလမ်းတွေကို အသုံးပြုကြမယ်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Display basic statistics\n",
|
|
"print(\"Age column statistics:\")\n",
|
|
"print(dirty_data['age'].describe())\n",
|
|
"\n",
|
|
"# Identify impossible values using domain knowledge\n",
|
|
"print(\"\\nRows with impossible age values (< 0 or > 120):\")\n",
|
|
"impossible_ages = dirty_data[(dirty_data['age'] < 0) | (dirty_data['age'] > 120)]\n",
|
|
"print(impossible_ages[['customer_id', 'name', 'age']])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"#### IQR (အလယ်တန်းအကွာအဝေး) နည်းလမ်းကို အသုံးပြုခြင်း\n",
|
|
"\n",
|
|
"IQR နည်းလမ်းသည် အလွန်အမင်းတန်ဖိုးများအပေါ် အထူးမထိခိုက်သော အလွန်အမင်းတန်ဖိုးများကို ရှာဖွေဖို့ အသုံးပြုနိုင်သော အဆင့်မြင့် စက်မှုစဉ်နည်းလမ်းတစ်ခုဖြစ်သည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Calculate IQR for age (excluding impossible values)\n",
|
|
"valid_ages = dirty_data[(dirty_data['age'] >= 0) & (dirty_data['age'] <= 120)]['age']\n",
|
|
"\n",
|
|
"Q1 = valid_ages.quantile(0.25)\n",
|
|
"Q3 = valid_ages.quantile(0.75)\n",
|
|
"IQR = Q3 - Q1\n",
|
|
"\n",
|
|
"# Define outlier bounds\n",
|
|
"lower_bound = Q1 - 1.5 * IQR\n",
|
|
"upper_bound = Q3 + 1.5 * IQR\n",
|
|
"\n",
|
|
"print(f\"IQR-based outlier bounds for age: [{lower_bound:.2f}, {upper_bound:.2f}]\")\n",
|
|
"\n",
|
|
"# Identify outliers\n",
|
|
"age_outliers = dirty_data[(dirty_data['age'] < lower_bound) | (dirty_data['age'] > upper_bound)]\n",
|
|
"print(f\"\\nRows with age outliers:\")\n",
|
|
"print(age_outliers[['customer_id', 'name', 'age']])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"#### Z-Score နည်းလမ်းကို အသုံးပြုခြင်း\n",
|
|
"\n",
|
|
"Z-score နည်းလမ်းသည် အလယ်တန်းတန်ဖိုးမှ စံအလျားချိုးများအပေါ် အခြေခံ၍ ထူးခြားသောတန်ဖိုးများကို ဖော်ထုတ်သည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"try:\n",
|
|
" from scipy import stats\n",
|
|
"except ImportError:\n",
|
|
" print(\"scipy is required for Z-score calculation. Please install it with 'pip install scipy' and rerun this cell.\")\n",
|
|
"else:\n",
|
|
" # Calculate Z-scores for age, handling NaN values\n",
|
|
" age_nonan = dirty_data['age'].dropna()\n",
|
|
" zscores = np.abs(stats.zscore(age_nonan))\n",
|
|
" dirty_data['age_zscore'] = np.nan\n",
|
|
" dirty_data.loc[age_nonan.index, 'age_zscore'] = zscores\n",
|
|
"\n",
|
|
" # Typically, Z-score > 3 indicates an outlier\n",
|
|
" print(\"Rows with age Z-score > 3:\")\n",
|
|
" zscore_outliers = dirty_data[dirty_data['age_zscore'] > 3]\n",
|
|
" print(zscore_outliers[['customer_id', 'name', 'age', 'age_zscore']])\n",
|
|
"\n",
|
|
" # Clean up the temporary column\n",
|
|
" dirty_data = dirty_data.drop('age_zscore', axis=1)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"#### အထူးအချက်များကို ကိုင်တွယ်ခြင်း\n",
|
|
"\n",
|
|
"အထူးအချက်များကို ရှာဖွေတွေ့ရှိပြီးနောက်၊ အောက်ပါနည်းလမ်းများဖြင့် ကိုင်တွယ်နိုင်ပါသည်။\n",
|
|
"1. **ဖယ်ရှား**: အမှားဖြစ်သော အထူးအချက်များပါဝင်သော အတန်းများကို ဖယ်ရှားပါ။\n",
|
|
"2. **အကန့်အသတ်ထား**: အကန့်အသတ်တန်ဖိုးများဖြင့် အစားထိုးပါ။\n",
|
|
"3. **NaN ဖြင့် အစားထိုး**: မရှိသော ဒေတာအဖြစ် ဆက်ဆံပြီး အစားထိုးနည်းလမ်းများကို အသုံးပြုပါ။\n",
|
|
"4. **ထားရှိထား**: အထူးအချက်များသည် တရားဝင်သော extrême တန်ဖိုးများဖြစ်ပါက ထားရှိပါ။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Create a cleaned version by replacing impossible ages with NaN\n",
|
|
"dirty_data['age_clean'] = dirty_data['age'].apply(\n",
|
|
" lambda x: np.nan if (x < 0 or x > 120) else x\n",
|
|
")\n",
|
|
"\n",
|
|
"print(\"Age column before and after cleaning:\")\n",
|
|
"print(dirty_data[['customer_id', 'name', 'age', 'age_clean']])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### 3. နီးကပ်သော အတူတူသော အတန်းများကို ရှာဖွေခြင်း\n",
|
|
"\n",
|
|
"ကျွန်ုပ်တို့၏ ဒေတာစနစ်တွင် \"John Smith\" အတွက် အနည်းငယ်ကွဲပြားသော တန်ဖိုးများနှင့်အတူ အများအပြား အဝင်များရှိသည်ကို သတိပြုပါ။ နာမည်တူညီမှုအပေါ် အခြေခံပြီး များစွာသော အတူတူသော အတန်းများကို ရှာဖွေကြမည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# First, let's look at exact name matches (ignoring extra whitespace)\n",
|
|
"dirty_data['name_normalized'] = dirty_data['name'].str.strip().str.lower()\n",
|
|
"\n",
|
|
"print(\"Checking for duplicate names:\")\n",
|
|
"duplicate_names = dirty_data[dirty_data.duplicated(['name_normalized'], keep=False)]\n",
|
|
"print(duplicate_names.sort_values('name_normalized')[['customer_id', 'name', 'age', 'country']])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"#### နီးစပ်သော အတူတူသောအရာများကို Fuzzy Matching ဖြင့် ရှာဖွေခြင်း\n",
|
|
"\n",
|
|
"ပိုမိုတိုးတက်သော အတူတူသောအရာများကို ရှာဖွေရန်အတွက် Fuzzy Matching ကို အသုံးပြု၍ နီးစပ်သော နာမည်များကို ရှာဖွေနိုင်ပါသည်။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"try:\n",
|
|
" from rapidfuzz import process, fuzz\n",
|
|
"\n",
|
|
" # Function to find potential duplicates\n",
|
|
" def find_near_duplicates(df, column, threshold=90):\n",
|
|
" \"\"\"\n",
|
|
" Find near-duplicate entries in a column using fuzzy matching.\n",
|
|
" \n",
|
|
" Parameters:\n",
|
|
" - df: DataFrame\n",
|
|
" - column: Column name to check for duplicates\n",
|
|
" - threshold: Similarity threshold (0-100)\n",
|
|
" \n",
|
|
" Returns: List of potential duplicate groups\n",
|
|
" \"\"\"\n",
|
|
" values = df[column].unique()\n",
|
|
" duplicate_groups = []\n",
|
|
" checked = set()\n",
|
|
" \n",
|
|
" for value in values:\n",
|
|
" if value in checked:\n",
|
|
" continue\n",
|
|
" \n",
|
|
" # Find similar values\n",
|
|
" matches = process.extract(value, values, scorer=fuzz.ratio, limit=len(values))\n",
|
|
" similar = [m[0] for m in matches if m[1] >= threshold]\n",
|
|
" \n",
|
|
" if len(similar) > 1:\n",
|
|
" duplicate_groups.append(similar)\n",
|
|
" checked.update(similar)\n",
|
|
" \n",
|
|
" return duplicate_groups\n",
|
|
"\n",
|
|
" # Find near-duplicate names\n",
|
|
" duplicate_groups = find_near_duplicates(dirty_data, 'name', threshold=90)\n",
|
|
"\n",
|
|
" print(\"Potential duplicate groups:\")\n",
|
|
" for i, group in enumerate(duplicate_groups, 1):\n",
|
|
" print(f\"\\nGroup {i}:\")\n",
|
|
" for name in group:\n",
|
|
" matching_rows = dirty_data[dirty_data['name'] == name]\n",
|
|
" print(f\" '{name}': {len(matching_rows)} occurrence(s)\")\n",
|
|
" for _, row in matching_rows.iterrows():\n",
|
|
" print(f\" - Customer {row['customer_id']}: age={row['age']}, country={row['country']}\")\n",
|
|
"except ImportError:\n",
|
|
" print(\"rapidfuzz is not installed. Skipping fuzzy matching for near-duplicates.\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"#### အတူတူဖြစ်သောအရာများကို ကိုင်တွယ်ခြင်း\n",
|
|
"\n",
|
|
"အတူတူဖြစ်သောအရာများကို ရှာဖွေတွေ့ရှိပြီးနောက်၊ အောက်ပါနည်းလမ်းများဖြင့် ကိုင်တွယ်ရန် ဆုံးဖြတ်ရမည်။\n",
|
|
"1. **ပထမဆုံးတွေ့ရှိမှုကို ထားရှိရန်**: `drop_duplicates(keep='first')` ကို အသုံးပြုပါ\n",
|
|
"2. **နောက်ဆုံးတွေ့ရှိမှုကို ထားရှိရန်**: `drop_duplicates(keep='last')` ကို အသုံးပြုပါ\n",
|
|
"3. **အချက်အလက်များကို စုပေါင်းရန်**: အတူတူဖြစ်သော အတန်းများမှ အချက်အလက်များကို ပေါင်းစည်းပါ\n",
|
|
"4. **လူ့အကဲဖြတ်မှု**: လူ့အကဲဖြတ်မှုအတွက် အမှတ်အသားပြုထားပါ\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Example: Remove duplicates based on normalized name, keeping first occurrence\n",
|
|
"cleaned_data = dirty_data.drop_duplicates(subset=['name_normalized'], keep='first')\n",
|
|
"\n",
|
|
"print(f\"Original dataset: {len(dirty_data)} rows\")\n",
|
|
"print(f\"After removing name duplicates: {len(cleaned_data)} rows\")\n",
|
|
"print(f\"Removed: {len(dirty_data) - len(cleaned_data)} duplicate rows\")\n",
|
|
"\n",
|
|
"print(\"\\nCleaned dataset:\")\n",
|
|
"print(cleaned_data[['customer_id', 'name', 'age', 'country_clean']])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### အကျဉ်းချုပ် - အပြည့်အစုံသော ဒေတာသန့်စင်ရေးပိုင်းဆိုင်ရာလုပ်ငန်းစဉ်\n",
|
|
"\n",
|
|
"အခုတော့ ဒေတာသန့်စင်ရေးလုပ်ငန်းစဉ်ကို အပြည့်အစုံအဖြစ် စုပေါင်းပြီး တစ်ခုတည်းအဖြစ် ဖော်ဆောင်ကြမယ်:\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"def clean_dataset(df):\n",
|
|
" \"\"\"\n",
|
|
" Comprehensive data cleaning function.\n",
|
|
" \"\"\"\n",
|
|
" # Create a copy to avoid modifying the original\n",
|
|
" cleaned = df.copy()\n",
|
|
" \n",
|
|
" # 1. Standardize categorical values (country)\n",
|
|
" country_mapping = {\n",
|
|
" 'usa': 'USA', 'u.s.a': 'USA', 'united states': 'USA',\n",
|
|
" 'uk': 'UK', 'united kingdom': 'UK',\n",
|
|
" 'canada': 'Canada', 'mexico': 'Mexico'\n",
|
|
" }\n",
|
|
" cleaned['country'] = cleaned['country'].str.lower().map(country_mapping)\n",
|
|
" \n",
|
|
" # 2. Clean abnormal age values\n",
|
|
" cleaned['age'] = cleaned['age'].apply(\n",
|
|
" lambda x: np.nan if (x < 0 or x > 120) else x\n",
|
|
" )\n",
|
|
" \n",
|
|
" # 3. Remove near-duplicate names (normalize whitespace)\n",
|
|
" cleaned['name'] = cleaned['name'].str.strip()\n",
|
|
" cleaned = cleaned.drop_duplicates(subset=['name'], keep='first')\n",
|
|
" \n",
|
|
" return cleaned\n",
|
|
"\n",
|
|
"# Apply the cleaning pipeline\n",
|
|
"final_cleaned_data = clean_dataset(dirty_data)\n",
|
|
"\n",
|
|
"print(\"Before cleaning:\")\n",
|
|
"print(f\" Rows: {len(dirty_data)}\")\n",
|
|
"print(f\" Unique countries: {dirty_data['country'].nunique()}\")\n",
|
|
"print(f\" Invalid ages: {((dirty_data['age'] < 0) | (dirty_data['age'] > 120)).sum()}\")\n",
|
|
"\n",
|
|
"print(\"\\nAfter cleaning:\")\n",
|
|
"print(f\" Rows: {len(final_cleaned_data)}\")\n",
|
|
"print(f\" Unique countries: {final_cleaned_data['country'].nunique()}\")\n",
|
|
"print(f\" Invalid ages: {((final_cleaned_data['age'] < 0) | (final_cleaned_data['age'] > 120)).sum()}\")\n",
|
|
"\n",
|
|
"print(\"\\nCleaned dataset:\")\n",
|
|
"print(final_cleaned_data[['customer_id', 'name', 'age', 'country', 'purchase_amount']])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### 🎯 စိန်ခေါ်မှုလေ့ကျင့်ခန်း\n",
|
|
"\n",
|
|
"အခုတော့ သင့်အလှည့်ပါ! အောက်မှာ အရည်အသွေးပြဿနာများစွာပါဝင်တဲ့ ဒေတာတစ်တန်းအသစ်ရှိပါတယ်။ သင်လုပ်နိုင်မလား:\n",
|
|
"\n",
|
|
"1. ဒီတန်းမှာရှိတဲ့ ပြဿနာအားလုံးကို ဖော်ထုတ်ပါ\n",
|
|
"2. ပြဿနာတစ်ခုချင်းစီကို သန့်ရှင်းစေရန် ကုဒ်ရေးပါ\n",
|
|
"3. သန့်ရှင်းပြီးတဲ့ ဒေတာတန်းကို dataset ထဲမှာ ထည့်ပါ\n",
|
|
"\n",
|
|
"ဒီမှာ ပြဿနာရှိတဲ့ ဒေတာတွေရှိပါတယ်:\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# New problematic row\n",
|
|
"new_row = pd.DataFrame({\n",
|
|
" 'customer_id': [13],\n",
|
|
" 'name': [' Diana Prince '], # Extra whitespace\n",
|
|
" 'age': [250], # Impossible age\n",
|
|
" 'country': ['U.S.A.'], # Inconsistent format\n",
|
|
" 'purchase_amount': [150.00]\n",
|
|
"})\n",
|
|
"\n",
|
|
"print(\"New row to clean:\")\n",
|
|
"print(new_row)\n",
|
|
"\n",
|
|
"# TODO: Your code here to clean this row\n",
|
|
"# Hints:\n",
|
|
"# 1. Strip whitespace from the name\n",
|
|
"# 2. Check if the name is a duplicate (Diana Prince already exists)\n",
|
|
"# 3. Handle the impossible age value\n",
|
|
"# 4. Standardize the country name\n",
|
|
"\n",
|
|
"# Example solution (uncomment and modify as needed):\n",
|
|
"# new_row_cleaned = new_row.copy()\n",
|
|
"# new_row_cleaned['name'] = new_row_cleaned['name'].str.strip()\n",
|
|
"# new_row_cleaned['age'] = np.nan # Invalid age\n",
|
|
"# new_row_cleaned['country'] = 'USA' # Standardized\n",
|
|
"# print(\"\\nCleaned row:\")\n",
|
|
"# print(new_row_cleaned)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### အဓိကအချက်များ\n",
|
|
"\n",
|
|
"1. **အမျိုးအစားများ မညီညွတ်မှု** သည် အမှန်တကယ်ရှိသော ဒေတာများတွင် မကြာခဏတွေ့ရသည်။ တန်ဖိုးများကို ထူးခြားစွာ စစ်ဆေးပြီး မျှတစွာ စနစ်တကျပြင်ဆင်ရန် mapping သို့မဟုတ် fuzzy matching ကို အသုံးပြုပါ။\n",
|
|
"\n",
|
|
"2. **Outliers** သည် သင့်အနုစိတ်ခွဲခြမ်းစိတ်ဖြာမှုကို အလွန်အကျွံ သက်ရောက်စေနိုင်သည်။ အထူးကျွမ်းကျင်မှုနှင့် စာရင်းအင်းနည်းလမ်းများ (IQR, Z-score) ကို ပေါင်းစပ်အသုံးပြု၍ Outliers ကို ရှာဖွေပါ။\n",
|
|
"\n",
|
|
"3. **နီးကပ်သော အတူတူများ** ကို တိကျသော အတူတူများထက် ရှာဖွေဖို့ ပိုခက်သည်။ Fuzzy matching နှင့် ဒေတာကို အဆင်ပြေစွာ ပြင်ဆင်ခြင်း (lowercasing, whitespace ဖယ်ရှားခြင်း) ကို အသုံးပြု၍ ရှာဖွေပါ။\n",
|
|
"\n",
|
|
"4. **ဒေတာသန့်စင်ခြင်းသည် အဆင့်ဆင့်ဖြစ်သည်**။ သင့်ဒေတာသန့်စင်ပြီးဆုံးရန် မတူညီသောနည်းလမ်းများကို အသုံးပြုပြီး ရလဒ်များကို ပြန်လည်သုံးသပ်ရန် လိုအပ်နိုင်သည်။\n",
|
|
"\n",
|
|
"5. **သင့်ဆုံးဖြတ်ချက်များကို မှတ်တမ်းတင်ပါ**။ သင့်သန့်စင်ခြင်းအဆင့်များကို ဘာကြောင့်အသုံးပြုခဲ့သည်ဆိုတာ အလင်းပြထားရန်၊ ပြန်လုပ်နိုင်မှုနှင့် ထင်ရှားမှုအတွက် အရေးကြီးသည်။\n",
|
|
"\n",
|
|
"> **အကောင်းဆုံးအလေ့အကျင့်:** သင့်ရဲ့ မူရင်း \"ညစ်ပတ်နေသော\" ဒေတာကို အမြဲတမ်း မိတိတက်ထားပါ။ မူရင်းဒေတာဖိုင်များကို မဖျက်ပါနှင့် - `data_cleaned.csv` ကဲ့သို့သော အမည်ပေးနည်းလမ်းများဖြင့် သန့်စင်ထားသောဗားရှင်းများကို ဖန်တီးပါ။\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"\n---\n\n**အကြောင်းကြားချက်**: \nဤစာရွက်စာတမ်းကို AI ဘာသာပြန်ဝန်ဆောင်မှု [Co-op Translator](https://github.com/Azure/co-op-translator) ကို အသုံးပြု၍ ဘာသာပြန်ထားပါသည်။ ကျွန်ုပ်တို့သည် တိကျမှုအတွက် ကြိုးစားနေသော်လည်း အလိုအလျောက် ဘာသာပြန်မှုများတွင် အမှားများ သို့မဟုတ် မမှန်ကန်မှုများ ပါဝင်နိုင်သည်ကို သတိပြုပါ။ မူရင်းဘာသာစကားဖြင့် ရေးသားထားသော စာရွက်စာတမ်းကို အာဏာတရ အရင်းအမြစ်အဖြစ် သတ်မှတ်သင့်ပါသည်။ အရေးကြီးသော အချက်အလက်များအတွက် လူက ဘာသာပြန်မှုကို အကြံပြုပါသည်။ ဤဘာသာပြန်မှုကို အသုံးပြုခြင်းမှ ဖြစ်ပေါ်လာသော အလွဲအမှားများ သို့မဟုတ် အနားလွဲမှုများအတွက် ကျွန်ုပ်တို့သည် တာဝန်မယူပါ။\n"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"anaconda-cloud": {},
|
|
"colab": {
|
|
"name": "notebook.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.5.4"
|
|
},
|
|
"coopTranslator": {
|
|
"original_hash": "6301339d1c9a301b00639c635dc9b731",
|
|
"translation_date": "2025-10-03T21:20:19+00:00",
|
|
"source_file": "2-Working-With-Data/08-data-preparation/notebook.ipynb",
|
|
"language_code": "my"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 0
|
|
} |