{ "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 ရှိနေခဲ့ရင်, သင်လုပ်နေတဲ့အရာကို ဘယ်လို စတင်နားလည်ရမလဲ? ကံကောင်းစွာ, pandas ဟာ `DataFrame` တစ်ခုရဲ့ အထွေထွေ အချက်အလက်တွေကို အလျင်အမြန် ကြည့်ရှုနိုင်ဖို့ အဆင်ပြေတဲ့ ကိရိယာတွေကို ပံ့ပိုးပေးထားပါတယ်။ ဒါ့အပြင်, ရှေ့ဆုံးအတန်းအချို့နဲ့ နောက်ဆုံးအတန်းအချို့ကိုလည်း မြင်နိုင်ပါတယ်။\n", "\n", "ဒီလုပ်ဆောင်ချက်ကို စူးစမ်းဖို့အတွက်, Python scikit-learn library ကို import လုပ်ပြီး, ဒေတာသိပ္ပံပညာရှင်တိုင်း သိပြီးသား dataset တစ်ခုကို အသုံးပြုပါမယ်။ ဒါကတော့ 1936 ခုနှစ်မှာ ဗြိတိသျှ ဇီဝဗေဒပညာရှင် Ronald Fisher ရေးသားခဲ့တဲ့ \"The use of multiple measurements in taxonomic problems\" စာတမ်းမှာ အသုံးပြုခဲ့တဲ့ *Iris* ဒေတာစနစ် ဖြစ်ပါတယ်။\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 က ဒေတာစုပေါင်းတစ်ခုမှာပါဝင်တဲ့ features တွေကိုဖော်ထုတ်ချင်တဲ့အခါမှာ အရေးကြီးလာပါတယ်။\n" ] }, { "cell_type": "markdown", "metadata": { "id": "2UTlvkjmgRrs" }, "source": [ "### `DataFrame.info`\n", "ဒေတာပမာဏ (`shape` attribute မှပေးထားသည်) နှင့် feature များ သို့မဟုတ် column များ၏အမည်များ (`columns` attribute မှပေးထားသည်) သည် dataset အကြောင်းအချို့ကို ပြောပြပေးသည်။ အခုတော့ dataset ကို ပိုမိုနက်နက်ရှိုင်းရှိုင်း လေ့လာလိုပါသည်။ `DataFrame.info()` function သည် အလွန်အသုံးဝင်သော 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": [ "\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", "\n", "1. ကော်လံတစ်ခုချင်းစီရဲ့ DataType: ဒီဒေတာအစုအဝေးမှာ ဒေတာအားလုံးကို 64-bit floating-point နံပါတ်အနေနဲ့ သိမ်းဆည်းထားပါတယ်။\n", "2. Non-Null အတန်းအရေအတွက်: Null တန်ဖိုးတွေကို ကိုင်တွယ်ဖို့က ဒေတာပြင်ဆင်မှုအဆင့်မှာ အရေးကြီးတဲ့အဆင့်တစ်ခုဖြစ်ပါတယ်။ ဒါကို နောက်ပိုင်း notebook မှာ ကိုင်တွယ်သွားမှာဖြစ်ပါတယ်။\n" ] }, { "cell_type": "markdown", "metadata": { "id": "IYlyxbpWFEF4" }, "source": [ "### DataFrame.describe()\n", "ကျွန်တော်တို့ dataset မှာ ကိန်းဂဏန်းအချက်အလက်များ များစွာရှိတယ်လို့ ဆိုပါစို့။ mean, median, quartiles စတဲ့ တစ်ခုချင်းစီ column တွေမှာ univariate စာရင်းဇယားတွက်ချက်မှုတွေကို ပြုလုပ်နိုင်ပါတယ်။ `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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
sepal length (cm)sepal width (cm)petal length (cm)petal width (cm)
count150.000000150.000000150.000000150.000000
mean5.8433333.0573333.7580001.199333
std0.8280660.4358661.7652980.762238
min4.3000002.0000001.0000000.100000
25%5.1000002.8000001.6000000.300000
50%5.8000003.0000004.3500001.300000
75%6.4000003.3000005.1000001.800000
max7.9000004.4000006.9000002.500000
\n", "
" ], "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 ရဲ့ အထက်ဆုံးအခြေအနေကို ကြည့်ရှုနိုင်ပါပြီ။ ဒေတာအချက်အလက်များ ဘယ်လောက်ရှိသလဲ၊ feature များ ဘယ်နှစ်ခုရှိသလဲ၊ feature တစ်ခုချင်းစီရဲ့ data type ဘယ်လိုလဲ၊ feature တစ်ခုချင်းစီမှာ null မဟုတ်တဲ့ အချက်အလက်အရေအတွက် ဘယ်လောက်ရှိသလဲဆိုတာကို သိရှိနိုင်ပါပြီ။\n", "\n", "အခုတော့ ဒေတာကို ကိုယ်တိုင်ကြည့်မယ့်အချိန်ရောက်ပါပြီ။ `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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
sepal length (cm)sepal width (cm)petal length (cm)petal width (cm)
05.13.51.40.2
14.93.01.40.2
24.73.21.30.2
34.63.11.50.2
45.03.61.40.2
\n", "
" ], "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` ရဲ့ ပထမဆုံးအတန်း ၅ ခုကို ပြန်ပေးတယ်ဆိုတာ ရှင်းလင်းပါတယ်။ အောက်မှာရှိတဲ့ ကုဒ်ဆဲလ်မှာ၊ အတန်း ၅ ခုထက် ပိုမိုပြသနိုင်တဲ့ နည်းလမ်းကို ရှာဖွေနိုင်မလား?\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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
sepal length (cm)sepal width (cm)petal length (cm)petal width (cm)
1456.73.05.22.3
1466.32.55.01.9
1476.53.05.22.0
1486.23.45.42.3
1495.93.05.11.8
\n", "
" ], "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": [ "အလေ့အထ၏အရ၊ အစီအစဉ်တစ်ခုတွင် အစောပိုင်းအတန်းများ သို့မဟုတ် နောက်ဆုံးအတန်းများကို လွယ်ကူစွာ ကြည့်ရှုနိုင်ခြင်းသည် အထူးသဖြင့် အစီအစဉ်တစ်ခုတွင် အစီအစဉ်ထားသော ဒေတာများတွင် အထူးသဖြင့် အထူးအချက်အလက်များ (outliers) ကို ရှာဖွေလိုသောအခါ အထောက်အကူဖြစ်သည်။\n", "\n", "အထက်တွင် ဖော်ပြထားသည့် function များနှင့် attribute များအားလုံးကို ကုဒ်ဥပမာများဖြင့် ဖော်ပြထားပြီး၊ ဒေတာ၏ ပုံစံနှင့် အကြောင်းအရာကို နားလည်ရန် ကူညီပေးသည်။\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 မှလာသောကြောင့်၊ ဒါကို NumPy နှင့် pandas ၏ `'object'` data type မဟုတ်သော arrays တွင် အသုံးမပြုနိုင်ပါ။ သတိပြုပါ၊ NumPy arrays (နှင့် pandas ၏ data structures) တွင် တစ်မျိုးတည်းသော data type ကိုသာ ပါဝင်နိုင်သည်။ ဒါက သူတို့ကို အကြီးစား data နှင့် ကွန်ပျူတာဆိုင်ရာ အလုပ်များအတွက် အလွန်အစွမ်းထက်စေသော်လည်း၊ flexibility ကို ကန့်သတ်စေသည်။ အဲဒီလို arrays တွေဟာ “အနိမ့်ဆုံး ပေါင်းစည်းနိုင်သော အမျိုးအစား” (lowest common denominator) သို့ အမျိုးအစားကို အလိုအလျောက် ပြောင်းလဲရမည်ဖြစ်သည်၊ ဒါကတော့ array ထဲမှာရှိသမျှကို အုပ်စည်းနိုင်မည့် 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` တန်ဖိုးပါဝင်သော အစုအဝေးများတွင် အသုံးပြုပါက ပုံမှန်အားဖြင့် အမှားတစ်ခုကို ဖြစ်ပေါ်စေမည်ဖြစ်သည်-\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\u001b[0m in \u001b[0;36m\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": [] }, { "cell_type": "markdown", "metadata": { "id": "pWvVHvETgRr9" }, "source": [ "### `NaN`: မရှိသော float တန်ဖိုးများ\n", "\n", "`None` နှင့်မတူဘဲ၊ NumPy (နှင့် pandas) သည် ၎င်း၏ အမြန်နှုန်းမြင့်သော၊ ဗက်တာအခြေပြု လုပ်ဆောင်မှုများနှင့် ufuncs များအတွက် `NaN` ကို ပံ့ပိုးပေးပါသည်။ သတင်းမကောင်းကတော့ `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` ပါဝင်တဲ့ အရေအတွက်များပေါ်မှာ aggregation များကို လုပ်ဆောင်တဲ့အခါ အမှားများ မပေါက်ဖွားပါဘူး။ သတင်းဆိုးကတော့ ရလဒ်များသည် တစ်သမတ်တည်း အသုံးဝင်မှု မရှိကြောင်း ဖြစ်ပါတယ်။\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": [] }, { "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": [] }, { "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": [] }, { "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": [ "### မရှိသောတန်ဖိုးများကို ရှာဖွေခြင်း\n", "\n", "မရှိသောတန်ဖိုးများ၏ အရေးပါမှုကို နားလည်ပြီးနောက်၊ အရင်ဆုံး မရှိသောတန်ဖိုးများကို ကျွန်ုပ်တို့၏ဒေတာအစုတွင် ရှာဖွေဖို့ လိုအပ်ပါသည်။ \n", "`isnull()` နှင့် `notnull()` နှစ်ခုစလုံးသည် မရှိသောဒေတာကို ရှာဖွေဖို့ အဓိကနည်းလမ်းများဖြစ်သည်။ \n", "နှစ်ခုစလုံးသည် သင့်ဒေတာအပေါ် 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": [ "အောက်ပါအကြောင်းအရာကို မြန်မာဘာသာဖြင့် ဘာသာပြန်ထားသည် -\n", "\n", "အထက်ပါအချက်များကို သေချာစွာကြည့်ပါ။ `0` သည် သင်္ချာဆိုင်ရာ null ဖြစ်သော်လည်း၊ ၎င်းသည် ကောင်းမွန်သော အပြည့်အဝ integer တစ်ခုဖြစ်ပြီး pandas က ၎င်းကို ထိုသို့ပင် သတ်မှတ်သည်။ `''` သည် နည်းနည်းပိုမိုနက်နဲသည်။ ကျွန်ုပ်တို့သည် ၎င်းကို အပိုင်း ၁ တွင် အလွတ်စကားကြောင်းတန်ဖိုးကို ကိုယ်စားပြုရန် အသုံးပြုခဲ့သော်လည်း၊ ၎င်းသည် string object တစ်ခုဖြစ်ပြီး pandas အရ null ကို ကိုယ်စားပြုသောအရာမဟုတ်ပါ။\n", "\n", "ယခု၊ ဤအရာကို ပြောင်းလဲပြီး သင်အလေ့အကျင့်အဖြစ် အသုံးပြုမည့် နည်းလမ်းများဖြင့် အသုံးပြုကြည့်ပါ။ သင်သည် Boolean masks ကို တိုက်ရိုက် ``Series`` သို့မဟုတ် ``DataFrame`` index အဖြစ် အသုံးပြုနိုင်ပြီး၊ ၎င်းသည် အထီးကျန်နေသော (သို့မဟုတ် ရှိနေသော) တန်ဖိုးများနှင့် အလုပ်လုပ်ရန် အသုံးဝင်နိုင်သည်။\n", "\n", "ကျွန်ုပ်တို့ Missing Values အရေအတွက်စုစုပေါင်းကို သိလိုပါက၊ `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": [] }, { "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": [] }, { "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 တန်ဖိုးများကို ဖယ်ရှားခြင်းက ဒေတာပွင့်များအရေအတွက်ကို လျှော့ချတာဖြစ်ပြီး ဒေတာအစုအဝေးရဲ့ အရွယ်အစားကိုလည်း လျှော့ချတာဖြစ်ပါတယ်။ ဒါကြောင့် ဒေတာအစုအဝေးက အလွန်ကြီးမားတဲ့အခါ 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 များကို indexing လုပ်တာအစား၊ `dropna` က `Series` `example3` ထဲမှ ပျောက်ဆုံးနေသော အချက်အလက်များကို ဖယ်ရှားလိုက်ခြင်းဖြစ်သည်။\n", "\n", "DataFrames တွင် အတိုင်းအတာနှစ်ခုရှိသောကြောင့်၊ အချက်အလက်များကို ဖယ်ရှားရန် အခြားရွေးချယ်စရာများ ပိုမိုရရှိနိုင်ပါသည်။\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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
012
01.0NaN7
12.05.08
2NaN6.09
\n", "
" ], "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 လုပ်လို့မရပါဘူး၊ ဒါကြောင့် အတန်းတစ်ခုလုံး သို့မဟုတ် ကော်လံတစ်ခုလုံးကို drop လုပ်ရမည်ဖြစ်သည်။ သင်လုပ်ဆောင်လိုသောအရာပေါ်မူတည်ပြီး၊ တစ်ခု သို့မဟုတ် တစ်ခုကိုရွေးချယ်နိုင်ပြီး pandas က နှစ်မျိုးလုံးအတွက် ရွေးချယ်စရာများပေးထားသည်။ ဒေတာသိပ္ပံတွင် ကော်လံများသည် အများအားဖြင့် variable များကို ကိုယ်စားပြုပြီး အတန်းများသည် observation များကို ကိုယ်စားပြုသောကြောင့်၊ သင်အတန်းများကို ပိုမိုများစွာ drop လုပ်နိုင်သည်။ `dropna()` ၏ default setting သည် null value များပါဝင်သော အတန်းအားလုံးကို 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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
012
12.05.08
\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
2
07
18
29
\n", "
" ], "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": [ "ဤသည် သင့်ရဲ့ dataset တွေထဲမှာ အချက်အလက်များကို အများကြီးပျောက်ဆုံးစေနိုင်ပါတယ်၊ အထူးသဖြင့် dataset သေးငယ်တဲ့အခါမှာ။ ဒါပေမယ့် သင့်ရဲ့ dataset ထဲမှာ null value အများကြီးပါဝင်တဲ့ rows သို့မဟုတ် columns တွေကိုပဲ drop လုပ်ချင်ရင်ရော ဘာလုပ်မလဲ? `dropna` function ရဲ့ `how` နဲ့ `thresh` parameters တွေကို သတ်မှတ်နိုင်ပါတယ်။\n", "\n", "ပုံမှန်အားဖြင့် `how='any'` သတ်မှတ်ထားပါတယ် (သင့်ကိုယ်တိုင်စစ်ဆေးချင်ရင် သို့မဟုတ် method ရဲ့ အခြား parameters တွေကိုကြည့်ချင်ရင် `example4.dropna?` ကို code cell မှာ run လုပ်ပါ။) အခြားနည်းလမ်းတစ်ခုအနေနဲ့ `how='all'` ကို သတ်မှတ်နိုင်ပါတယ်၊ ဒါက null value အားလုံးပါဝင်တဲ့ rows သို့မဟုတ် columns တွေကိုပဲ drop လုပ်မှာဖြစ်ပါတယ်။ အောက်ပါ 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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
0123
01.0NaN7NaN
12.05.08NaN
2NaN6.09NaN
\n", "
" ], "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. `DataFrame.dropna(axis=)` method သည် Null အချက်အလက်များကို ဖယ်ရှားရန် အထောက်အကူပြုသည်။ `axis` argument သည် အတန်းများကို ဖယ်ရှားမည်လား၊ ကော်လံများကို ဖယ်ရှားမည်လား ဆိုသည်ကို ဖော်ပြသည်။\n", "4. `how` argument ကိုလည်း အသုံးပြုနိုင်သည်။ ပုံမှန်အားဖြင့် ၎င်းကို `any` အဖြစ် သတ်မှတ်ထားသည်။ ထို့ကြောင့် Null အချက်အလက်များ ပါဝင်သော အတန်း/ကော်လံများကိုသာ ဖယ်ရှားသည်။ ၎င်းကို `all` အဖြစ် သတ်မှတ်နိုင်ပြီး Null အချက်အလက်များသာ ပါဝင်သော အတန်း/ကော်လံများကိုသာ ဖယ်ရှားမည်ဟု သတ်မှတ်နိုင်သည်။\n" ] }, { "cell_type": "markdown", "metadata": { "id": "oXXSfQFHgRsF" }, "source": [] }, { "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
0123
12.05.08NaN
\n", "
" ], "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": [] }, { "cell_type": "markdown", "metadata": { "id": "mCcxLGyUgRsG" }, "source": [ "### အချိုးအစားမရှိသော တန်ဖိုးများ ဖြည့်ခြင်း\n", "\n", "တစ်ခါတစ်ရံမှာ အချိုးအစားမရှိတဲ့ တန်ဖိုးတွေကို သင့်တော်တဲ့ တန်ဖိုးတွေနဲ့ ဖြည့်သွင်းတာဟာ make sense ဖြစ်တတ်ပါတယ်။ အချိုးအစားမရှိတဲ့ တန်ဖိုးတွေကို ဖြည့်သွင်းဖို့ နည်းလမ်းအချို့ ရှိပါတယ်။ ပထမနည်းလမ်းကတော့ Domain Knowledge (ဒေတာဆက်စပ်တဲ့ အကြောင်းအရာပေါ်မှာ အခြေခံထားတဲ့ အသိပညာ) ကို အသုံးပြုပြီး အချိုးအစားမရှိတဲ့ တန်ဖိုးတွေကို ခန့်မှန်းဖြည့်သွင်းတာ ဖြစ်ပါတယ်။\n", "\n", "ဒီလိုလုပ်ဖို့ `isnull` ကို သုံးနိုင်ပေမယ့် ဒါဟာ အလုပ်ရှုပ်တတ်ပါတယ်၊ အထူးသဖြင့် ဖြည့်ရမယ့် တန်ဖိုးတွေ များများရှိရင် ပိုပြီး အလုပ်ရှုပ်နိုင်ပါတယ်။ ဒေတာသိပ္ပံမှာ ဒီလိုအလုပ်ဟာ အလွန်ရိုးရိုးရှင်းရှင်း ဖြစ်တဲ့အတွက် pandas က `fillna` ကို ပံ့ပိုးပေးထားပါတယ်။ ဒါကတော့ သင့်ရဲ့ `Series` သို့မဟုတ် `DataFrame` ကို ကူးယူပြီး အချိုးအစားမရှိတဲ့ တန်ဖိုးတွေကို သင့်စိတ်ကြိုက် တန်ဖိုးတွေနဲ့ အစားထိုးပေးတဲ့ function တစ်ခု ဖြစ်ပါတယ်။ ဒီလိုလုပ်ပုံကို လက်တွေ့ကြည့်ရှုနိုင်ဖို့ အခြား `Series` တစ်ခုကို ဖန်တီးကြည့်ရအောင်။\n" ] }, { "cell_type": "markdown", "metadata": { "id": "CE8S7louLezV" }, "source": [ "### အမျိုးအစားအချက်အလက် (Non-numeric)\n", "ပထမဆုံး Non-numeric အချက်အလက်ကို စဉ်းစားကြည့်ပါ။ ဒေတာစုများတွင် အမျိုးအစားအချက်အလက်ပါသော ကော်လံများရှိပါသည်။ ဥပမာ - ကျား/မ၊ True သို့မဟုတ် 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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
012
012True
134None
256False
378True
4910True
\n", "
" ], "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": [] }, { "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": [] }, { "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
012
012True
134True
256False
378True
4910True
\n", "
" ], "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": [] }, { "cell_type": "markdown", "metadata": { "id": "heYe1I0dOmQ_" }, "source": [ "### ကိန်းဂဏန်းဆိုင်ရာ ဒေတာ\n", "အခု ကိန်းဂဏန်းဆိုင်ရာ ဒေတာကို ဆွေးနွေးကြမယ်။ ဒီမှာ မရှိတဲ့တန်ဖိုးတွေကို အစားထိုးဖို့အတွက် အများဆုံးအသုံးပြုတဲ့ နည်းလမ်းနှစ်ခုရှိတယ်။\n", "\n", "1. အတန်းရဲ့ အလယ်တန်းတန်ဖိုး (Median) နဲ့ အစားထိုးခြင်း \n", "2. အတန်းရဲ့ ပျမ်းမျှတန်ဖိုး (Mean) နဲ့ အစားထိုးခြင်း \n", "\n", "အလယ်တန်းတန်ဖိုး (Median) နဲ့ အစားထိုးတာက အလွန်အမင်းတန်ဖိုးတွေ (outliers) ပါဝင်တဲ့ skewed data တွေမှာ အသုံးပြုတယ်။ ဒါကတော့ အလယ်တန်းတန်ဖိုးဟာ အလွန်အမင်းတန်ဖိုးတွေကို သက်ရောက်မှုမရှိစေတဲ့ အကြောင်းကြောင့် ဖြစ်တယ်။\n", "\n", "ဒေတာကို ပုံမှန်အတိုင်း (normalized) ပြုလုပ်ထားတဲ့အခါမှာတော့ ပျမ်းမျှတန်ဖိုး (Mean) ကို အသုံးပြုနိုင်တယ်။ အဲဒီအချိန်မှာ Mean နဲ့ Median ဟာ တစ်ခွင်တည်းနီးနီး ဖြစ်နေမယ်။\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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
012
0-2.001
1-1.023
2NaN45
31.067
42.089
\n", "
" ], "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": [] }, { "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
012
0-2.001
1-1.023
20.045
31.067
42.089
\n", "
" ], "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": [] }, { "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
012
0-20.01
1-12.03
20NaN5
316.07
428.09
\n", "
" ], "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": [] }, { "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
012
0-20.01
1-12.03
204.05
316.07
428.09
\n", "
" ], "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. Categorized အချက်အလက်များအတွက် မရှိသည့်အချက်အလက်များကို အများအားဖြင့် ကော်လံ၏ mode ဖြင့် အစားထိုးသည်။\n", "4. နံပါတ်ဆိုင်ရာအချက်အလက်များအတွက် မရှိသည့်အချက်အလက်များကို အများအားဖြင့် mean (normalized datasets များအတွက်) သို့မဟုတ် ကော်လံ၏ median ဖြင့် ဖြည့်စွက်သည်။\n" ] }, { "cell_type": "markdown", "metadata": { "id": "FI9MmqFJgRsH" }, "source": [] }, { "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": [] }, { "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": [ "သင်သည် **back-fill** ကိုလည်း အသုံးပြု၍ null ကို ဖြည့်ရန် နောက်ထပ်တရားဝင်တန်ဖိုးကို နောက်ဆုတ်၍ ဖြည့်နိုင်သည်။\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 တန်ဖိုးတွေကို ဖြည့်ရန် `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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
0123
01.0NaN7NaN
12.05.08NaN
2NaN6.09NaN
\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
0123
01.01.07.07.0
12.05.08.08.0
2NaN6.09.09.0
\n", "
" ], "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": [] }, { "cell_type": "markdown", "metadata": { "id": "eeAoOU0RgRsJ" }, "source": [] }, { "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
0123
01.05.57NaN
12.05.08NaN
21.56.09NaN
\n", "
" ], "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": [ "### ကဏ္ဍအချက်အလက်များကို Encode လုပ်ခြင်း\n", "\n", "Machine learning မော်ဒယ်များသည် ကိန်းဂဏန်းများနှင့် ကိန်းဂဏန်းပုံစံအချက်အလက်များကိုသာ ကိုင်တွယ်နိုင်သည်။ မော်ဒယ်သည် Yes နှင့် No အကြားကွာခြားမှုကို မသိနိုင်ပေမယ့် 0 နှင့် 1 အကြားကွာခြားမှုကို သိနိုင်ပါမည်။ ထို့ကြောင့် ပျောက်ဆုံးနေသော အချက်အလက်များကို ဖြည့်ပြီးနောက်၊ ကဏ္ဍအချက်အလက်များကို မော်ဒယ်နားလည်နိုင်ရန်အတွက် ကိန်းဂဏန်းပုံစံတစ်ခုအဖြစ် encode လုပ်ရန် လိုအပ်ပါသည်။\n", "\n", "Encoding ကို နည်းလမ်းနှစ်မျိုးဖြင့် ပြုလုပ်နိုင်ပါသည်။ အောက်တွင် အဆိုပါနည်းလမ်းများကို ဆွေးနွေးသွားမည်ဖြစ်သည်။\n" ] }, { "cell_type": "markdown", "metadata": { "id": "uDq9SxB7mu5i" }, "source": [ "**တံဆိပ်ကုဒ်ဖြင့်အမှတ်အသားပေးခြင်း**\n", "\n", "တံဆိပ်ကုဒ်ဖြင့်အမှတ်အသားပေးခြင်းသည် အမျိုးအစားတစ်ခုချင်းစီကို နံပါတ်တစ်ခုအဖြစ် ပြောင်းလဲခြင်းဖြစ်သည်။ ဥပမာအားဖြင့်၊ လေကြောင်းခရီးသည်များ၏ ဒေတာစုတစ်ခုရှိပြီး၊ ၎င်းတွင် ['business class', 'economy class', 'first class'] စသည်ဖြင့် ခရီးသည်အတန်းအစားကို ဖော်ပြထားသော ကော်လံတစ်ခုရှိသည်ဟု ဆိုပါစို့။ တံဆိပ်ကုဒ်ဖြင့်အမှတ်အသားပေးခြင်းကို ပြုလုပ်ပါက၊ ၎င်းသည် [0,1,2] အဖြစ် ပြောင်းလဲသွားမည်ဖြစ်သည်။ ဥပမာကို ကုဒ်ဖြင့် ကြည့်ရှုကြမည်။ ကျွန်ုပ်တို့သည် နောက်ထပ် notebook များတွင် `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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
IDclass
010business class
120first class
230economy class
340economy class
450economy class
560business class
\n", "
" ], "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 ပြုလုပ်ရန်အတွက်၊ အတန်းတစ်ခုချင်းစီကို နံပါတ်တစ်ခုနှင့်ဆက်စပ်ထားသော မြေပုံဖော်ပြချက်ကို အရင်ဆုံးဖော်ပြရမည်၊ ထို့နောက် အစားထိုးရန်\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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
IDclass
0100
1202
2301
3401
4501
5600
\n", "
" ], "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", "အခြားသော Encoding အမျိုးအစားတစ်ခုမှာ One Hot Encoding ဖြစ်ပါတယ်။ ဒီ Encoding အမျိုးအစားမှာ Column ရဲ့ Category တစ်ခုစီကို သီးသန့် Column အဖြစ် ထည့်သွင်းပြီး၊ Data Point တစ်ခုစီမှာ အဲဒီ Category ပါဝင်မပါဝင်ပေါ်မူတည်ပြီး 0 သို့မဟုတ် 1 ကို ထည့်သွင်းပေးပါမယ်။ ဒါကြောင့် Category မျိုးစုံ n ခုရှိရင် Dataframe မှာ Column n ခုကို ထပ်ထည့်ပေးပါမယ်။\n", "\n", "ဥပမာအားဖြင့် အရင်က သုံးခဲ့တဲ့ လေယာဉ်အတန်းပုံစံကို ပြန်ယူကြည့်ရအောင်။ Categories တွေက ['business class', 'economy class', 'first class'] ဖြစ်ပါတယ်။ ဒါကြောင့် One Hot Encoding ကို လုပ်ဆောင်မယ်ဆိုရင် Dataset မှာ အောက်ပါ Column သုံးခုကို ထည့်သွင်းပေးပါမယ်။ ['class_business class', 'class_economy class', 'class_first class']\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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
IDclass
010business class
120first class
230economy class
340economy class
450economy class
560business class
\n", "
" ], "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": [] }, { "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
IDclass_business classclass_economy classclass_first class
010100
120001
230010
340010
450010
560100
\n", "
" ], "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. အမျိုးအစားများရဲ့ အရေအတွက်နဲ့ ဒေတာစနစ်ရဲ့ အရွယ်အစားက သေးငယ်တဲ့အခါ။\n", "2. အမျိုးအစားများမှာ သတ်မှတ်ထားတဲ့ အစီအစဉ်မရှိတဲ့အခါ။\n" ] }, { "cell_type": "markdown", "metadata": { "id": "XnUmci_4uvyu" }, "source": [ "အဓိကအချက်များ: \n", "1. Encoding သည် အနက်မပါသော ဒေတာများကို အနက်ပါသော ဒေတာများအဖြစ် ပြောင်းလဲရန်အတွက် ပြုလုပ်သည်။ \n", "2. Encoding အမျိုးအစားနှစ်မျိုးရှိသည် - Label encoding နှင့် One Hot encoding၊ ဒါတွေကို dataset ရဲ့ လိုအပ်ချက်အပေါ်မူတည်ပြီး ပြုလုပ်နိုင်သည်။ \n" ] }, { "cell_type": "markdown", "metadata": { "id": "K8UXOJYRgRsJ" }, "source": [ "## အချက်အလက်အတူတူများကို ဖယ်ရှားခြင်း\n", "\n", "> **သင်ယူရည်မှန်းချက်:** ဤအပိုင်းလေးအဆုံးသတ်ချိန်တွင် DataFrames မှ အချက်အလက်အတူတူများကို ဖော်ထုတ်ပြီး ဖယ်ရှားနိုင်ရန် ကျွမ်းကျင်မှုရှိလာမည်။\n", "\n", "ပျက်ကွက်နေသော အချက်အလက်များအပြင်၊ အမှန်တကယ်ရှိသော dataset များတွင် အချက်အလက်အတူတူများနှင့်လည်း ကြုံတွေ့ရလေ့ရှိသည်။ ကံကောင်းစွာဖြင့် pandas သည် အချက်အလက်အတူတူများကို ရှာဖွေဖော်ထုတ်ရန်နှင့် ဖယ်ရှားရန် လွယ်ကူသော နည်းလမ်းတစ်ခုကို ပံ့ပိုးပေးထားသည်။\n" ] }, { "cell_type": "markdown", "metadata": { "id": "qrEG-Wa0gRsJ" }, "source": [ "### အတူတူဖြစ်နေသောတန်ဖိုးများကို ရှာဖွေခြင်း: `duplicated`\n", "\n", "သင်သည် pandas ရဲ့ `duplicated` method ကို အသုံးပြု၍ အတူတူဖြစ်နေသောတန်ဖိုးများကို လွယ်ကူစွာ ရှာဖွေနိုင်ပါသည်။ ဤ method သည် `DataFrame` အတွင်းရှိ တစ်ခုတည်းသော အချက်အလက်သည် ယခင်တစ်ခုနှင့် အတူတူဖြစ်ကြောင်း ပြသသော Boolean mask ကို ပြန်ပေးပါသည်။ ဤကို လက်တွေ့အသုံးပြုရန်အတွက် နောက်ထပ် `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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
lettersnumbers
0A1
1B2
2A1
3B3
4B3
\n", "
" ], "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` ဖြစ်နေသော အချက်အလက်များကို ကူးယူပြီး ပြန်ပေးသည်။\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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
lettersnumbers
0A1
1B2
3B3
\n", "
" ], "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` နှစ်ခုစလုံးသည် အကုန်လုံးသော ကော်လံများကို စဉ်းစားရန် ပုံမှန်ထားရှိထားပြီး သို့သော် သင့် `DataFrame` တွင် ကော်လံအချို့ကိုသာ စစ်ဆေးရန် သတ်မှတ်နိုင်ပါသည်။\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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
lettersnumbers
0A1
1B2
\n", "
" ], "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": [] }, { "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": "8533b3a2230311943339963fc7f04c21", "translation_date": "2025-09-02T07:19:05+00:00", "source_file": "2-Working-With-Data/08-data-preparation/notebook.ipynb", "language_code": "my" } }, "nbformat": 4, "nbformat_minor": 0 }