{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "rQ8UhzFpgRra" }, "source": [ "# ਡਾਟਾ ਤਿਆਰੀ\n", "\n", "[ਅਸਲ ਨੋਟਬੁੱਕ ਸਰੋਤ *ਡਾਟਾ ਸਾਇੰਸ: ਪਾਇਥਨ ਅਤੇ ਮਸ਼ੀਨ ਲਰਨਿੰਗ ਸਟੂਡੀਓ ਲਈ ਮਸ਼ੀਨ ਲਰਨਿੰਗ ਦਾ ਪਰਿਚਯ ਲੀ ਸਟੌਟ ਦੁਆਰਾ*](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 ਵਿੱਚ ਆਪਣਾ ਡਾਟਾ ਲੋਡ ਕਰ ਲੈਂਦੇ ਹੋ, ਤਾਂ ਇਹ ਜ਼ਿਆਦਾਤਰ ਸੰਭਾਵਨਾ ਹੈ ਕਿ ਇਹ ਇੱਕ `DataFrame` ਵਿੱਚ ਹੋਵੇਗਾ। ਪਰ, ਜੇ ਤੁਹਾਡੇ `DataFrame` ਵਿੱਚ 60,000 ਕਤਾਰਾਂ ਅਤੇ 400 ਕਾਲਮ ਹਨ, ਤਾਂ ਤੁਸੀਂ ਇਹ ਸਮਝਣਾ ਕਿਵੇਂ ਸ਼ੁਰੂ ਕਰੋਗੇ ਕਿ ਤੁਸੀਂ ਕਿਸ ਨਾਲ ਕੰਮ ਕਰ ਰਹੇ ਹੋ? ਖੁਸ਼ਕਿਸਮਤੀ ਨਾਲ, pandas ਕੁਝ ਸੁਵਿਧਾਜਨਕ ਟੂਲ ਪ੍ਰਦਾਨ ਕਰਦਾ ਹੈ ਜੋ ਇੱਕ `DataFrame` ਬਾਰੇ ਕੁੱਲ ਜਾਣਕਾਰੀ ਦੇਖਣ ਦੇ ਨਾਲ ਨਾਲ ਪਹਿਲੀਆਂ ਕੁਝ ਅਤੇ ਆਖਰੀ ਕੁਝ ਕਤਾਰਾਂ ਨੂੰ ਤੇਜ਼ੀ ਨਾਲ ਦੇਖਣ ਦੀ ਸਹੂਲਤ ਦਿੰਦੇ ਹਨ।\n", "\n", "ਇਸ ਫੰਕਸ਼ਨਾਲਿਟੀ ਦੀ ਪੜਚੋਲ ਕਰਨ ਲਈ, ਅਸੀਂ Python ਦੀ scikit-learn ਲਾਇਬ੍ਰੇਰੀ ਨੂੰ ਇੰਪੋਰਟ ਕਰਾਂਗੇ ਅਤੇ ਇੱਕ ਪ੍ਰਸਿੱਧ ਡਾਟਾਸੈਟ ਦੀ ਵਰਤੋਂ ਕਰਾਂਗੇ ਜੋ ਹਰ ਡਾਟਾ ਸਾਇੰਟਿਸਟ ਸੈਂਕੜੇ ਵਾਰ ਦੇਖ ਚੁੱਕਾ ਹੈ: ਬ੍ਰਿਟਿਸ਼ ਜੀਵ ਵਿਗਿਆਨੀ ਰੋਨਾਲਡ ਫਿਸ਼ਰ ਦਾ *Iris* ਡਾਟਾਸੈਟ, ਜੋ ਉਸਦੇ 1936 ਦੇ ਪੇਪਰ \"ਟੈਕਸੋਨੋਮਿਕ ਸਮੱਸਿਆਵਾਂ ਵਿੱਚ ਕਈ ਮਾਪਦੰਡਾਂ ਦੇ ਉਪਯੋਗ\" ਵਿੱਚ ਵਰਤਿਆ ਗਿਆ ਸੀ:\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_df` ਵੈਰੀਏਬਲ ਵਿੱਚ Iris Dataset ਲੋਡ ਕੀਤਾ ਹੈ। ਡਾਟਾ ਵਿੱਚ ਘੁਸਣ ਤੋਂ ਪਹਿਲਾਂ, ਇਹ ਜਾਣਨਾ ਮਹੱਤਵਪੂਰਨ ਹੋਵੇਗਾ ਕਿ ਸਾਡੇ ਕੋਲ ਕਿੰਨੇ ਡਾਟਾਪੌਇੰਟ ਹਨ ਅਤੇ ਡਾਟਾਸੈੱਟ ਦਾ ਕੁੱਲ ਆਕਾਰ ਕੀ ਹੈ। ਇਹ ਜਾਣਨਾ ਲਾਭਦਾਇਕ ਹੈ ਕਿ ਅਸੀਂ ਕਿੰਨੀ ਮਾਤਰਾ ਦੇ ਡਾਟਾ ਨਾਲ ਨਿਪਟ ਰਹੇ ਹਾਂ।\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": [ "ਅਸੀਂ 150 ਕਤਾਰਾਂ ਅਤੇ 4 ਕਾਲਮਾਂ ਦੇ ਡਾਟਾ ਨਾਲ ਨਿਪਟ ਰਹੇ ਹਾਂ। ਹਰ ਕਤਾਰ ਇੱਕ ਡਾਟਾਪੌਇੰਟ ਨੂੰ ਦਰਸਾਉਂਦੀ ਹੈ ਅਤੇ ਹਰ ਕਾਲਮ ਡਾਟਾ ਫਰੇਮ ਨਾਲ ਜੁੜੀ ਇੱਕ ਵਿਸ਼ੇਸ਼ਤਾ ਨੂੰ ਦਰਸਾਉਂਦਾ ਹੈ। ਇਸ ਲਈ, ਮੁਲ਼ ਤੌਰ 'ਤੇ, ਇੱਥੇ 150 ਡਾਟਾਪੌਇੰਟ ਹਨ, ਜਿਨ੍ਹਾਂ ਵਿੱਚੋਂ ਹਰ ਇੱਕ ਵਿੱਚ 4 ਵਿਸ਼ੇਸ਼ਤਾਵਾਂ ਹਨ।\n", "\n", "`shape` ਇੱਥੇ ਡਾਟਾ ਫਰੇਮ ਦੀ ਇੱਕ ਗੁਣਵੱਤਾ ਹੈ, ਨਾ ਕਿ ਇੱਕ ਫੰਕਸ਼ਨ, ਇਸ ਲਈ ਇਹ ਦੇ ਅੰਤ ਵਿੱਚ ਗੋਲ ਬ੍ਰੈਕਟਸ ਨਹੀਂ ਹਨ।\n" ] }, { "cell_type": "markdown", "metadata": { "id": "d3AZKs0PinGP" }, "source": [ "### `DataFrame.columns`\n", "ਹੁਣ ਆਓ ਡਾਟਾ ਦੀਆਂ 4 ਕਾਲਮਾਂ ਵੱਲ ਜਾਈਏ। ਹਰ ਇੱਕ ਕਾਲਮ ਦਾ ਅਰਥ ਕੀ ਹੈ? `columns` ਐਟ੍ਰਿਬਿਊਟ ਸਾਨੂੰ ਡਾਟਾਫ੍ਰੇਮ ਵਿੱਚ ਕਾਲਮਾਂ ਦੇ ਨਾਮ ਦੱਸੇਗਾ।\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": [ "ਜਿਵੇਂ ਕਿ ਅਸੀਂ ਦੇਖ ਸਕਦੇ ਹਾਂ, ਇੱਥੇ ਚਾਰ (4) ਕਾਲਮ ਹਨ। `columns` ਗੁਣ ਧਰਮ ਸਾਨੂੰ ਕਾਲਮਾਂ ਦੇ ਨਾਮ ਦੱਸਦਾ ਹੈ ਅਤੇ ਮੁੱਢਲੇ ਤੌਰ 'ਤੇ ਹੋਰ ਕੁਝ ਨਹੀਂ। ਇਹ ਗੁਣ ਧਰਮ ਮਹੱਤਵਪੂਰਨ ਹੋ ਜਾਂਦਾ ਹੈ ਜਦੋਂ ਅਸੀਂ ਇਹ ਪਛਾਣਣਾ ਚਾਹੁੰਦੇ ਹਾਂ ਕਿ ਇੱਕ ਡੇਟਾਸੈੱਟ ਵਿੱਚ ਕਿਹੜੀਆਂ ਵਿਸ਼ੇਸ਼ਤਾਵਾਂ ਸ਼ਾਮਲ ਹਨ।\n" ] }, { "cell_type": "markdown", "metadata": { "id": "2UTlvkjmgRrs" }, "source": [ "### `DataFrame.info`\n", "ਡਾਟਾ ਦੀ ਮਾਤਰਾ (`shape` ਗੁਣ) ਅਤੇ ਫੀਚਰਾਂ ਜਾਂ ਕਾਲਮਾਂ ਦੇ ਨਾਮ (`columns` ਗੁਣ) ਸਾਨੂੰ ਡਾਟਾਸੈੱਟ ਬਾਰੇ ਕੁਝ ਦੱਸਦੇ ਹਨ। ਹੁਣ, ਅਸੀਂ ਡਾਟਾਸੈੱਟ ਵਿੱਚ ਹੋਰ ਗਹਿਰਾਈ ਨਾਲ ਜਾਣਾ ਚਾਹਾਂਗੇ। `DataFrame.info()` ਫੰਕਸ਼ਨ ਇਸ ਲਈ ਕਾਫ਼ੀ ਲਾਭਦਾਇਕ ਹੈ।\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. ਹਰ ਕਾਲਮ ਦੀ ਡੇਟਾ ਕਿਸਮ: ਇਸ ਡੇਟਾਸੈੱਟ ਵਿੱਚ, ਸਾਰਾ ਡੇਟਾ 64-ਬਿਟ ਫਲੋਟਿੰਗ-ਪੌਇੰਟ ਨੰਬਰਾਂ ਦੇ ਰੂਪ ਵਿੱਚ ਸਟੋਰ ਕੀਤਾ ਗਿਆ ਹੈ। \n", "2. ਨਾਨ-ਨੱਲ ਮੁੱਲਾਂ ਦੀ ਗਿਣਤੀ: ਨੱਲ ਮੁੱਲਾਂ ਨਾਲ ਨਿਪਟਣਾ ਡੇਟਾ ਤਿਆਰੀ ਵਿੱਚ ਇੱਕ ਮਹੱਤਵਪੂਰਨ ਕਦਮ ਹੈ। ਇਸਨੂੰ ਨੋਟਬੁੱਕ ਵਿੱਚ ਬਾਅਦ ਵਿੱਚ ਹੱਲ ਕੀਤਾ ਜਾਵੇਗਾ। \n" ] }, { "cell_type": "markdown", "metadata": { "id": "IYlyxbpWFEF4" }, "source": [ "### DataFrame.describe()\n", "ਮੰਨੋ ਸਾਡੇ ਡਾਟਾਸੈੱਟ ਵਿੱਚ ਬਹੁਤ ਸਾਰਾ ਸੰਖਿਆਤਮਕ ਡਾਟਾ ਹੈ। ਇੱਕ-ਵਿਚਲਨ ਅੰਕੜੇ ਗਣਨਾਵਾਂ, ਜਿਵੇਂ ਕਿ ਔਸਤ, ਮੱਧਿਕ, ਚੌਥਾਈਕ ਆਦਿ, ਹਰ ਕਾਲਮ 'ਤੇ ਅਲੱਗ-ਅਲੱਗ ਕੀਤੀਆਂ ਜਾ ਸਕਦੀਆਂ ਹਨ। `DataFrame.describe()` ਫੰਕਸ਼ਨ ਸਾਨੂੰ ਡਾਟਾਸੈੱਟ ਦੇ ਸੰਖਿਆਤਮਕ ਕਾਲਮਾਂ ਦੀ ਅੰਕੜੇਵਾਰ ਸੰਖੇਪ ਜਾਣਕਾਰੀ ਪ੍ਰਦਾਨ ਕਰਦਾ ਹੈ।\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", "ਉਪਰ ਦਿੱਤੀਆਂ ਸਾਰੀਆਂ ਫੰਕਸ਼ਨਾਂ ਅਤੇ ਗੁਣਾਂ ਨਾਲ, ਸਾਨੂੰ ਡਾਟਾਸੈਟ ਦੀ ਇੱਕ ਉੱਚ ਪੱਧਰੀ ਝਲਕ ਮਿਲ ਗਈ ਹੈ। ਸਾਨੂੰ ਪਤਾ ਹੈ ਕਿ ਕਿੰਨੇ ਡਾਟਾ ਪੌਇੰਟ ਹਨ, ਕਿੰਨੇ ਫੀਚਰ ਹਨ, ਹਰ ਫੀਚਰ ਦਾ ਡਾਟਾ ਟਾਈਪ ਕੀ ਹੈ ਅਤੇ ਹਰ ਫੀਚਰ ਲਈ ਕਿੰਨੇ non-null ਮੁੱਲ ਹਨ।\n", "\n", "ਹੁਣ ਸਮਾਂ ਹੈ ਡਾਟਾ ਨੂੰ ਖੁਦ ਦੇਖਣ ਦਾ। ਆਓ ਵੇਖੀਏ ਕਿ ਸਾਡੇ `DataFrame` ਦੀਆਂ ਪਹਿਲੀਆਂ ਕੁਝ ਪੰਗਤਾਂ (ਪਹਿਲੇ ਕੁਝ ਡਾਟਾ ਪੌਇੰਟ) ਕਿਵੇਂ ਦਿਖਦੇ ਹਨ:\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": [ "ਇੱਥੇ ਨਤੀਜੇ ਵਜੋਂ, ਅਸੀਂ ਡੇਟਾਸੈੱਟ ਦੀਆਂ ਪੰਜ (5) ਐਂਟਰੀਆਂ ਦੇਖ ਸਕਦੇ ਹਾਂ। ਜੇ ਅਸੀਂ ਖੱਬੇ ਪਾਸੇ ਇੰਡੈਕਸ ਨੂੰ ਵੇਖੀਏ, ਤਾਂ ਸਾਨੂੰ ਪਤਾ ਲੱਗਦਾ ਹੈ ਕਿ ਇਹ ਪਹਿਲੀਆਂ ਪੰਜ ਕਤਾਰਾਂ ਹਨ।\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": [ "ਅਮਲ ਵਿੱਚ, ਇਹ ਲਾਭਦਾਇਕ ਹੁੰਦਾ ਹੈ ਕਿ ਤੁਸੀਂ ਆਸਾਨੀ ਨਾਲ `DataFrame` ਦੀਆਂ ਪਹਿਲੀਆਂ ਕੁਝ ਕਤਾਰਾਂ ਜਾਂ ਆਖਰੀ ਕੁਝ ਕਤਾਰਾਂ ਦੀ ਜਾਂਚ ਕਰ ਸਕੋ, ਖਾਸ ਕਰਕੇ ਜਦੋਂ ਤੁਸੀਂ ਕ੍ਰਮਬੱਧ ਡੇਟਾਸੈਟਸ ਵਿੱਚ ਅਸਧਾਰਨ ਮੁੱਲਾਂ ਦੀ ਭਾਲ ਕਰ ਰਹੇ ਹੋ। \n", "\n", "ਉਪਰ ਦਿੱਤੇ ਸਾਰੇ ਫੰਕਸ਼ਨ ਅਤੇ ਗੁਣ, ਜੋ ਕੋਡ ਉਦਾਹਰਣਾਂ ਦੀ ਮਦਦ ਨਾਲ ਦਿਖਾਏ ਗਏ ਹਨ, ਸਾਨੂੰ ਡੇਟਾ ਦੀ ਇੱਕ ਝਲਕ ਅਤੇ ਅਹਿਸਾਸ ਪ੍ਰਾਪਤ ਕਰਨ ਵਿੱਚ ਮਦਦ ਕਰਦੇ ਹਨ। \n", "\n", "> **ਮੁੱਖ ਗੱਲ:** ਸਿਰਫ `DataFrame` ਵਿੱਚ ਮੌਜੂਦ ਜਾਣਕਾਰੀ ਬਾਰੇ ਮੈਟਾਡੇਟਾ ਜਾਂ ਉਸ ਦੀਆਂ ਪਹਿਲੀਆਂ ਅਤੇ ਆਖਰੀ ਕੁਝ ਕਦਰਾਂ ਨੂੰ ਦੇਖ ਕੇ ਵੀ, ਤੁਸੀਂ ਉਸ ਡੇਟਾ ਦੇ ਆਕਾਰ, ਰੂਪ ਅਤੇ ਸਮੱਗਰੀ ਬਾਰੇ ਤੁਰੰਤ ਇੱਕ ਵਿਚਾਰ ਪ੍ਰਾਪਤ ਕਰ ਸਕਦੇ ਹੋ, ਜਿਸ ਨਾਲ ਤੁਸੀਂ ਨਿਪਟ ਰਹੇ ਹੋ। \n" ] }, { "cell_type": "markdown", "metadata": { "id": "TvurZyLSDxq_" }, "source": [ "### ਗੁੰਮ ਡਾਟਾ\n", "ਆਓ ਗੁੰਮ ਡਾਟਾ ਬਾਰੇ ਸਮਝੀਏ। ਗੁੰਮ ਡਾਟਾ ਉਸ ਸਮੇਂ ਹੁੰਦਾ ਹੈ, ਜਦੋਂ ਕੁਝ ਕਾਲਮਾਂ ਵਿੱਚ ਕੋਈ ਵੀ ਮੁੱਲ ਸਟੋਰ ਨਹੀਂ ਕੀਤਾ ਜਾਂਦਾ।\n", "\n", "ਚਲੋ ਇੱਕ ਉਦਾਹਰਨ ਲੈਂਦੇ ਹਾਂ: ਮੰਨੋ ਕਿ ਕੋਈ ਵਿਅਕਤੀ ਆਪਣੇ ਵਜ਼ਨ ਨੂੰ ਲੈ ਕੇ ਸਚੇਤ ਹੈ ਅਤੇ ਸਰਵੇ ਵਿੱਚ ਵਜ਼ਨ ਵਾਲਾ ਖੇਤਰ ਨਹੀਂ ਭਰਦਾ। ਫਿਰ, ਉਸ ਵਿਅਕਤੀ ਲਈ ਵਜ਼ਨ ਦਾ ਮੁੱਲ ਗੁੰਮ ਹੋਵੇਗਾ।\n", "\n", "ਅਕਸਰ, ਅਸਲ ਦੁਨੀਆ ਦੇ ਡਾਟਾਸੈਟਸ ਵਿੱਚ, ਗੁੰਮ ਮੁੱਲ ਮਿਲਦੇ ਹਨ।\n", "\n", "**ਪੈਂਡਾਸ ਕਿਵੇਂ ਗੁੰਮ ਡਾਟਾ ਨੂੰ ਹੈਂਡਲ ਕਰਦਾ ਹੈ**\n", "\n", "ਪੈਂਡਾਸ ਗੁੰਮ ਮੁੱਲਾਂ ਨੂੰ ਦੋ ਤਰੀਕਿਆਂ ਨਾਲ ਹੈਂਡਲ ਕਰਦਾ ਹੈ। ਪਹਿਲਾ ਤਰੀਕਾ ਤੁਸੀਂ ਪਹਿਲੇ ਸੈਕਸ਼ਨਾਂ ਵਿੱਚ ਵੇਖ ਚੁੱਕੇ ਹੋ: `NaN`, ਜਾਂ Not a Number। ਇਹ ਦਰਅਸਲ ਇੱਕ ਖਾਸ ਮੁੱਲ ਹੈ ਜੋ IEEE ਫਲੋਟਿੰਗ-ਪੌਇੰਟ ਸਪੈਸਿਫਿਕੇਸ਼ਨ ਦਾ ਹਿੱਸਾ ਹੈ ਅਤੇ ਇਹ ਸਿਰਫ ਗੁੰਮ ਫਲੋਟਿੰਗ-ਪੌਇੰਟ ਮੁੱਲਾਂ ਨੂੰ ਦਰਸਾਉਣ ਲਈ ਵਰਤਿਆ ਜਾਂਦਾ ਹੈ।\n", "\n", "ਫਲੋਟਸ ਤੋਂ ਇਲਾਵਾ ਹੋਰ ਕਿਸਮ ਦੇ ਗੁੰਮ ਮੁੱਲਾਂ ਲਈ, ਪੈਂਡਾਸ Python ਦੇ `None` ਆਬਜੈਕਟ ਦਾ ਇਸਤੇਮਾਲ ਕਰਦਾ ਹੈ। ਜਦੋਂ ਕਿ ਇਹ ਥੋੜ੍ਹਾ ਗੁੰਝਲਦਾਰ ਲੱਗ ਸਕਦਾ ਹੈ ਕਿ ਤੁਸੀਂ ਦੋ ਵੱਖ-ਵੱਖ ਕਿਸਮ ਦੇ ਮੁੱਲਾਂ ਨੂੰ ਦੇਖੋਗੇ ਜੋ ਅਸਲ ਵਿੱਚ ਇੱਕੋ ਗੱਲ ਕਹਿੰਦੇ ਹਨ, ਇਸ ਡਿਜ਼ਾਈਨ ਚੋਣ ਦੇ ਪਿੱਛੇ ਮਜ਼ਬੂਤ ਕਾਰਨ ਹਨ। ਅਮਲ ਵਿੱਚ, ਇਹ ਤਰੀਕਾ ਪੈਂਡਾਸ ਨੂੰ ਬਹੁਤ ਸਾਰੇ ਕੇਸਾਂ ਲਈ ਇੱਕ ਵਧੀਆ ਸਮਝੌਤਾ ਪੇਸ਼ ਕਰਨ ਦੇ ਯੋਗ ਬਣਾਉਂਦਾ ਹੈ। ਇਸਦੇ ਬਾਵਜੂਦ, `None` ਅਤੇ `NaN` ਦੋਵਾਂ ਵਿੱਚ ਕੁਝ ਪਾਬੰਦੀਆਂ ਹੁੰਦੀਆਂ ਹਨ ਜਿਨ੍ਹਾਂ ਬਾਰੇ ਤੁਹਾਨੂੰ ਸਾਵਧਾਨ ਰਹਿਣ ਦੀ ਲੋੜ ਹੈ ਕਿ ਇਹਨਾਂ ਨੂੰ ਕਿਵੇਂ ਵਰਤਿਆ ਜਾ ਸਕਦਾ ਹੈ।\n" ] }, { "cell_type": "markdown", "metadata": { "id": "lOHqUlZFgRr5" }, "source": [ "### `None`: ਗੈਰ-ਫਲੋਟ ਗੁੰਮ ਡਾਟਾ \n", "ਕਿਉਂਕਿ `None` ਪਾਇਥਨ ਤੋਂ ਆਉਂਦਾ ਹੈ, ਇਸਨੂੰ NumPy ਅਤੇ pandas ਐਰੇਜ਼ ਵਿੱਚ ਵਰਤਿਆ ਨਹੀਂ ਜਾ ਸਕਦਾ ਜਿਹਨਾਂ ਦਾ ਡਾਟਾ ਟਾਈਪ `'object'` ਨਹੀਂ ਹੈ। ਯਾਦ ਰੱਖੋ, NumPy ਐਰੇਜ਼ (ਅਤੇ pandas ਵਿੱਚ ਡਾਟਾ ਸਟ੍ਰਕਚਰ) ਸਿਰਫ ਇੱਕ ਹੀ ਕਿਸਮ ਦੇ ਡਾਟਾ ਨੂੰ ਰੱਖ ਸਕਦੇ ਹਨ। ਇਹੀ ਗੁਣ ਉਨ੍ਹਾਂ ਨੂੰ ਵੱਡੇ ਪੱਧਰ ਦੇ ਡਾਟਾ ਅਤੇ ਗਣਨਾ ਦੇ ਕੰਮ ਲਈ ਬੇਹੱਦ ਤਾਕਤਵਰ ਬਣਾਉਂਦਾ ਹੈ, ਪਰ ਇਹ ਉਨ੍ਹਾਂ ਦੀ ਲਚੀਲਤਾਵਾਂ ਨੂੰ ਵੀ ਸੀਮਿਤ ਕਰਦਾ ਹੈ। ਇਸ ਤਰ੍ਹਾਂ ਦੇ ਐਰੇਜ਼ ਨੂੰ \"ਸਭ ਤੋਂ ਘੱਟ ਸਾਂਝੇ ਗੁਣਕ\" ਵੱਲ ਅੱਪਕਾਸਟ ਕਰਨਾ ਪੈਂਦਾ ਹੈ, ਜੋ ਡਾਟਾ ਟਾਈਪ ਐਰੇ ਵਿੱਚ ਹਰ ਚੀਜ਼ ਨੂੰ ਸ਼ਾਮਲ ਕਰ ਸਕੇ। ਜਦੋਂ ਐਰੇ ਵਿੱਚ `None` ਹੁੰਦਾ ਹੈ, ਇਸਦਾ ਮਤਲਬ ਹੈ ਕਿ ਤੁਸੀਂ ਪਾਇਥਨ ਆਬਜੈਕਟਸ ਨਾਲ ਕੰਮ ਕਰ ਰਹੇ ਹੋ। \n", "\n", "ਇਸਨੂੰ ਕਿਰਿਆਸ਼ੀਲ ਰੂਪ ਵਿੱਚ ਵੇਖਣ ਲਈ, ਹੇਠਾਂ ਦਿੱਤੇ ਉਦਾਹਰਣ ਐਰੇ ਨੂੰ ਵੇਖੋ (ਇਸਦਾ `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": [ "ਅੱਪਕਾਸਟ ਡਾਟਾ ਟਾਈਪਸ ਦੀ ਹਕੀਕਤ ਨਾਲ ਦੋ ਪਾਸੇ ਪ੍ਰਭਾਵ ਜੁੜੇ ਹੋਏ ਹਨ। ਪਹਿਲਾਂ, ਕਾਰਵਾਈਆਂ ਵਿਆਖਿਆ ਕੀਤੇ Python ਕੋਡ ਦੇ ਪੱਧਰ 'ਤੇ ਕੀਤੀਆਂ ਜਾਣਗੀਆਂ ਨਾ ਕਿ ਕੰਪਾਇਲ ਕੀਤੇ NumPy ਕੋਡ ਦੇ ਪੱਧਰ 'ਤੇ। ਅਸਲ ਵਿੱਚ, ਇਸਦਾ ਮਤਲਬ ਹੈ ਕਿ ਜੇਕਰ `Series` ਜਾਂ `DataFrames` ਵਿੱਚ `None` ਸ਼ਾਮਲ ਹੈ, ਤਾਂ ਉਨ੍ਹਾਂ ਨਾਲ ਜੁੜੀਆਂ ਕਾਰਵਾਈਆਂ ਹੌਲੀ ਹੋਣਗੀਆਂ। ਹਾਲਾਂਕਿ ਤੁਸੀਂ ਸ਼ਾਇਦ ਇਸ ਪ੍ਰਦਰਸ਼ਨ ਵਿੱਚ ਘਾਟ ਨੂੰ ਮਹਿਸੂ ਨਾ ਕਰੋ, ਵੱਡੇ ਡਾਟਾਸੈਟਸ ਲਈ ਇਹ ਸਮੱਸਿਆ ਬਣ ਸਕਦੀ ਹੈ।\n", "\n", "ਦੂਜਾ ਪਾਸੇ ਪ੍ਰਭਾਵ ਪਹਿਲੇ ਤੋਂ ਉਤਪੰਨ ਹੁੰਦਾ ਹੈ। ਕਿਉਂਕਿ `None` ਅਸਲ ਵਿੱਚ `Series` ਜਾਂ `DataFrame`s ਨੂੰ ਵੈਨਿਲਾ Python ਦੀ ਦੁਨੀਆ ਵਿੱਚ ਵਾਪਸ ਖਿੱਚ ਲੈਂਦਾ ਹੈ, ਇਸ ਲਈ ਜੇਕਰ NumPy/pandas ਐਗਰੀਗੇਸ਼ਨ ਜਿਵੇਂ ਕਿ `sum()` ਜਾਂ `min()` ਨੂੰ ਉਹਨਾਂ ਐਰੇਜ਼ 'ਤੇ ਵਰਤਿਆ ਜਾਵੇ ਜਿਨ੍ਹਾਂ ਵਿੱਚ ``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`: ਗੁੰਮ ਸ਼ੂਨ ਭਿੰਨ ਮੁੱਲ\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` ਹੁੰਦੇ ਹਨ, ਉਨ੍ਹਾਂ 'ਤੇ ਚੱਲਣ ਵਾਲੀਆਂ ਐਗ੍ਰਿਗੇਸ਼ਨਜ਼ ਵਿੱਚ ਗਲਤੀਆਂ ਨਹੀਂ ਆਉਂਦੀਆਂ। ਮਾੜੀ ਖ਼ਬਰ: ਨਤੀਜੇ ਹਮੇਸ਼ਾ ਉਪਯੋਗੀ ਨਹੀਂ ਹੁੰਦੇ:\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": [] }, { "cell_type": "markdown", "metadata": { "id": "kj6EKdsAgRsA" }, "source": [ "### `NaN` ਅਤੇ `None`: pandas ਵਿੱਚ null ਮੁੱਲ\n", "\n", "ਹਾਲਾਂਕਿ `NaN` ਅਤੇ `None` ਕੁਝ ਹੱਦ ਤੱਕ ਵੱਖਰੇ ਤਰੀਕੇ ਨਾਲ ਵਰਤਾਰਾ ਕਰ ਸਕਦੇ ਹਨ, pandas ਫਿਰ ਵੀ ਉਨ੍ਹਾਂ ਨੂੰ ਇੱਕੋ ਜਿਹਾ ਸੰਭਾਲਣ ਲਈ ਬਣਾਇਆ ਗਿਆ ਹੈ। ਇਸ ਗੱਲ ਨੂੰ ਸਮਝਣ ਲਈ, ਆਓ ਇੱਕ integers ਦੀ `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`s ਵਿੱਚ ਡਾਟਾ ਦੀ ਇੱਕਸਾਰਤਾ ਸਥਾਪਿਤ ਕਰਨ ਲਈ ਡਾਟਾ ਟਾਈਪਸ ਨੂੰ ਉੱਚੇ ਟਾਈਪਸ ਵਿੱਚ ਬਦਲਣ ਦੀ ਪ੍ਰਕਿਰਿਆ ਦੌਰਾਨ, ਪਾਂਡਾਸ ਆਸਾਨੀ ਨਾਲ ਗੁੰਮ ਹੋਈਆਂ ਕਦਰਾਂ ਨੂੰ `None` ਅਤੇ `NaN` ਦੇ ਵਿਚਕਾਰ ਬਦਲ ਸਕਦਾ ਹੈ। ਇਸ ਡਿਜ਼ਾਈਨ ਵਿਸ਼ੇਸ਼ਤਾ ਕਰਕੇ, ਪਾਂਡਾਸ ਵਿੱਚ `None` ਅਤੇ `NaN` ਨੂੰ \"null\" ਦੇ ਦੋ ਵੱਖ-ਵੱਖ ਰੂਪਾਂ ਵਜੋਂ ਸੋਚਣਾ ਲਾਭਦਾਇਕ ਹੋ ਸਕਦਾ ਹੈ। ਦਰਅਸਲ, ਕੁਝ ਮੁੱਖ ਤਰੀਕੇ ਜੋ ਤੁਸੀਂ ਪਾਂਡਾਸ ਵਿੱਚ ਗੁੰਮ ਹੋਈਆਂ ਕਦਰਾਂ ਨਾਲ ਨਜਿੱਠਣ ਲਈ ਵਰਤਦੇ ਹੋ, ਇਸ ਵਿਚਾਰ ਨੂੰ ਆਪਣੇ ਨਾਮਾਂ ਵਿੱਚ ਦਰਸਾਉਂਦੇ ਹਨ:\n", "\n", "- `isnull()`: ਗੁੰਮ ਹੋਈਆਂ ਕਦਰਾਂ ਨੂੰ ਦਰਸਾਉਣ ਵਾਲਾ ਬੂਲੀਅਨ ਮਾਸਕ ਤਿਆਰ ਕਰਦਾ ਹੈ\n", "- `notnull()`: `isnull()` ਦਾ ਉਲਟ\n", "- `dropna()`: ਡਾਟੇ ਦਾ ਇੱਕ ਫਿਲਟਰ ਕੀਤਾ ਹੋਇਆ ਸੰਸਕਰਣ ਵਾਪਸ ਕਰਦਾ ਹੈ\n", "- `fillna()`: ਗੁੰਮ ਹੋਈਆਂ ਕਦਰਾਂ ਨੂੰ ਭਰ ਕੇ ਜਾਂ ਅਨੁਮਾਨ ਲਗਾ ਕੇ ਡਾਟੇ ਦੀ ਇੱਕ ਕਾਪੀ ਵਾਪਸ ਕਰਦਾ ਹੈ\n", "\n", "ਇਹ ਤਰੀਕੇ ਸਿੱਖਣ ਅਤੇ ਇਨ੍ਹਾਂ ਨਾਲ ਆਰਾਮਦਾਇਕ ਹੋਣਾ ਬਹੁਤ ਜ਼ਰੂਰੀ ਹੈ, ਇਸ ਲਈ ਆਓ ਅਸੀਂ ਹਰ ਇੱਕ ਨੂੰ ਥੋੜ੍ਹੀ ਹੋਰ ਗਹਿਰਾਈ ਨਾਲ ਸਮਝੀਏ।\n" ] }, { "cell_type": "markdown", "metadata": { "id": "Yh5ifd9FgRsB" }, "source": [ "### ਨੱਲ ਮੁੱਲਾਂ ਦੀ ਪਛਾਣ ਕਰਨਾ\n", "\n", "ਹੁਣ ਜਦੋਂ ਅਸੀਂ ਗੁੰਮਸ਼ੁਦਾ ਮੁੱਲਾਂ ਦੀ ਮਹੱਤਤਾ ਨੂੰ ਸਮਝ ਲਿਆ ਹੈ, ਤਾਂ ਸਾਨੂੰ ਉਹਨਾਂ ਨਾਲ ਨਿਪਟਣ ਤੋਂ ਪਹਿਲਾਂ ਆਪਣੇ ਡਾਟਾਸੈੱਟ ਵਿੱਚ ਉਹਨਾਂ ਦੀ ਪਛਾਣ ਕਰਨੀ ਚਾਹੀਦੀ ਹੈ। \n", "`isnull()` ਅਤੇ `notnull()` ਦੋਵੇਂ ਹੀ ਨੱਲ ਡਾਟਾ ਦੀ ਪਛਾਣ ਕਰਨ ਲਈ ਤੁਹਾਡੇ ਮੁੱਖ ਤਰੀਕੇ ਹਨ। ਦੋਵੇਂ ਤੁਹਾਡੇ ਡਾਟਾ 'ਤੇ ਬੂਲੀਅਨ ਮਾਸਕ ਵਾਪਸ ਕਰਦੇ ਹਨ।\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` ਇੱਕ ਗਣਿਤਕ ਨਲ ਹੈ, ਇਹ ਫਿਰ ਵੀ ਇੱਕ ਬਹੁਤ ਵਧੀਆ ਪੂਰਨ ਅੰਕ ਹੈ ਅਤੇ pandas ਇਸਨੂੰ ਇਸ ਤਰ੍ਹਾਂ ਹੀ ਮੰਨਦਾ ਹੈ। `''` ਕੁਝ ਹੱਦ ਤੱਕ ਹੋਰ ਸੁਖਮ ਹੈ। ਜਦੋਂ ਕਿ ਅਸੀਂ ਇਸਨੂੰ ਭਾਗ 1 ਵਿੱਚ ਖਾਲੀ ਸਤਰ ਦੀ ਮੁੱਲ ਦਰਸਾਉਣ ਲਈ ਵਰਤਿਆ ਸੀ, ਇਹ ਫਿਰ ਵੀ ਇੱਕ ਸਤਰ ਵਸਤੂ ਹੈ ਅਤੇ pandas ਦੇ ਹਿਸਾਬ ਨਾਲ ਨਲ ਦੀ ਪ੍ਰਤੀਨਿਧਤਾ ਨਹੀਂ ਹੈ।\n", "\n", "ਹੁਣ, ਆਓ ਇਸਨੂੰ ਉਲਟਾ ਕਰੀਏ ਅਤੇ ਇਹਨਾਂ ਤਰੀਕਿਆਂ ਨੂੰ ਇਸ ਤਰ੍ਹਾਂ ਵਰਤਾਂ ਜਿਵੇਂ ਤੁਸੀਂ ਅਮਲ ਵਿੱਚ ਵਰਤੋਂਗੇ। ਤੁਸੀਂ Boolean masks ਨੂੰ ਸਿੱਧੇ ਤੌਰ 'ਤੇ ``Series`` ਜਾਂ ``DataFrame`` ਇੰਡੈਕਸ ਵਜੋਂ ਵਰਤ ਸਕਦੇ ਹੋ, ਜੋ ਕਿ ਅਲੱਗ-ਅਲੱਗ ਗੁੰਮ (ਜਾਂ ਮੌਜੂਦ) ਮੁੱਲਾਂ ਨਾਲ ਕੰਮ ਕਰਨ ਦੀ ਕੋਸ਼ਿਸ਼ ਕਰਦੇ ਸਮੇਂ ਲਾਭਦਾਇਕ ਹੋ ਸਕਦਾ ਹੈ।\n", "\n", "ਜੇਕਰ ਅਸੀਂ ਗੁੰਮ ਮੁੱਲਾਂ ਦੀ ਕੁੱਲ ਗਿਣਤੀ ਚਾਹੁੰਦੇ ਹਾਂ, ਤਾਂ ਅਸੀਂ ਸਿਰਫ `isnull()` ਤਰੀਕੇ ਦੁਆਰਾ ਬਣਾਈ ਗਈ mask 'ਤੇ ਇੱਕ ਜੋੜ ਕਰ ਸਕਦੇ ਹਾਂ।\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()` ਦੋਵੇਂ ਵਿਧੀਆਂ ਸਮਾਨ ਨਤੀਜੇ ਪੈਦਾ ਕਰਦੀਆਂ ਹਨ: ਇਹ ਨਤੀਜੇ ਅਤੇ ਉਨ੍ਹਾਂ ਦੇ ਸੂਚਕਾਂਕ ਦਿਖਾਉਂਦੀਆਂ ਹਨ, ਜੋ ਤੁਹਾਡੀ ਡਾਟਾ ਨਾਲ ਨਿਪਟਣ ਦੌਰਾਨ ਤੁਹਾਡੀ ਬਹੁਤ ਮਦਦ ਕਰਨਗੀਆਂ।\n" ] }, { "cell_type": "markdown", "metadata": { "id": "BvnoojWsgRr4" }, "source": [ "### ਗੁੰਮ ਡਾਟਾ ਨਾਲ ਨਿਪਟਣਾ\n", "\n", "> **ਸਿੱਖਣ ਦਾ ਮਕਸਦ:** ਇਸ ਉਪਵਿਭਾਗ ਦੇ ਅੰਤ ਤੱਕ, ਤੁਸੀਂ ਜਾਣ ਸਕੋਗੇ ਕਿ DataFrames ਵਿੱਚੋਂ null ਮੁੱਲਾਂ ਨੂੰ ਕਦੋਂ ਅਤੇ ਕਿਵੇਂ ਬਦਲਣਾ ਜਾਂ ਹਟਾਉਣਾ ਹੈ।\n", "\n", "Machine Learning ਮਾਡਲ ਖੁਦ ਗੁੰਮ ਡਾਟਾ ਨਾਲ ਨਿਪਟ ਨਹੀਂ ਕਰ ਸਕਦੇ। ਇਸ ਲਈ, ਡਾਟਾ ਨੂੰ ਮਾਡਲ ਵਿੱਚ ਪਾਸ ਕਰਨ ਤੋਂ ਪਹਿਲਾਂ, ਸਾਨੂੰ ਇਨ੍ਹਾਂ ਗੁੰਮ ਮੁੱਲਾਂ ਨਾਲ ਨਿਪਟਣਾ ਪਵੇਗਾ।\n", "\n", "ਗੁੰਮ ਡਾਟਾ ਨੂੰ ਕਿਵੇਂ ਹੱਲ ਕੀਤਾ ਜਾਂਦਾ ਹੈ, ਇਸ ਨਾਲ ਨਰਮ-ਨਰਮ ਤਰਾਜੂ ਜੁੜੇ ਹੋਏ ਹਨ, ਜੋ ਤੁਹਾਡੇ ਅੰਤਿਮ ਵਿਸ਼ਲੇਸ਼ਣ ਅਤੇ ਹਕੀਕਤੀ ਨਤੀਜਿਆਂ ਨੂੰ ਪ੍ਰਭਾਵਿਤ ਕਰ ਸਕਦੇ ਹਨ।\n", "\n", "ਗੁੰਮ ਡਾਟਾ ਨਾਲ ਨਿਪਟਣ ਦੇ ਮੁੱਖ ਤੌਰ 'ਤੇ ਦੋ ਤਰੀਕੇ ਹਨ:\n", "\n", "1. ਉਸ ਕਤਾਰ ਨੂੰ ਹਟਾਉਣਾ ਜਿਸ ਵਿੱਚ ਗੁੰਮ ਮੁੱਲ ਹੈ \n", "2. ਗੁੰਮ ਮੁੱਲ ਨੂੰ ਕਿਸੇ ਹੋਰ ਮੁੱਲ ਨਾਲ ਬਦਲਣਾ \n", "\n", "ਅਸੀਂ ਦੋਵੇਂ ਤਰੀਕਿਆਂ ਅਤੇ ਉਨ੍ਹਾਂ ਦੇ ਫਾਇਦੇ ਅਤੇ ਨੁਕਸਾਨਾਂ ਨੂੰ ਵਿਸਥਾਰ ਵਿੱਚ ਚਰਚਾ ਕਰਾਂਗੇ। \n" ] }, { "cell_type": "markdown", "metadata": { "id": "3VaYC1TvgRsD" }, "source": [ "### ਨੱਲ ਮੁੱਲਾਂ ਨੂੰ ਹਟਾਉਣਾ\n", "\n", "ਜਿੰਨੀ ਡਾਟਾ ਅਸੀਂ ਆਪਣੇ ਮਾਡਲ ਨੂੰ ਦਿੰਦੇ ਹਾਂ, ਉਸਦਾ ਸਿੱਧਾ ਅਸਰ ਇਸਦੀ ਪ੍ਰਦਰਸ਼ਨਸ਼ੀਲਤਾ 'ਤੇ ਪੈਂਦਾ ਹੈ। ਨੱਲ ਮੁੱਲਾਂ ਨੂੰ ਹਟਾਉਣ ਦਾ ਮਤਲਬ ਹੈ ਕਿ ਅਸੀਂ ਡਾਟਾਪੌਇੰਟਸ ਦੀ ਗਿਣਤੀ ਘਟਾ ਰਹੇ ਹਾਂ, ਅਤੇ ਇਸ ਤਰ੍ਹਾਂ ਡਾਟਾਸੈੱਟ ਦਾ ਆਕਾਰ ਘਟਾ ਰਹੇ ਹਾਂ। ਇਸ ਲਈ, ਜਦੋਂ ਡਾਟਾਸੈੱਟ ਕਾਫ਼ੀ ਵੱਡਾ ਹੋਵੇ, ਤਾਂ ਨੱਲ ਮੁੱਲਾਂ ਵਾਲੀਆਂ ਕਤਾਰਾਂ ਨੂੰ ਹਟਾਉਣਾ ਸਲਾਹਯੋਗ ਹੈ।\n", "\n", "ਇੱਕ ਹੋਰ ਹਾਲਤ ਇਹ ਹੋ ਸਕਦੀ ਹੈ ਕਿ ਕਿਸੇ ਖਾਸ ਕਤਾਰ ਜਾਂ ਕਾਲਮ ਵਿੱਚ ਬਹੁਤ ਸਾਰੇ ਗੁੰਮ ਮੁੱਲ ਹੋਣ। ਫਿਰ, ਉਹਨਾਂ ਨੂੰ ਹਟਾਇਆ ਜਾ ਸਕਦਾ ਹੈ ਕਿਉਂਕਿ ਉਹ ਸਾਡੇ ਵਿਸ਼ਲੇਸ਼ਣ ਵਿੱਚ ਜ਼ਿਆਦਾ ਮੂਲ ਭਾਗ ਨਹੀਂ ਜੋੜਣਗੇ, ਕਿਉਂਕਿ ਉਸ ਕਤਾਰ/ਕਾਲਮ ਲਈ ਜ਼ਿਆਦਾਤਰ ਡਾਟਾ ਗੁੰਮ ਹੈ।\n", "\n", "ਗੁੰਮ ਮੁੱਲਾਂ ਦੀ ਪਛਾਣ ਕਰਨ ਤੋਂ ਇਲਾਵਾ, pandas `Series` ਅਤੇ `DataFrame`s ਤੋਂ ਨੱਲ ਮੁੱਲਾਂ ਨੂੰ ਹਟਾਉਣ ਦਾ ਇੱਕ ਆਸਾਨ ਤਰੀਕਾ ਪ੍ਰਦਾਨ ਕਰਦਾ ਹੈ। ਇਸਨੂੰ ਕਿਰਿਆਸ਼ੀਲਤਾ ਵਿੱਚ ਦੇਖਣ ਲਈ, ਆਓ `example3` ਵੱਲ ਮੁੜ ਚੱਲੀਏ। `DataFrame.dropna()` ਫੰਕਸ਼ਨ ਨੱਲ ਮੁੱਲਾਂ ਵਾਲੀਆਂ ਕਤਾਰਾਂ ਨੂੰ ਹਟਾਉਣ ਵਿੱਚ ਮਦਦ ਕਰਦਾ ਹੈ।\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()]` ਦੇ ਆਉਟਪੁੱਟ ਵਰਗਾ ਦਿਖਾਈ ਦੇਣਾ ਚਾਹੀਦਾ ਹੈ। ਇੱਥੇ ਫਰਕ ਇਹ ਹੈ ਕਿ, ਸਿਰਫ ਮਾਸਕ ਕੀਤੇ ਗਏ ਮੁੱਲਾਂ 'ਤੇ ਇੰਡੈਕਸ ਕਰਨ ਦੀ ਬਜਾਇ, `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`s ਨੂੰ ਸਮਝਣ ਲਈ ਦੋ ਕਾਲਮਾਂ ਨੂੰ ਫਲੋਟ ਵਿੱਚ ਅਪਕਾਸਟ ਕੀਤਾ?)\n", "\n", "ਤੁਸੀਂ `DataFrame` ਤੋਂ ਇੱਕ ਹੀ ਮੁੱਲ ਨਹੀਂ ਹਟਾ ਸਕਦੇ, ਇਸ ਲਈ ਤੁਹਾਨੂੰ ਪੂਰੀਆਂ ਪੰਗਤਾਂ ਜਾਂ ਕਾਲਮਾਂ ਹਟਾਉਣੇ ਪੈਂਦੇ ਹਨ। ਜੋ ਕੁਝ ਤੁਸੀਂ ਕਰ ਰਹੇ ਹੋ, ਉਸ ਦੇ ਆਧਾਰ 'ਤੇ ਤੁਸੀਂ ਇੱਕ ਜਾਂ ਦੂਜਾ ਚੋਣ ਸਕਦੇ ਹੋ, ਅਤੇ ਇਸ ਲਈ pandas ਤੁਹਾਨੂੰ ਦੋਨੋਂ ਲਈ ਵਿਕਲਪ ਦਿੰਦਾ ਹੈ। ਕਿਉਂਕਿ ਡਾਟਾ ਸਾਇੰਸ ਵਿੱਚ, ਕਾਲਮ ਆਮ ਤੌਰ 'ਤੇ ਵੈਰੀਏਬਲ ਨੂੰ ਦਰਸਾਉਂਦੇ ਹਨ ਅਤੇ ਪੰਗਤਾਂ ਅਵਲੋਕਨ ਨੂੰ ਦਰਸਾਉਂਦੀਆਂ ਹਨ, ਤੁਸੀਂ ਡਾਟਾ ਦੀਆਂ ਪੰਗਤਾਂ ਨੂੰ ਹਟਾਉਣ ਦੀ ਸੰਭਾਵਨਾ ਵਧੇਰੇ ਰੱਖਦੇ ਹੋ; `dropna()` ਲਈ ਡਿਫਾਲਟ ਸੈਟਿੰਗ ਇਹ ਹੈ ਕਿ ਉਹ ਸਾਰੀਆਂ ਪੰਗਤਾਂ ਨੂੰ ਹਟਾ ਦਿੰਦਾ ਹੈ ਜਿਨ੍ਹਾਂ ਵਿੱਚ ਕੋਈ ਵੀ null ਮੁੱਲ ਹੁੰਦਾ ਹੈ:\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": [ "ਇਹ ਧਿਆਨ ਵਿੱਚ ਰੱਖੋ ਕਿ ਇਹ ਛੋਟੇ ਡਾਟਾਸੈਟ ਵਿੱਚ ਕਾਫ਼ੀ ਡਾਟਾ ਗੁਆ ਸਕਦਾ ਹੈ, ਜੋ ਤੁਸੀਂ ਰੱਖਣਾ ਚਾਹੁੰਦੇ ਹੋ। ਕੀ ਹੋਵੇ ਜੇ ਤੁਸੀਂ ਸਿਰਫ਼ ਉਹ ਪੰਗਤਾਂ ਜਾਂ ਕਾਲਮ ਹਟਾਉਣਾ ਚਾਹੁੰਦੇ ਹੋ ਜਿਨ੍ਹਾਂ ਵਿੱਚ ਕਈ ਜਾਂ ਸਾਰੇ null ਮੁੱਲ ਹਨ? ਤੁਸੀਂ ਇਹ ਸੈਟਿੰਗ `dropna` ਵਿੱਚ `how` ਅਤੇ `thresh` ਪੈਰਾਮੀਟਰਾਂ ਨਾਲ ਨਿਰਧਾਰਤ ਕਰਦੇ ਹੋ।\n", "\n", "ਡਿਫਾਲਟ ਤੌਰ 'ਤੇ, `how='any'` ਹੁੰਦਾ ਹੈ (ਜੇ ਤੁਸੀਂ ਖੁਦ ਜਾਂਚਣਾ ਚਾਹੁੰਦੇ ਹੋ ਜਾਂ ਵੇਖਣਾ ਚਾਹੁੰਦੇ ਹੋ ਕਿ ਇਸ ਮੈਥਡ ਦੇ ਹੋਰ ਪੈਰਾਮੀਟਰ ਕੀ ਹਨ, ਤਾਂ ਇੱਕ ਕੋਡ ਸੈਲ ਵਿੱਚ `example4.dropna?` ਚਲਾਓ)। ਤੁਸੀਂ ਵਿਕਲਪਕ ਤੌਰ 'ਤੇ `how='all'` ਨਿਰਧਾਰਤ ਕਰ ਸਕਦੇ ਹੋ ਤਾਂ ਜੋ ਸਿਰਫ਼ ਉਹ ਪੰਗਤਾਂ ਜਾਂ ਕਾਲਮ ਹਟਾਏ ਜਾਣ ਜੋ ਸਾਰੇ null ਮੁੱਲਾਂ ਨੂੰ ਸ਼ਾਮਲ ਕਰਦੇ ਹਨ। ਆਓ ਅਗਲੇ ਅਭਿਆਸ ਵਿੱਚ ਇਸ ਨੂੰ ਕਾਰਵਾਈ ਵਿੱਚ ਦੇਖਣ ਲਈ ਆਪਣੇ ਉਦਾਹਰਨ `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. ਨੱਲ ਮੁੱਲਾਂ ਨੂੰ ਹਟਾਉਣਾ ਸਿਰਫ ਉਸ ਸਮੇਂ ਵਧੀਆ ਵਿਚਾਰ ਹੈ ਜੇ ਡਾਟਾਸੈੱਟ ਕਾਫੀ ਵੱਡਾ ਹੈ। \n", "2. ਪੂਰੀਆਂ ਪੰਗਤਾਂ ਜਾਂ ਕਾਲਮ ਹਟਾਏ ਜਾ ਸਕਦੇ ਹਨ ਜੇ ਉਹਨਾਂ ਵਿੱਚ ਜ਼ਿਆਦਾਤਰ ਡਾਟਾ ਗੁੰਮ ਹੈ। \n", "3. `DataFrame.dropna(axis=)` ਵਿਧੀ ਨੱਲ ਮੁੱਲਾਂ ਨੂੰ ਹਟਾਉਣ ਵਿੱਚ ਮਦਦ ਕਰਦੀ ਹੈ। `axis` ਦਲੀਲ ਦਰਸਾਉਂਦੀ ਹੈ ਕਿ ਪੰਗਤਾਂ ਹਟਾਈਆਂ ਜਾਣੀਆਂ ਹਨ ਜਾਂ ਕਾਲਮ। \n", "4. `how` ਦਲੀਲ ਵੀ ਵਰਤੀ ਜਾ ਸਕਦੀ ਹੈ। ਮੂਲ ਰੂਪ ਵਿੱਚ ਇਹ `any` 'ਤੇ ਸੈਟ ਹੁੰਦੀ ਹੈ। ਇਸ ਲਈ, ਇਹ ਸਿਰਫ ਉਹਨਾਂ ਪੰਗਤਾਂ/ਕਾਲਮਾਂ ਨੂੰ ਹਟਾਉਂਦੀ ਹੈ ਜਿਨ੍ਹਾਂ ਵਿੱਚ ਕੋਈ ਵੀ ਨੱਲ ਮੁੱਲ ਹੁੰਦਾ ਹੈ। ਇਸਨੂੰ `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` ਪੈਰਾਮੀਟਰ ਤੁਹਾਨੂੰ ਵਧੀਆ-ਦਰਜੇ ਦਾ ਨਿਯੰਤਰਣ ਦਿੰਦਾ ਹੈ: ਤੁਸੀਂ ਉਹ ਗਿਣਤੀ ਸੈਟ ਕਰਦੇ ਹੋ ਜਿੰਨੀ *ਗੈਰ-ਨੱਲ* ਮੁੱਲਾਂ ਦੀ ਲੋੜ ਹੈ ਤਾਂ ਜੋ ਇੱਕ ਕਤਾਰ ਜਾਂ ਕਾਲਮ ਨੂੰ ਰੱਖਿਆ ਜਾ ਸਕੇ:\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", "ਕਈ ਵਾਰ ਖਾਲੀ ਮੁੱਲਾਂ ਨੂੰ ਉਹਨਾਂ ਨਾਲ ਭਰਨਾ ਸਮਝਦਾਰੀ ਹੁੰਦੀ ਹੈ ਜੋ ਸਹੀ ਹੋ ਸਕਦੇ ਹਨ। ਖਾਲੀ ਮੁੱਲਾਂ ਨੂੰ ਭਰਨ ਲਈ ਕੁਝ ਤਕਨੀਕਾਂ ਹਨ। ਪਹਿਲੀ ਤਕਨੀਕ ਹੈ ਡੋਮੇਨ ਨੌਲਿਜ (ਉਸ ਵਿਸ਼ੇ ਦੀ ਜਾਣਕਾਰੀ ਜਿਸ 'ਤੇ ਡੇਟਾਸੈੱਟ ਆਧਾਰਿਤ ਹੈ) ਦੀ ਵਰਤੋਂ ਕਰਕੇ ਕਿਸੇ ਤਰ੍ਹਾਂ ਖਾਲੀ ਮੁੱਲਾਂ ਦਾ ਅੰਦਾਜ਼ਾ ਲਗਾਉਣਾ। \n", "\n", "ਤੁਸੀਂ ਇਸ ਕੰਮ ਨੂੰ ਕਰਨ ਲਈ `isnull` ਦੀ ਵਰਤੋਂ ਕਰ ਸਕਦੇ ਹੋ, ਪਰ ਇਹ ਥੋੜ੍ਹਾ ਥਕਾਵਟ ਭਰਿਆ ਹੋ ਸਕਦਾ ਹੈ, ਖਾਸ ਕਰਕੇ ਜਦੋਂ ਤੁਹਾਡੇ ਕੋਲ ਭਰਨ ਲਈ ਬਹੁਤ ਸਾਰੇ ਮੁੱਲ ਹੋਣ। ਕਿਉਂਕਿ ਇਹ ਡੇਟਾ ਸਾਇੰਸ ਵਿੱਚ ਇੱਕ ਆਮ ਕੰਮ ਹੈ, pandas `fillna` ਪ੍ਰਦਾਨ ਕਰਦਾ ਹੈ, ਜੋ `Series` ਜਾਂ `DataFrame` ਦੀ ਇੱਕ ਕਾਪੀ ਵਾਪਸ ਕਰਦਾ ਹੈ ਜਿਸ ਵਿੱਚ ਖਾਲੀ ਮੁੱਲ ਤੁਹਾਡੇ ਚੋਣੇ ਹੋਏ ਮੁੱਲ ਨਾਲ ਬਦਲੇ ਜਾਂਦੇ ਹਨ। ਆਓ ਇੱਕ ਹੋਰ ਉਦਾਹਰਨ ਲਈ `Series` ਬਣਾਈਏ ਤਾਂ ਜੋ ਵੇਖ ਸਕੀਏ ਕਿ ਇਹ ਅਸਲ ਵਿੱਚ ਕਿਵੇਂ ਕੰਮ ਕਰਦਾ ਹੈ।\n" ] }, { "cell_type": "markdown", "metadata": { "id": "CE8S7louLezV" }, "source": [ "### ਸ਼੍ਰੇਣੀਬੱਧ ਡਾਟਾ (ਗਿਣਤੀਯੋਗ ਨਹੀਂ)\n", "\n", "ਸਭ ਤੋਂ ਪਹਿਲਾਂ ਆਓ ਗਿਣਤੀਯੋਗ ਨਹੀਂ ਡਾਟਾ ਬਾਰੇ ਸੋਚੀਏ। ਡਾਟਾਸੈਟ ਵਿੱਚ ਸਾਡੇ ਕੋਲ ਸ਼੍ਰੇਣੀਬੱਧ ਡਾਟਾ ਵਾਲੇ ਕਾਲਮ ਹੁੰਦੇ ਹਨ। ਉਦਾਹਰਣ ਲਈ, ਲਿੰਗ, ਸੱਚ ਜਾਂ ਝੂਠ ਆਦਿ।\n", "\n", "ਇਨ੍ਹਾਂ ਵਿੱਚੋਂ ਜ਼ਿਆਦਾਤਰ ਮਾਮਲਿਆਂ ਵਿੱਚ, ਅਸੀਂ ਗੁੰਮ ਹੋਏ ਮੁੱਲਾਂ ਨੂੰ ਕਾਲਮ ਦੇ `ਮੋਡ` ਨਾਲ ਬਦਲ ਦਿੰਦੇ ਹਾਂ। ਮੰਨੋ, ਸਾਡੇ ਕੋਲ 100 ਡਾਟਾ ਪੌਇੰਟ ਹਨ, ਜਿਨ੍ਹਾਂ ਵਿੱਚੋਂ 90 ਨੇ ਸੱਚ ਕਿਹਾ ਹੈ, 8 ਨੇ ਝੂਠ ਕਿਹਾ ਹੈ ਅਤੇ 2 ਨੇ ਕੁਝ ਨਹੀਂ ਭਰਿਆ। ਫਿਰ, ਅਸੀਂ ਉਹ 2 ਸੱਚ ਨਾਲ ਭਰ ਸਕਦੇ ਹਾਂ, ਪੂਰੇ ਕਾਲਮ ਨੂੰ ਧਿਆਨ ਵਿੱਚ ਰੱਖਦੇ ਹੋਏ।\n", "\n", "ਇੱਥੇ ਵੀ ਅਸੀਂ ਖੇਤਰ ਵਿਸ਼ੇਸ਼ ਗਿਆਨ ਦੀ ਵਰਤੋਂ ਕਰ ਸਕਦੇ ਹਾਂ। ਆਓ ਮੋਡ ਨਾਲ ਭਰਨ ਦੇ ਇੱਕ ਉਦਾਹਰਣ ਨੂੰ ਸਮਝੀਏ।\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": [ "ਜਿਵੇਂ ਅਸੀਂ ਦੇਖ ਸਕਦੇ ਹਾਂ, ਨੱਲ ਮੁੱਲ ਦੀ ਥਾਂ ਲੈ ਲਈ ਗਈ ਹੈ। ਕਹਿਣ ਦੀ ਲੋੜ ਨਹੀਂ, ਅਸੀਂ `'True'` ਦੀ ਥਾਂ ਕੁਝ ਵੀ ਲਿਖ ਸਕਦੇ ਸੀ ਅਤੇ ਇਹ ਸਥਾਨਾਪਨ ਹੋ ਜਾਂਦਾ।\n" ] }, { "cell_type": "markdown", "metadata": { "id": "heYe1I0dOmQ_" }, "source": [ "### ਸੰਖਿਆਤਮਕ ਡਾਟਾ\n", "ਹੁਣ, ਸੰਖਿਆਤਮਕ ਡਾਟਾ ਵੱਲ ਆਓ। ਇੱਥੇ, ਗੁੰਮ ਹੋਏ ਮੁੱਲਾਂ ਨੂੰ ਭਰਨ ਦੇ ਦੋ ਆਮ ਤਰੀਕੇ ਹਨ:\n", "\n", "1. ਕਤਾਰ ਦੇ ਮੱਧ (Median) ਨਾਲ ਭਰੋ \n", "2. ਕਤਾਰ ਦੇ ਔਸਤ (Mean) ਨਾਲ ਭਰੋ \n", "\n", "ਜੇ ਡਾਟਾ ਵਿੱਚ ਬਾਹਰਲੇ ਮੁੱਲ (outliers) ਨਾਲ ਝੁਕਾਅ ਹੋਵੇ, ਤਾਂ ਅਸੀਂ ਮੱਧ (Median) ਨਾਲ ਭਰਦੇ ਹਾਂ। ਇਹ ਇਸ ਲਈ ਕਿਉਂਕਿ ਮੱਧ ਬਾਹਰਲੇ ਮੁੱਲਾਂ ਲਈ ਸੰਵੇਦਨਸ਼ੀਲ ਨਹੀਂ ਹੁੰਦਾ।\n", "\n", "ਜਦੋਂ ਡਾਟਾ ਸਧਾਰਨਕ੍ਰਿਤ (normalized) ਹੁੰਦਾ ਹੈ, ਅਸੀਂ ਔਸਤ (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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \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": [ "ਜਿਵੇਂ ਅਸੀਂ ਦੇਖ ਸਕਦੇ ਹਾਂ, ਗੁੰਮ ਹੋਈ ਮੁੱਲ ਨੂੰ ਇਸਦੇ ਔਸਤ ਨਾਲ ਬਦਲ ਦਿੱਤਾ ਗਿਆ ਹੈ।\n" ] }, { "cell_type": "markdown", "metadata": { "id": "jIvF13a1i00Z" }, "source": [ "ਹੁਣ ਆਓ ਅਸੀਂ ਇੱਕ ਹੋਰ ਡਾਟਾਫ੍ਰੇਮ ਦੀ ਕੋਸ਼ਿਸ਼ ਕਰੀਏ, ਅਤੇ ਇਸ ਵਾਰ ਅਸੀਂ 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": [ "ਤੁਸੀਂ ਸਾਰੇ ਖਾਲੀ ਐਂਟਰੀਜ਼ ਨੂੰ ਇੱਕ ਹੀ ਮੁੱਲ ਨਾਲ ਭਰ ਸਕਦੇ ਹੋ, ਜਿਵੇਂ ਕਿ `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. ਸ਼੍ਰੇਣੀਬੱਧ ਡਾਟਾ ਲਈ, ਜ਼ਿਆਦਾਤਰ ਗੁੰਮ ਹੋਏ ਮੁੱਲਾਂ ਨੂੰ ਕਾਲਮ ਦੇ ਮੋਡ ਨਾਲ ਬਦਲਿਆ ਜਾਂਦਾ ਹੈ। \n", "4. ਸੰਖਿਆਤਮਕ ਡਾਟਾ ਲਈ, ਗੁੰਮ ਹੋਏ ਮੁੱਲਾਂ ਨੂੰ ਆਮ ਤੌਰ 'ਤੇ ਕਾਲਮ ਦੇ ਔਸਤ (ਨਾਰਮਲਾਈਜ਼ਡ ਡਾਟਾਸੈਟ ਲਈ) ਜਾਂ ਮੱਧਕ ਨਾਲ ਭਰਿਆ ਜਾਂਦਾ ਹੈ। \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": [] }, { "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": [ "ਤੁਸੀਂ ਅਗਲੇ ਵੈਧ ਮੁੱਲ ਨੂੰ ਪਿੱਛੇ ਵੱਲ ਪ੍ਰਸਾਰਿਤ ਕਰਨ ਲਈ **ਬੈਕ-ਫਿਲ** ਵੀ ਕਰ ਸਕਦੇ ਹੋ ਤਾਂ ਜੋ ਇੱਕ ਨੱਲ ਨੂੰ ਭਰਿਆ ਜਾ ਸਕੇ:\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 ਨਾਲ ਵੀ ਇੱਕੋ ਤਰ੍ਹਾਂ ਕੰਮ ਕਰਦਾ ਹੈ, ਪਰ ਤੁਸੀਂ ਉਸ `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": [ "ਵਿਆਯਾਮ:\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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \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": [ "ਧਿਆਨ ਦਿਓ ਕਿ ਕਾਲਮ 3 ਅਜੇ ਵੀ ਖਾਲੀ ਹੈ: ਡਿਫਾਲਟ ਦਿਸ਼ਾ ਮੁਤਾਬਕ ਮੁੱਲਾਂ ਨੂੰ ਕਤਾਰਾਂ ਅਨੁਸਾਰ ਭਰਿਆ ਜਾਂਦਾ ਹੈ।\n", "\n", "> **ਮੁੱਖ ਗੱਲ:** ਆਪਣੇ ਡਾਟਾਸੈਟ ਵਿੱਚ ਗੁੰਮ ਮੁੱਲਾਂ ਨਾਲ ਨਿਪਟਣ ਦੇ ਕਈ ਤਰੀਕੇ ਹਨ। ਤੁਸੀਂ ਜੋ ਖਾਸ ਰਣਨੀਤੀ ਵਰਤਦੇ ਹੋ (ਉਨ੍ਹਾਂ ਨੂੰ ਹਟਾਉਣਾ, ਬਦਲਣਾ, ਜਾਂ ਇੱਥੇ ਤੱਕ ਕਿ ਕਿਵੇਂ ਬਦਲਣਾ) ਉਹ ਡਾਟਾ ਦੀ ਵਿਸ਼ੇਸ਼ਤਾਵਾਂ ਦੁਆਰਾ ਨਿਰਧਾਰਤ ਹੋਣੀ ਚਾਹੀਦੀ ਹੈ। ਜਿਵੇਂ ਜਿਵੇਂ ਤੁਸੀਂ ਡਾਟਾਸੈਟਸ ਨਾਲ ਵਧੇਰੇ ਕੰਮ ਕਰਦੇ ਹੋ ਅਤੇ ਉਨ੍ਹਾਂ ਨਾਲ ਸੰਚਾਰ ਕਰਦੇ ਹੋ, ਤੁਸੀਂ ਗੁੰਮ ਮੁੱਲਾਂ ਨਾਲ ਨਿਪਟਣ ਦਾ ਬਿਹਤਰ ਅਨੁਭਵ ਵਿਕਸਿਤ ਕਰੋਗੇ।\n" ] }, { "cell_type": "markdown", "metadata": { "id": "bauDnESIl9FH" }, "source": [ "### ਸ਼੍ਰੇਣੀਬੱਧ ਡਾਟਾ ਨੂੰ ਕੋਡ ਕਰਨਾ\n", "\n", "ਮਸ਼ੀਨ ਲਰਨਿੰਗ ਮਾਡਲ ਸਿਰਫ਼ ਨੰਬਰਾਂ ਅਤੇ ਕਿਸੇ ਵੀ ਤਰ੍ਹਾਂ ਦੇ ਸੰਖਿਆਤਮਕ ਡਾਟਾ ਨਾਲ ਕੰਮ ਕਰਦੇ ਹਨ। ਇਹ \"ਹਾਂ\" ਅਤੇ \"ਨਹੀਂ\" ਵਿੱਚ ਫਰਕ ਨਹੀਂ ਕਰ ਸਕਦੇ, ਪਰ ਇਹ 0 ਅਤੇ 1 ਵਿੱਚ ਅੰਤਰ ਕਰ ਸਕਦੇ ਹਨ। ਇਸ ਲਈ, ਗੁੰਮ ਡਾਟਾ ਨੂੰ ਭਰਨ ਤੋਂ ਬਾਅਦ, ਸਾਨੂੰ ਮਾਡਲ ਨੂੰ ਸਮਝਣ ਲਈ ਸ਼੍ਰੇਣੀਬੱਧ ਡਾਟਾ ਨੂੰ ਕੁਝ ਸੰਖਿਆਤਮਕ ਰੂਪ ਵਿੱਚ ਕੋਡ ਕਰਨਾ ਪਵੇਗਾ।\n", "\n", "ਕੋਡਿੰਗ ਦੋ ਤਰੀਕਿਆਂ ਨਾਲ ਕੀਤੀ ਜਾ ਸਕਦੀ ਹੈ। ਅਸੀਂ ਅਗਲੇ ਹਿੱਸੇ ਵਿੱਚ ਇਹਨਾਂ ਬਾਰੇ ਚਰਚਾ ਕਰਾਂਗੇ।\n" ] }, { "cell_type": "markdown", "metadata": { "id": "uDq9SxB7mu5i" }, "source": [ "**ਲੇਬਲ ਐਨਕੋਡਿੰਗ**\n", "\n", "ਲੇਬਲ ਐਨਕੋਡਿੰਗ ਮੂਲ ਰੂਪ ਵਿੱਚ ਹਰ ਸ਼੍ਰੇਣੀ ਨੂੰ ਇੱਕ ਨੰਬਰ ਵਿੱਚ ਬਦਲਣ ਦੀ ਪ੍ਰਕਿਰਿਆ ਹੈ। ਉਦਾਹਰਣ ਲਈ, ਮੰਨੋ ਸਾਡੇ ਕੋਲ ਏਅਰਲਾਈਨ ਯਾਤਰੀਆਂ ਦਾ ਡਾਟਾਸੈਟ ਹੈ ਅਤੇ ਉਸ ਵਿੱਚ ਇੱਕ ਕਾਲਮ ਹੈ ਜੋ ਉਨ੍ਹਾਂ ਦੀ ਕਲਾਸ ਦੱਸਦਾ ਹੈ ['ਬਿਜ਼ਨਸ ਕਲਾਸ', 'ਇਕਨਾਮੀ ਕਲਾਸ', 'ਫਰਸਟ ਕਲਾਸ'] ਵਿੱਚੋਂ। ਜੇ ਇਸ 'ਤੇ ਲੇਬਲ ਐਨਕੋਡਿੰਗ ਕੀਤੀ ਜਾਵੇ, ਤਾਂ ਇਹ [0,1,2] ਵਿੱਚ ਬਦਲ ਜਾਵੇਗਾ। ਆਓ ਇਸ ਨੂੰ ਕੋਡ ਰਾਹੀਂ ਇੱਕ ਉਦਾਹਰਣ ਦੇ ਨਾਲ ਸਮਝੀਏ। ਕਿਉਂਕਿ ਅਸੀਂ ਅਗਲੇ ਨੋਟਬੁੱਕਸ ਵਿੱਚ `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": [ "ਪਹਿਲੇ ਕਤਾਰ 'ਤੇ ਲੇਬਲ ਐਨਕੋਡਿੰਗ ਕਰਨ ਲਈ, ਸਾਨੂੰ ਪਹਿਲਾਂ ਹਰ ਵਰਗ ਤੋਂ ਇੱਕ ਨੰਬਰ ਤੱਕ ਦਾ ਨਕਸ਼ਾ ਬਣਾਉਣਾ ਪਵੇਗਾ, ਇਸ ਤੋਂ ਪਹਿਲਾਂ ਕਿ ਬਦਲਣਾ ਸ਼ੁਰੂ ਕਰੀਏ।\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": [ "ਜਿਵੇਂ ਕਿ ਅਸੀਂ ਵੇਖ ਸਕਦੇ ਹਾਂ, ਨਤੀਜਾ ਉਹੀ ਹੈ ਜੋ ਅਸੀਂ ਸੋਚਿਆ ਸੀ। ਤਾਂ ਫਿਰ, ਅਸੀਂ ਲੇਬਲ ਐਨਕੋਡਿੰਗ ਕਦੋਂ ਵਰਤਦੇ ਹਾਂ? ਲੇਬਲ ਐਨਕੋਡਿੰਗ ਹੇਠਾਂ ਦਿੱਤੇ ਦੋਨੋਂ ਵਿੱਚੋਂ ਕਿਸੇ ਇੱਕ ਜਾਂ ਦੋਨੋਂ ਹਾਲਤਾਂ ਵਿੱਚ ਵਰਤੀ ਜਾਂਦੀ ਹੈ: \n", "1. ਜਦੋਂ ਸ਼੍ਰੇਣੀਆਂ ਦੀ ਗਿਣਤੀ ਵੱਡੀ ਹੋਵੇ \n", "2. ਜਦੋਂ ਸ਼੍ਰੇਣੀਆਂ ਵਿੱਚ ਕ੍ਰਮ ਹੋਵੇ। \n" ] }, { "cell_type": "markdown", "metadata": { "id": "eQPAPVwsqWT7" }, "source": [ "**ਵਨ ਹਾਟ ਇਨਕੋਡਿੰਗ**\n", "\n", "ਇਕ ਹੋਰ ਤਰ੍ਹਾਂ ਦੀ ਇਨਕੋਡਿੰਗ ਵਨ ਹਾਟ ਇਨਕੋਡਿੰਗ ਹੈ। ਇਸ ਤਰ੍ਹਾਂ ਦੀ ਇਨਕੋਡਿੰਗ ਵਿੱਚ, ਕਾਲਮ ਦੀ ਹਰ ਸ਼੍ਰੇਣੀ ਨੂੰ ਇੱਕ ਵੱਖਰੇ ਕਾਲਮ ਵਜੋਂ ਸ਼ਾਮਲ ਕੀਤਾ ਜਾਂਦਾ ਹੈ ਅਤੇ ਹਰ ਡੇਟਾਪੌਇੰਟ ਨੂੰ 0 ਜਾਂ 1 ਮਿਲਦਾ ਹੈ, ਇਸ ਗੱਲ 'ਤੇ ਨਿਰਭਰ ਕਰਦਿਆਂ ਕਿ ਉਹ ਸ਼੍ਰੇਣੀ ਸ਼ਾਮਲ ਹੈ ਜਾਂ ਨਹੀਂ। ਇਸ ਲਈ, ਜੇ n ਵੱਖ-ਵੱਖ ਸ਼੍ਰੇਣੀਆਂ ਹਨ, ਤਾਂ n ਕਾਲਮ ਡੇਟਾਫਰੇਮ ਵਿੱਚ ਸ਼ਾਮਲ ਕੀਤੇ ਜਾਣਗੇ।\n", "\n", "ਉਦਾਹਰਣ ਵਜੋਂ, ਆਓ ਉਹੀ ਜਹਾਜ਼ ਦੀ ਕਲਾਸ ਵਾਲਾ ਉਦਾਹਰਣ ਲਵਾਂ। ਸ਼੍ਰੇਣੀਆਂ ਸਨ: ['ਬਿਜ਼ਨਸ ਕਲਾਸ', 'ਇਕਨਾਮੀ ਕਲਾਸ', 'ਫਰਸਟ ਕਲਾਸ']। ਇਸ ਲਈ, ਜੇ ਅਸੀਂ ਵਨ ਹਾਟ ਇਨਕੋਡਿੰਗ ਕਰਦੇ ਹਾਂ, ਤਾਂ ਹੇਠ ਲਿਖੇ ਤਿੰਨ ਕਾਲਮ ਡੇਟਾਸੈੱਟ ਵਿੱਚ ਸ਼ਾਮਲ ਕੀਤੇ ਜਾਣਗੇ: ['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": [ "ਆਓ ਅਸੀਂ ਪਹਿਲੇ ਕਾਲਮ 'ਤੇ ਇੱਕ ਹੌਟ ਐਨਕੋਡਿੰਗ ਕਰੀਏ\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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \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": [ "ਹਰ ਇੱਕ ਹੌਟ ਐਨਕੋਡ ਕੀਤੀ ਕਾਲਮ ਵਿੱਚ 0 ਜਾਂ 1 ਹੁੰਦਾ ਹੈ, ਜੋ ਇਹ ਦਰਸਾਉਂਦਾ ਹੈ ਕਿ ਕੀ ਉਹ ਸ਼੍ਰੇਣੀ ਉਸ ਡੇਟਾਪੌਇੰਟ ਲਈ ਮੌਜੂਦ ਹੈ।\n" ] }, { "cell_type": "markdown", "metadata": { "id": "bDnC4NQOu0qr" }, "source": [ "ਅਸੀਂ ਇੱਕ ਹੌਟ ਇਨਕੋਡਿੰਗ ਕਦੋਂ ਵਰਤਦੇ ਹਾਂ? ਇੱਕ ਹੌਟ ਇਨਕੋਡਿੰਗ ਹੇਠਾਂ ਦਿੱਤੇ ਦੋਨੋਂ ਜਾਂ ਦੋਨੋਂ ਹੀ ਮਾਮਲਿਆਂ ਵਿੱਚ ਵਰਤੀ ਜਾਂਦੀ ਹੈ:\n", "\n", "1. ਜਦੋਂ ਸ਼੍ਰੇਣੀਆਂ ਦੀ ਗਿਣਤੀ ਅਤੇ ਡਾਟਾਸੈਟ ਦਾ ਆਕਾਰ ਛੋਟਾ ਹੁੰਦਾ ਹੈ।\n", "2. ਜਦੋਂ ਸ਼੍ਰੇਣੀਆਂ ਕਿਸੇ ਖਾਸ ਕ੍ਰਮ ਦੀ ਪਾਲਣਾ ਨਹੀਂ ਕਰਦੀਆਂ।\n" ] }, { "cell_type": "markdown", "metadata": { "id": "XnUmci_4uvyu" }, "source": [ "> ਮੁੱਖ ਗੱਲਾਂ:\n", "1. ਐਨਕੋਡਿੰਗ ਦਾ ਉਦੇਸ਼ ਗਿਣਤੀ ਨਾ ਹੋਣ ਵਾਲੇ ਡਾਟਾ ਨੂੰ ਗਿਣਤੀ ਵਾਲੇ ਡਾਟਾ ਵਿੱਚ ਬਦਲਣਾ ਹੈ। \n", "2. ਐਨਕੋਡਿੰਗ ਦੇ ਦੋ ਪ੍ਰਕਾਰ ਹਨ: ਲੇਬਲ ਐਨਕੋਡਿੰਗ ਅਤੇ ਵਨ ਹਾਟ ਐਨਕੋਡਿੰਗ, ਜਿਨ੍ਹਾਂ ਨੂੰ ਡਾਟਾਸੈੱਟ ਦੀ ਲੋੜਾਂ ਦੇ ਅਧਾਰ 'ਤੇ ਕੀਤਾ ਜਾ ਸਕਦਾ ਹੈ। \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` ਵਿਧੀ ਦੀ ਵਰਤੋਂ ਕਰਕੇ ਆਸਾਨੀ ਨਾਲ ਨਕਲੀਆਂ ਮੁੱਲਾਂ ਨੂੰ ਪਛਾਣ ਸਕਦੇ ਹੋ, ਜੋ ਇੱਕ ਬੂਲੀਅਨ ਮਾਸਕ ਵਾਪਸ ਕਰਦੀ ਹੈ ਜੋ ਦੱਸਦੀ ਹੈ ਕਿ `DataFrame` ਵਿੱਚ ਕੋਈ ਐਨਟਰੀ ਪਹਿਲਾਂ ਦੀ ਨਕਲ ਹੈ ਜਾਂ ਨਹੀਂ। ਆਓ ਇਸਨੂੰ ਕਾਰਵਾਈ ਵਿੱਚ ਦੇਖਣ ਲਈ ਇੱਕ ਹੋਰ ਉਦਾਹਰਣ `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:32:48+00:00", "source_file": "2-Working-With-Data/08-data-preparation/notebook.ipynb", "language_code": "pa" } }, "nbformat": 4, "nbformat_minor": 0 }