diff --git a/1-Introduction/01-defining-data-science/README.md b/1-Introduction/01-defining-data-science/README.md
index aa92a9c..bedbb1e 100644
--- a/1-Introduction/01-defining-data-science/README.md
+++ b/1-Introduction/01-defining-data-science/README.md
@@ -6,7 +6,7 @@
---
-[![Defining Data Science Video](images/video-def-ds.png)](https://youtu.be/pqqsm5reGvs)
+[![Defining Data Science Video](images/video-def-ds.png)](https://youtu.be/beZ7Mb_oz9I)
## [Pre-lecture quiz](https://red-water-0103e7a0f.azurestaticapps.net/quiz/0)
diff --git a/2-Working-With-Data/08-data-preparation/notebook.ipynb b/2-Working-With-Data/08-data-preparation/notebook.ipynb
index 93c37c3..448de5f 100644
--- a/2-Working-With-Data/08-data-preparation/notebook.ipynb
+++ b/2-Working-With-Data/08-data-preparation/notebook.ipynb
@@ -1,7 +1,36 @@
{
+ "nbformat": 4,
+ "nbformat_minor": 0,
+ "metadata": {
+ "anaconda-cloud": {},
+ "kernelspec": {
+ "name": "python3",
+ "display_name": "Python 3",
+ "language": "python"
+ },
+ "language_info": {
+ "mimetype": "text/x-python",
+ "nbconvert_exporter": "python",
+ "name": "python",
+ "file_extension": ".py",
+ "version": "3.5.4",
+ "pygments_lexer": "ipython3",
+ "codemirror_mode": {
+ "version": 3,
+ "name": "ipython"
+ }
+ },
+ "colab": {
+ "name": "notebook.ipynb",
+ "provenance": []
+ }
+ },
"cells": [
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "rQ8UhzFpgRra"
+ },
"source": [
"# Data Preparation\n",
"\n",
@@ -11,15 +40,20 @@
"\n",
"> **Learning goal:** By the end of this subsection, you should be comfortable finding general information about the data stored in pandas DataFrames.\n",
"\n",
- "Once you have loaded your data into pandas, it will more likely than not be in a `DataFrame`. \n",
+
+ "Once you have loaded your data into pandas, it will more likely than not be in a `DataFrame`. However, if the data set in your `DataFrame` has 60,000 rows and 400 columns, how do you even begin to get a sense of what you're working with? Fortunately, pandas provides some convenient tools to quickly look at overall information about a `DataFrame` in addition to the first few and last few rows.\n",
"\n",
- "In order to explore our `DataFramme`, we will import the Python `scikit-learn` library and use an iconic dataset that every data scientist has seen hundreds of times: British biologist Ronald Fisher's **Iris data set** used in his 1936 paper \"*The use of multiple measurements in taxonomic problems*\":"
- ],
- "metadata": {}
+ "In order to explore this functionality, we will import the Python scikit-learn library and use an iconic dataset that every data scientist has seen hundreds of times: British biologist Ronald Fisher's *Iris* data set used in his 1936 paper \"The use of multiple measurements in taxonomic problems\":"
+ ]
},
{
"cell_type": "code",
- "execution_count": 1,
+ "metadata": {
+ "collapsed": true,
+ "trusted": false,
+ "id": "hB1RofhdgRrp"
+ },
+
"source": [
"import pandas as pd\n",
"from sklearn.datasets import load_iris\n",
@@ -27,26 +61,129 @@
"iris = load_iris()\n",
"iris_df = pd.DataFrame(data=iris['data'], columns=iris['feature_names'])"
],
- "outputs": [],
+ "execution_count": 1,
+ "outputs": []
+ },
+ {
+ "cell_type": "markdown",
"metadata": {
- "collapsed": true,
- "trusted": false
- }
+ "id": "AGA0A_Y8hMdz"
+ },
+ "source": [
+ "### `DataFrame.shape`\n",
+ "We have loaded the Iris Dataset in the variable `iris_df`. Before diving into the data, it would be valuable to know the number of datapoints we have and the overall size of the dataset. It is useful to look at the volume of data we are dealing with. "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "metadata": {
+ "id": "LOe5jQohhulf",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "outputId": "fb0577ac-3b4a-4623-cb41-20e1b264b3e9"
+ },
+ "source": [
+ "iris_df.shape"
+ ],
+ "execution_count": 2,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ "(150, 4)"
+ ]
+ },
+ "metadata": {},
+ "execution_count": 2
+ }
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "smE7AGzOhxk2"
+ },
+ "source": [
+ "So, we are dealing with 150 rows and 4 columns of data. Each row represents one datapoint and each column represents a single feature associated with the data frame. So basically, there are 150 datapoints containing 4 features each.\n",
+ "\n",
+ "`shape` here is an attribute of the dataframe and not a function, which is why it doesn't end in a pair of parentheses. "
+ ]
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "d3AZKs0PinGP"
+ },
"source": [
- "### `DataFrame.info`\r\n",
- "Let's take a look at this dataset to see what we have:"
+ "### `DataFrame.columns`\n",
+ "Let us now move into the 4 columns of data. What does each of them exactly represent? The `columns` attribute will give us the name of the columns in the dataframe. "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "metadata": {
+ "id": "YPGh_ziji-CY",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "outputId": "74e7a43a-77cc-4c80-da56-7f50767c37a0"
+ },
+ "source": [
+ "iris_df.columns"
],
- "metadata": {}
+ "execution_count": 3,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ "Index(['sepal length (cm)', 'sepal width (cm)', 'petal length (cm)',\n",
+ " 'petal width (cm)'],\n",
+ " dtype='object')"
+ ]
+ },
+ "metadata": {},
+ "execution_count": 3
+ }
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "TsobcU_VjCC_"
+ },
+ "source": [
+ "As we can see, there are four(4) columns. The `columns` attribute tells us the name of the columns and basically nothing else. This attribute assumes importance when we want to identify the features a dataset contains."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "2UTlvkjmgRrs"
+ },
+ "source": [
+ "### `DataFrame.info`\n",
+ "The amount of data(given by the `shape` attribute) and the name of the features or columns(given by the `columns` attribute) tell us something about the dataset. Now, we would want to dive deeper into the dataset. The `DataFrame.info()` function is quite useful for this. "
+ ]
},
{
"cell_type": "code",
- "execution_count": 2,
+
+ "metadata": {
+ "trusted": false,
+ "id": "dHHRyG0_gRrt",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "outputId": "d8fb0c40-4f18-4e19-da48-c8db77d1d3a5"
+ },
"source": [
"iris_df.info()"
],
+ "execution_count": 4,
+
"outputs": [
{
"output_type": "stream",
@@ -65,32 +202,189 @@
"memory usage: 4.8 KB\n"
]
}
- ],
+
+ ]
+ },
+ {
+ "cell_type": "markdown",
"metadata": {
- "trusted": false
- }
+ "id": "1XgVMpvigRru"
+ },
+ "source": [
+ "From here, we get to can make a few observations:\n",
+ "1. The DataType of each column: In this dataset, all of the data is stored as 64-bit floating-point numbers.\n",
+ "2. Number of Non-Null values: Dealing with null values is an important step in data preparation. It will be dealt with later in the notebook."
+ ]
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "IYlyxbpWFEF4"
+ },
+ "source": [
+ "### DataFrame.describe()\n",
+ "Say we have a lot of numerical data in our dataset. Univariate statistical calculations such as the mean, median, quartiles etc. can be done on each of the columns individually. The `DataFrame.describe()` function provides us with a statistical summary of the numerical columns of a dataset.\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "metadata": {
+ "id": "tWV-CMstFIRA",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 297
+ },
+ "outputId": "4fc49941-bc13-4b0c-a412-cb39e7d3f289"
+ },
"source": [
- "From this, we know that the *Iris* dataset has 150 entries in four columns. All of the data is stored as 64-bit floating-point numbers."
+ "iris_df.describe()"
],
- "metadata": {}
+ "execution_count": 5,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/html": [
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " sepal length (cm) | \n",
+ " sepal width (cm) | \n",
+ " petal length (cm) | \n",
+ " petal width (cm) | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " count | \n",
+ " 150.000000 | \n",
+ " 150.000000 | \n",
+ " 150.000000 | \n",
+ " 150.000000 | \n",
+ "
\n",
+ " \n",
+ " mean | \n",
+ " 5.843333 | \n",
+ " 3.057333 | \n",
+ " 3.758000 | \n",
+ " 1.199333 | \n",
+ "
\n",
+ " \n",
+ " std | \n",
+ " 0.828066 | \n",
+ " 0.435866 | \n",
+ " 1.765298 | \n",
+ " 0.762238 | \n",
+ "
\n",
+ " \n",
+ " min | \n",
+ " 4.300000 | \n",
+ " 2.000000 | \n",
+ " 1.000000 | \n",
+ " 0.100000 | \n",
+ "
\n",
+ " \n",
+ " 25% | \n",
+ " 5.100000 | \n",
+ " 2.800000 | \n",
+ " 1.600000 | \n",
+ " 0.300000 | \n",
+ "
\n",
+ " \n",
+ " 50% | \n",
+ " 5.800000 | \n",
+ " 3.000000 | \n",
+ " 4.350000 | \n",
+ " 1.300000 | \n",
+ "
\n",
+ " \n",
+ " 75% | \n",
+ " 6.400000 | \n",
+ " 3.300000 | \n",
+ " 5.100000 | \n",
+ " 1.800000 | \n",
+ "
\n",
+ " \n",
+ " max | \n",
+ " 7.900000 | \n",
+ " 4.400000 | \n",
+ " 6.900000 | \n",
+ " 2.500000 | \n",
+ "
\n",
+ " \n",
+ "
\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"
+ ]
+ },
+ "metadata": {},
+ "execution_count": 5
+ }
+ ]
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "zjjtW5hPGMuM"
+ },
"source": [
- "### `DataFrame.head`\r\n",
- "Next, let's see what the first few rows of our `DataFrame` look like:"
- ],
- "metadata": {}
+ "The output above shows the total number of data points, mean, standard deviation, minimum, lower quartile(25%), median(50%), upper quartile(75%) and the maximum value of each column."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "-lviAu99gRrv"
+ },
+ "source": [
+ "### `DataFrame.head`\n",
+ "With all the above functions and attributes, we have got a top level view of the dataset. We know how many data points are there, how many features are there, the data type of each feature and the number of non-null values for each feature.\n",
+ "\n",
+ "Now its time to look at the data itself. Let's see what the first few rows(the first few datapoints) of our `DataFrame` look like:"
+ ]
},
{
"cell_type": "code",
- "execution_count": 3,
+
+ "metadata": {
+ "trusted": false,
+ "id": "DZMJZh0OgRrw",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 204
+ },
+ "outputId": "d9393ee5-c106-4797-f815-218f17160e00"
+ },
"source": [
"iris_df.head()"
],
+ "execution_count": 6,
"outputs": [
{
"output_type": "execute_result",
@@ -170,48 +464,71 @@
]
},
"metadata": {},
- "execution_count": 3
+
+ "execution_count": 6
}
- ],
+ ]
+ },
+ {
+ "cell_type": "markdown",
"metadata": {
- "trusted": false
- }
+ "id": "EBHEimZuEFQK"
+ },
+ "source": [
+ "As the output here, we can see five(5) entries of the dataset. If we look at the index at the left, we find out that these are the first five rows."
+ ]
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "oj7GkrTdgRry"
+ },
"source": [
- "### Exercise:\r\n",
- "\r\n",
- "By default, `DataFrame.head` returns the first five rows of a `DataFrame`. In the code cell below, can you figure out how to get it to show more?"
- ],
- "metadata": {}
+ "### Exercise:\n",
+ "\n",
+ "From the example given above, it is clear that, by default, `DataFrame.head` returns the first five rows of a `DataFrame`. In the code cell below, can you figure out a way to display more than five rows?"
+ ]
},
{
"cell_type": "code",
- "execution_count": 4,
+
+ "metadata": {
+ "collapsed": true,
+ "trusted": false,
+ "id": "EKRmRFFegRrz"
+ },
"source": [
"# Hint: Consult the documentation by using iris_df.head?"
],
- "outputs": [],
- "metadata": {
- "collapsed": true,
- "trusted": false
- }
+ "execution_count": 7,
+ "outputs": []
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "BJ_cpZqNgRr1"
+ },
"source": [
- "### `DataFrame.tail`\r\n",
- "The flipside of `DataFrame.head` is `DataFrame.tail`, which returns the last five rows of a `DataFrame`:"
- ],
- "metadata": {}
+ "### `DataFrame.tail`\n",
+ "Another way of looking at the data can be from the end(instead of the beginning). The flipside of `DataFrame.head` is `DataFrame.tail`, which returns the last five rows of a `DataFrame`:"
+ ]
},
{
"cell_type": "code",
- "execution_count": 5,
+
+ "metadata": {
+ "trusted": false,
+ "id": "heanjfGWgRr2",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 0
+ },
+ "outputId": "6ae09a21-fe09-4110-b0d7-1a1fbf34d7f3"
+ },
"source": [
"iris_df.tail()"
],
+ "execution_count": 8,
"outputs": [
{
"output_type": "execute_result",
@@ -291,56 +608,76 @@
]
},
"metadata": {},
- "execution_count": 5
+
+ "execution_count": 8
}
- ],
- "metadata": {
- "trusted": false
- }
+ ]
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "31kBWfyLgRr3"
+ },
"source": [
- "In practice, it is useful to be able to easily examine the first few rows or the last few rows of a `DataFrame`, particularly when you are looking for outliers in ordered datasets.\r\n",
- "\r\n",
+ "In practice, it is useful to be able to easily examine the first few rows or the last few rows of a `DataFrame`, particularly when you are looking for outliers in ordered datasets. \n",
+ "\n",
+ "All the functions and attributes shown above with the help of code examples, help us get a look and feel of the data. \n",
+ "\n",
"> **Takeaway:** Even just by looking at the metadata about the information in a DataFrame or the first and last few values in one, you can get an immediate idea about the size, shape, and content of the data you are dealing with."
- ],
- "metadata": {}
+ ]
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "TvurZyLSDxq_"
+ },
"source": [
- "## Dealing with missing data\r\n",
- "\r\n",
- "> **Learning goal:** By the end of this subsection, you should know how to replace or remove null values from DataFrames.\r\n",
- "\r\n",
- "Most of the time the datasets you want to use (of have to use) have missing values in them. How missing data is handled carries with it subtle tradeoffs that can affect your final analysis and real-world outcomes.\r\n",
- "\r\n",
- "Pandas handles missing values in two ways. The first you've seen before in previous sections: `NaN`, or Not a Number. This is a actually a special value that is part of the IEEE floating-point specification and it is only used to indicate missing floating-point values.\r\n",
- "\r\n",
+ "### Missing Data\n",
+ "Let us dive into missing data. Missing data occurs, when no value is sotred in some of the columns. \n",
+ "\n",
+ "Let us take an example: say someone is concious about his/her weight and doesn't fill the weight field in a survey. Then, the weight value for that certain person will be missing. \n",
+ "\n",
+ "Most of the time, in real world datasets, missing values occur.\n",
+ "\n",
+ "**How Pandas Handles missing data**\n",
+ "\n",
+ "\n",
+ "Pandas handles missing values in two ways. The first you've seen before in previous sections: `NaN`, or Not a Number. This is a actually a special value that is part of the IEEE floating-point specification and it is only used to indicate missing floating-point values.\n",
+ "\n",
"For missing values apart from floats, pandas uses the Python `None` object. While it might seem confusing that you will encounter two different kinds of values that say essentially the same thing, there are sound programmatic reasons for this design choice and, in practice, going this route enables pandas to deliver a good compromise for the vast majority of cases. Notwithstanding this, both `None` and `NaN` carry restrictions that you need to be mindful of with regards to how they can be used."
- ],
- "metadata": {}
+ ]
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "lOHqUlZFgRr5"
+ },
"source": [
- "### `None`: non-float missing data\r\n",
- "Because `None` comes from Python, it cannot be used in NumPy and pandas arrays that are not of data type `'object'`. Remember, NumPy arrays (and the data structures in pandas) can contain only one type of data. This is what gives them their tremendous power for large-scale data and computational work, but it also limits their flexibility. Such arrays have to upcast to the “lowest common denominator,” the data type that will encompass everything in the array. When `None` is in the array, it means you are working with Python objects.\r\n",
- "\r\n",
+ "### `None`: non-float missing data\n",
+ "Because `None` comes from Python, it cannot be used in NumPy and pandas arrays that are not of data type `'object'`. Remember, NumPy arrays (and the data structures in pandas) can contain only one type of data. This is what gives them their tremendous power for large-scale data and computational work, but it also limits their flexibility. Such arrays have to upcast to the “lowest common denominator,” the data type that will encompass everything in the array. When `None` is in the array, it means you are working with Python objects.\n",
+ "\n",
"To see this in action, consider the following example array (note the `dtype` for it):"
- ],
- "metadata": {}
+ ]
},
{
"cell_type": "code",
- "execution_count": 6,
+
+ "metadata": {
+ "trusted": false,
+ "id": "QIoNdY4ngRr7",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "outputId": "92779f18-62f4-4a03-eca2-e9a101604336"
+ },
"source": [
"import numpy as np\n",
"\n",
"example1 = np.array([2, None, 6, 8])\n",
"example1"
],
+
+ "execution_count": 9,
"outputs": [
{
"output_type": "execute_result",
@@ -350,68 +687,97 @@
]
},
"metadata": {},
+
+ "execution_count": 9
+ }
+ ]
+
"execution_count": 6
}
],
"metadata": {
"trusted": false
}
+
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "pdlgPNbhgRr7"
+ },
"source": [
"The reality of upcast data types carries two side effects with it. First, operations will be carried out at the level of interpreted Python code rather than compiled NumPy code. Essentially, this means that any operations involving `Series` or `DataFrames` with `None` in them will be slower. While you would probably not notice this performance hit, for large datasets it might become an issue.\n",
"\n",
"The second side effect stems from the first. Because `None` essentially drags `Series` or `DataFrame`s back into the world of vanilla Python, using NumPy/pandas aggregations like `sum()` or `min()` on arrays that contain a ``None`` value will generally produce an error:"
- ],
- "metadata": {}
+ ]
},
{
"cell_type": "code",
- "execution_count": 7,
+
+ "metadata": {
+ "trusted": false,
+ "id": "gWbx-KB9gRr8",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 292
+ },
+ "outputId": "ecba710a-22ec-41d5-a39c-11f67e645b50"
+ },
"source": [
"example1.sum()"
],
+ "execution_count": 10,
"outputs": [
{
"output_type": "error",
"ename": "TypeError",
- "evalue": "unsupported operand type(s) for +: 'int' and 'NoneType'",
+
+ "evalue": "ignored",
"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~/anaconda3/lib/python3.8/site-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;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'"
]
}
- ],
- "metadata": {
- "trusted": false
- }
+ ]
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "LcEwO8UogRr9"
+ },
"source": [
"**Key takeaway**: Addition (and other operations) between integers and `None` values is undefined, which can limit what you can do with datasets that contain them."
- ],
- "metadata": {}
+ ]
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "pWvVHvETgRr9"
+ },
"source": [
"### `NaN`: missing float values\n",
"\n",
"In contrast to `None`, NumPy (and therefore pandas) supports `NaN` for its fast, vectorized operations and ufuncs. The bad news is that any arithmetic performed on `NaN` always results in `NaN`. For example:"
- ],
- "metadata": {}
+ ]
},
{
"cell_type": "code",
- "execution_count": 8,
+
+ "metadata": {
+ "trusted": false,
+ "id": "rcFYfMG9gRr9",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "outputId": "699e81b7-5c11-4b46-df1d-06071768690f"
+ },
"source": [
"np.nan + 1"
],
+ "execution_count": 11,
"outputs": [
{
"output_type": "execute_result",
@@ -421,19 +787,25 @@
]
},
"metadata": {},
- "execution_count": 8
+
+ "execution_count": 11
}
- ],
- "metadata": {
- "trusted": false
- }
+ ]
},
{
"cell_type": "code",
- "execution_count": 9,
+ "metadata": {
+ "trusted": false,
+ "id": "BW3zQD2-gRr-",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "outputId": "4525b6c4-495d-4f7b-a979-efce1dae9bd0"
+ },
"source": [
"np.nan * 0"
],
+ "execution_count": 12,
"outputs": [
{
"output_type": "execute_result",
@@ -443,27 +815,48 @@
]
},
"metadata": {},
+
+ "execution_count": 12
+ }
+ ]
+
"execution_count": 9
}
],
"metadata": {
"trusted": false
}
+
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "fU5IPRcCgRr-"
+ },
"source": [
"The good news: aggregations run on arrays with `NaN` in them don't pop errors. The bad news: the results are not uniformly useful:"
- ],
- "metadata": {}
+ ]
},
{
"cell_type": "code",
+
+ "metadata": {
+ "trusted": false,
+ "id": "LCInVgSSgRr_",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "outputId": "fa06495a-0930-4867-87c5-6023031ea8b5"
+ },
+
"execution_count": 10,
+
"source": [
"example2 = np.array([2, np.nan, 6, 8]) \n",
"example2.sum(), example2.min(), example2.max()"
],
+
+ "execution_count": 13,
"outputs": [
{
"output_type": "execute_result",
@@ -473,55 +866,85 @@
]
},
"metadata": {},
+
+ "execution_count": 13
+ }
+ ]
"execution_count": 10
}
],
"metadata": {
"trusted": false
}
+
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "nhlnNJT7gRr_"
+ },
"source": [
"### Exercise:"
- ],
- "metadata": {}
+ ]
},
{
"cell_type": "code",
+
"execution_count": 11,
"source": [
"# What happens if you add np.nan and None together?\n"
],
"outputs": [],
+
"metadata": {
"collapsed": true,
- "trusted": false
- }
- },
- {
- "cell_type": "markdown",
+ "trusted": false,
+ "id": "yan3QRaOgRr_"
+ },
"source": [
- "Remember: `NaN` is just for missing floating-point values; there is no `NaN` equivalent for integers, strings, or Booleans."
+ "# What happens if you add np.nan and None together?\n"
],
- "metadata": {}
+ "execution_count": 14,
+ "outputs": []
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "_iDvIRC8gRsA"
+ },
+ "source": [
+ "Remember: `NaN` is just for missing floating-point values; there is no `NaN` equivalent for integers, strings, or Booleans."
+ ]
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "kj6EKdsAgRsA"
+ },
"source": [
"### `NaN` and `None`: null values in pandas\n",
"\n",
"Even though `NaN` and `None` can behave somewhat differently, pandas is nevertheless built to handle them interchangeably. To see what we mean, consider a `Series` of integers:"
- ],
- "metadata": {}
+ ]
},
{
"cell_type": "code",
- "execution_count": 12,
+
+ "metadata": {
+ "trusted": false,
+ "id": "Nji-KGdNgRsA",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "outputId": "36aa14d2-8efa-4bfd-c0ed-682991288822"
+ },
"source": [
"int_series = pd.Series([1, 2, 3], dtype=int)\n",
"int_series"
],
+
+ "execution_count": 15,
+
"outputs": [
{
"output_type": "execute_result",
@@ -534,36 +957,40 @@
]
},
"metadata": {},
- "execution_count": 12
+
+ "execution_count": 15
}
- ],
- "metadata": {
- "trusted": false
- }
+ ]
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "WklCzqb8gRsB"
+ },
"source": [
"### Exercise:"
- ],
- "metadata": {}
+ ]
},
{
"cell_type": "code",
- "execution_count": 13,
+ "metadata": {
+ "collapsed": true,
+ "trusted": false,
+ "id": "Cy-gqX5-gRsB"
+ },
"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"
],
- "outputs": [],
- "metadata": {
- "collapsed": true,
- "trusted": false
- }
+ "execution_count": 16,
+ "outputs": []
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "WjMQwltNgRsB"
+ },
"source": [
"In the process of upcasting data types to establish data homogeneity in `Seires` and `DataFrame`s, pandas will willingly switch missing values between `None` and `NaN`. Because of this design feature, it can be helpful to think of `None` and `NaN` as two different flavors of \"null\" in pandas. Indeed, some of the core methods you will use to deal with missing values in pandas reflect this idea in their names:\n",
"\n",
@@ -573,35 +1000,49 @@
"- `fillna()`: Returns a copy of the data with missing values filled or imputed\n",
"\n",
"These are important methods to master and get comfortable with, so let's go over them each in some depth."
- ],
- "metadata": {}
+ ]
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "Yh5ifd9FgRsB"
+ },
"source": [
"### Detecting null values\n",
+ "\n",
+ "Now that we have understood the importance of missing values, we need to detect them in our dataset, before dealing with them.\n",
"Both `isnull()` and `notnull()` are your primary methods for detecting null data. Both return Boolean masks over your data."
- ],
- "metadata": {}
+ ]
},
{
"cell_type": "code",
- "execution_count": 14,
+
+ "metadata": {
+ "collapsed": true,
+ "trusted": false,
+ "id": "e-vFp5lvgRsC"
+ },
"source": [
"example3 = pd.Series([0, np.nan, '', None])"
],
- "outputs": [],
- "metadata": {
- "collapsed": true,
- "trusted": false
- }
+ "execution_count": 17,
+ "outputs": []
},
{
"cell_type": "code",
- "execution_count": 15,
+
+ "metadata": {
+ "trusted": false,
+ "id": "1XdaJJ7PgRsC",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "outputId": "92fc363a-1874-471f-846d-f4f9ce1f51d0"
+ },
"source": [
"example3.isnull()"
],
+ "execution_count": 18,
"outputs": [
{
"output_type": "execute_result",
@@ -615,65 +1056,139 @@
]
},
"metadata": {},
- "execution_count": 15
+
+ "execution_count": 18
}
- ],
- "metadata": {
- "trusted": false
- }
+ ]
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "PaSZ0SQygRsC"
+ },
"source": [
"Look closely at the output. Does any of it surprise you? While `0` is an arithmetic null, it's nevertheless a perfectly good integer and pandas treats it as such. `''` is a little more subtle. While we used it in Section 1 to represent an empty string value, it is nevertheless a string object and not a representation of null as far as pandas is concerned.\n",
"\n",
- "Now, let's turn this around and use these methods in a manner more like you will use them in practice. You can use Boolean masks directly as a ``Series`` or ``DataFrame`` index, which can be useful when trying to work with isolated missing (or present) values."
+ "Now, let's turn this around and use these methods in a manner more like you will use them in practice. You can use Boolean masks directly as a ``Series`` or ``DataFrame`` index, which can be useful when trying to work with isolated missing (or present) values.\n",
+ "\n",
+ "If we want the total number of missing values, we can just do a sum over the mask produced by the `isnull()` method."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "JCcQVoPkHDUv",
+ "outputId": "001daa72-54f8-4bd5-842a-4df627a79d4d"
+ },
+ "source": [
+ "example3.isnull().sum()"
],
- "metadata": {}
+ "execution_count": 19,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ "2"
+ ]
+ },
+ "metadata": {},
+ "execution_count": 19
+ }
+ ]
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "PlBqEo3mgRsC"
+ },
"source": [
"### Exercise:"
- ],
- "metadata": {}
+ ]
},
{
"cell_type": "code",
- "execution_count": 16,
+
+ "metadata": {
+ "collapsed": true,
+ "trusted": false,
+ "id": "ggDVf5uygRsD"
+ },
+
"source": [
"# Try running example3[example3.notnull()].\n",
"# Before you do so, what do you expect to see?\n"
],
- "outputs": [],
+ "execution_count": 20,
+ "outputs": []
+ },
+ {
+ "cell_type": "markdown",
"metadata": {
- "collapsed": true,
- "trusted": false
- }
+ "id": "D_jWN7mHgRsD"
+ },
+ "source": [
+ "**Key takeaway**: Both the `isnull()` and `notnull()` methods produce similar results when you use them in DataFrames: they show the results and the index of those results, which will help you enormously as you wrestle with your data."
+ ]
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "BvnoojWsgRr4"
+ },
"source": [
- "**Key takeaway**: Both the `isnull()` and `notnull()` methods produce similar results when you use them in `DataFrame`s: they show the results and the index of those results, which will help you enormously as you wrestle with your data."
- ],
- "metadata": {}
+ "### Dealing with missing data\n",
+ "\n",
+ "> **Learning goal:** By the end of this subsection, you should know how and when to replace or remove null values from DataFrames.\n",
+ "\n",
+ "Machine Learning models can't deal with missing data themselves. So, before passing the data into the model, we need to deal with these missing values.\n",
+ "\n",
+ "How missing data is handled carries with it subtle tradeoffs, can affect your final analysis and real-world outcomes.\n",
+ "\n",
+ "There are primarily two ways of dealing with missing data:\n",
+ "\n",
+ "\n",
+ "1. Drop the row containing the missing value\n",
+ "2. Replace the missing value with some other value\n",
+ "\n",
+ "We will discuss both these methods and their pros and cons in details.\n",
+ "\n"
+ ]
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "3VaYC1TvgRsD"
+ },
"source": [
"### Dropping null values\n",
"\n",
- "Beyond identifying missing values, pandas provides a convenient means to remove null values from `Series` and `DataFrame`s. (Particularly on large data sets, it is often more advisable to simply remove missing [NA] values from your analysis than deal with them in other ways.) To see this in action, let's return to `example3`:"
- ],
- "metadata": {}
+ "The amount of data we pass on to our model has a direct effect on its performance. Dropping null values means that we are reducing the number of datapoints, and hence reducing the size of the dataset. So, it is advisable to drop rows with null values when the dataset is quite large.\n",
+ "\n",
+ "Another instance maybe that a certain row or column has a lot of missing values. Then, they maybe dropped because they wouldn't add much value to our analysis as most of the data is missing for that row/column.\n",
+ "\n",
+ "Beyond identifying missing values, pandas provides a convenient means to remove null values from `Series` and `DataFrame`s. To see this in action, let's return to `example3`. The `DataFrame.dropna()` function helps in dropping the rows with null values. "
+ ]
},
{
"cell_type": "code",
- "execution_count": 17,
+
+ "metadata": {
+ "trusted": false,
+ "id": "7uIvS097gRsD",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "outputId": "c13fc117-4ca1-4145-a0aa-42ac89e6e218"
+ },
"source": [
"example3 = example3.dropna()\n",
"example3"
],
+ "execution_count": 21,
"outputs": [
{
"output_type": "execute_result",
@@ -685,31 +1200,43 @@
]
},
"metadata": {},
- "execution_count": 17
+
+ "execution_count": 21
}
- ],
- "metadata": {
- "trusted": false
- }
+ ]
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "hil2cr64gRsD"
+ },
"source": [
"Note that this should look like your output from `example3[example3.notnull()]`. The difference here is that, rather than just indexing on the masked values, `dropna` has removed those missing values from the `Series` `example3`.\n",
"\n",
- "Because `DataFrame`s have two dimensions, they afford more options for dropping data."
- ],
- "metadata": {}
+ "Because DataFrames have two dimensions, they afford more options for dropping data."
+ ]
},
{
"cell_type": "code",
- "execution_count": 18,
+
+ "metadata": {
+ "trusted": false,
+ "id": "an-l74sPgRsE",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 142
+ },
+ "outputId": "340876a0-63ad-40f6-bd54-6240cdae50ab"
+ },
+
"source": [
"example4 = pd.DataFrame([[1, np.nan, 7], \n",
" [2, 5, 8], \n",
" [np.nan, 6, 9]])\n",
"example4"
],
+
+ "execution_count": 22,
"outputs": [
{
"output_type": "execute_result",
@@ -769,28 +1296,38 @@
]
},
"metadata": {},
- "execution_count": 18
+
+ "execution_count": 22
}
- ],
- "metadata": {
- "trusted": false
- }
+ ]
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "66wwdHZrgRsE"
+ },
"source": [
"(Did you notice that pandas upcast two of the columns to floats to accommodate the `NaN`s?)\n",
"\n",
"You cannot drop a single value from a `DataFrame`, so you have to drop full rows or columns. Depending on what you are doing, you might want to do one or the other, and so pandas gives you options for both. Because in data science, columns generally represent variables and rows represent observations, you are more likely to drop rows of data; the default setting for `dropna()` is to drop all rows that contain any null values:"
- ],
- "metadata": {}
+ ]
},
{
"cell_type": "code",
- "execution_count": 19,
+
+ "metadata": {
+ "trusted": false,
+ "id": "jAVU24RXgRsE",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 80
+ },
+ "outputId": "0b5e5aee-7187-4d3f-b583-a44136ae5f80"
+ },
"source": [
"example4.dropna()"
],
+ "execution_count": 23,
"outputs": [
{
"output_type": "execute_result",
@@ -836,26 +1373,36 @@
]
},
"metadata": {},
- "execution_count": 19
+
+ "execution_count": 23
}
- ],
- "metadata": {
- "trusted": false
- }
+ ]
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "TrQRBuTDgRsE"
+ },
"source": [
"If necessary, you can drop NA values from columns. Use `axis=1` to do so:"
- ],
- "metadata": {}
+ ]
},
{
"cell_type": "code",
- "execution_count": 20,
+
+ "metadata": {
+ "trusted": false,
+ "id": "GrBhxu9GgRsE",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 142
+ },
+ "outputId": "ff4001f3-2e61-4509-d60e-0093d1068437"
+ },
"source": [
"example4.dropna(axis='columns')"
],
+ "execution_count": 24,
"outputs": [
{
"output_type": "execute_result",
@@ -907,29 +1454,40 @@
]
},
"metadata": {},
- "execution_count": 20
+
+ "execution_count": 24
}
- ],
- "metadata": {
- "trusted": false
- }
+ ]
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "KWXiKTfMgRsF"
+ },
"source": [
"Notice that this can drop a lot of data that you might want to keep, particularly in smaller datasets. What if you just want to drop rows or columns that contain several or even just all null values? You specify those setting in `dropna` with the `how` and `thresh` parameters.\n",
"\n",
- "By default, `how='any'` (if you would like to check for yourself or see what other parameters the method has, run `example4.dropna?` in a code cell). You could alternatively specify `how='all'` so as to drop only rows or columns that contain all null values. Let's expand our example `DataFrame` to see this in action."
- ],
- "metadata": {}
+ "By default, `how='any'` (if you would like to check for yourself or see what other parameters the method has, run `example4.dropna?` in a code cell). You could alternatively specify `how='all'` so as to drop only rows or columns that contain all null values. Let's expand our example `DataFrame` to see this in action in the next exercise."
+ ]
},
{
"cell_type": "code",
- "execution_count": 21,
+
+ "metadata": {
+ "trusted": false,
+ "id": "Bcf_JWTsgRsF",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 142
+ },
+ "outputId": "72e0b1b8-52fa-4923-98ce-b6fbed6e44b1"
+ },
"source": [
"example4[3] = np.nan\n",
"example4"
],
+
+ "execution_count": 25,
"outputs": [
{
"output_type": "execute_result",
@@ -993,19 +1551,32 @@
]
},
"metadata": {},
- "execution_count": 21
+
+ "execution_count": 25
}
- ],
+ ]
+ },
+ {
+ "cell_type": "markdown",
"metadata": {
- "trusted": false
- }
+ "id": "pNZer7q9JPNC"
+ },
+ "source": [
+ "> Key takeaways: \n",
+ "1. Dropping null values is a good idea only if the dataset is large enough.\n",
+ "2. Full rows or columns can be dropped if they have most of their data missing.\n",
+ "3. The `DataFrame.dropna(axis=)` method helps in dropping null values. The `axis` argument signifies whether rows are to be dropped or columns. \n",
+ "4. The `how` argument can also be used. By default it is set to `any`. So, it drops only those rows/columns which contain any null values. It can be set to `all` to specify that we will drop only those rows/columns where all values are null."
+ ]
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "oXXSfQFHgRsF"
+ },
"source": [
"### Exercise:"
- ],
- "metadata": {}
+ ]
},
{
"cell_type": "code",
@@ -1017,22 +1588,41 @@
"outputs": [],
"metadata": {
"collapsed": true,
- "trusted": false
- }
+ "trusted": false,
+ "id": "ExUwQRxpgRsF"
+ },
+ "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"
+ ],
+ "execution_count": 26,
+ "outputs": []
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "38kwAihWgRsG"
+ },
"source": [
"The `thresh` parameter gives you finer-grained control: you set the number of *non-null* values that a row or column needs to have in order to be kept:"
- ],
- "metadata": {}
+ ]
},
{
"cell_type": "code",
- "execution_count": 23,
+
+ "metadata": {
+ "trusted": false,
+ "id": "M9dCNMaagRsG",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 80
+ },
+ "outputId": "8093713a-54d2-4e54-c73f-4eea315cb6f2"
+ },
"source": [
"example4.dropna(axis='rows', thresh=3)"
],
+ "execution_count": 27,
"outputs": [
{
"output_type": "execute_result",
@@ -1080,193 +1670,1476 @@
]
},
"metadata": {},
- "execution_count": 23
+
+ "execution_count": 27
}
- ],
- "metadata": {
- "trusted": false
- }
+ ]
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "fmSFnzZegRsG"
+ },
"source": [
"Here, the first and last row have been dropped, because they contain only two non-null values."
- ],
- "metadata": {}
+ ]
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "mCcxLGyUgRsG"
+ },
"source": [
"### Filling null values\n",
"\n",
- "Depending on your dataset, it can sometimes make more sense to fill null values with valid ones rather than drop them. You could use `isnull` to do this in place, but that can be laborious, particularly if you have a lot of values to fill. Because this is such a common task in data science, pandas provides `fillna`, which returns a copy of the `Series` or `DataFrame` with the missing values replaced with one of your choosing. Let's create another example `Series` to see how this works in practice."
- ],
- "metadata": {}
+ "It sometimes makes sense to fill in missing values with ones which could be valid. There are a few techniques to fill null values. The first is using Domain Knowledge(knowledge of the subject on which the dataset is based) to somehow approximate the missing values. \n",
+ "\n",
+ "\n",
+ "You could use `isnull` to do this in place, but that can be laborious, particularly if you have a lot of values to fill. Because this is such a common task in data science, pandas provides `fillna`, which returns a copy of the `Series` or `DataFrame` with the missing values replaced with one of your choosing. Let's create another example `Series` to see how this works in practice."
+ ]
},
{
- "cell_type": "code",
- "execution_count": 24,
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "CE8S7louLezV"
+ },
"source": [
- "example5 = pd.Series([1, np.nan, 2, None, 3], index=list('abcde'))\n",
- "example5"
+ "### Categorical Data(Non-numeric)\n",
+ "First let us consider non-numeric data. In datasets, we have columns with categorical data. Eg. Gender, True or False etc.\n",
+ "\n",
+ "In most of these cases, we replace missing values with the `mode` of the column. Say, we have 100 data points and 90 have said True, 8 have said False and 2 have not filled. Then, we can will the 2 with True, considering the full column. \n",
+ "\n",
+ "Again, here we can use domain knowledge here. Let us consider an example of filling with the mode."
+ ]
+ },
+ {
+ "cell_type": "code",
+
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 204
+ },
+ "id": "MY5faq4yLdpQ",
+ "outputId": "19ab472e-1eed-4de8-f8a7-db2a3af3cb1a"
+ },
+ "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"
],
+ "execution_count": 28,
"outputs": [
{
"output_type": "execute_result",
"data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " 0 | \n",
+ " 1 | \n",
+ " 2 | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 0 | \n",
+ " 1 | \n",
+ " 2 | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " 1 | \n",
+ " 3 | \n",
+ " 4 | \n",
+ " None | \n",
+ "
\n",
+ " \n",
+ " 2 | \n",
+ " 5 | \n",
+ " 6 | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " 3 | \n",
+ " 7 | \n",
+ " 8 | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " 4 | \n",
+ " 9 | \n",
+ " 10 | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
"text/plain": [
- "a 1.0\n",
- "b NaN\n",
- "c 2.0\n",
- "d NaN\n",
- "e 3.0\n",
- "dtype: float64"
+ " 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"
]
},
"metadata": {},
- "execution_count": 24
+ "execution_count": 28
}
- ],
- "metadata": {
- "trusted": false
- }
+ ]
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "MLAoMQOfNPlA"
+ },
"source": [
- "You can fill all of the null entries with a single value, such as `0`:"
- ],
- "metadata": {}
+ "Now, lets first find the mode before filling the `None` value with the mode."
+ ]
},
{
"cell_type": "code",
- "execution_count": 25,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "WKy-9Y2tN5jv",
+ "outputId": "8da9fa16-e08c-447e-dea1-d4b1db2feebf"
+ },
"source": [
- "example5.fillna(0)"
+ "fill_with_mode[2].value_counts()"
],
+ "execution_count": 29,
"outputs": [
{
"output_type": "execute_result",
"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"
+ "True 3\n",
+ "False 1\n",
+ "Name: 2, dtype: int64"
]
},
"metadata": {},
- "execution_count": 25
+ "execution_count": 29
}
- ],
- "metadata": {
- "trusted": false
- }
+ ]
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "6iNz_zG_OKrx"
+ },
"source": [
- "### Exercise:"
+ "So, we will replace None with True"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "metadata": {
+ "id": "TxPKteRvNPOs"
+ },
+ "source": [
+ "fill_with_mode[2].fillna('True',inplace=True)"
],
- "metadata": {}
+ "execution_count": 30,
+ "outputs": []
},
{
"cell_type": "code",
- "execution_count": 26,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 204
+ },
+ "id": "tvas7c9_OPWE",
+ "outputId": "ec3c8e44-d644-475e-9e22-c65101965850"
+ },
"source": [
- "# What happens if you try to fill null values with a string, like ''?\n"
+ "fill_with_mode"
],
- "outputs": [],
+ "execution_count": 31,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " 0 | \n",
+ " 1 | \n",
+ " 2 | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 0 | \n",
+ " 1 | \n",
+ " 2 | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " 1 | \n",
+ " 3 | \n",
+ " 4 | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " 2 | \n",
+ " 5 | \n",
+ " 6 | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " 3 | \n",
+ " 7 | \n",
+ " 8 | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " 4 | \n",
+ " 9 | \n",
+ " 10 | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ "
\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"
+ ]
+ },
+ "metadata": {},
+ "execution_count": 31
+ }
+ ]
+ },
+ {
+ "cell_type": "markdown",
"metadata": {
- "collapsed": true,
- "trusted": false
- }
+ "id": "SktitLxxOR16"
+ },
+ "source": [
+ "As we can see, the null value has been replaced. Needless to say, we could have written anything in place or `'True'` and it would have got substituted."
+ ]
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "heYe1I0dOmQ_"
+ },
"source": [
- "You can **forward-fill** null values, which is to use the last valid value to fill a null:"
+ "### Numeric Data\n",
+ "Now, coming to numeric data. Here, we have a two common ways of replacing missing values:\n",
+ "\n",
+ "1. Replace with Median of the row\n",
+ "2. Replace with Mean of the row \n",
+ "\n",
+ "We replace with Median, in case of skewed data with outliers. This is beacuse median is robust to outliers.\n",
+ "\n",
+ "When the data is normalized, we can use mean, as in that case, mean and median would be pretty close.\n",
+ "\n",
+ "First, let us take a column which is normally distributed and let us fill the missing value with the mean of the column. "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 204
+ },
+ "id": "09HM_2feOj5Y",
+ "outputId": "7e309013-9acb-411c-9b06-4de795bbeeff"
+ },
+ "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"
],
- "metadata": {}
+ "execution_count": 32,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " 0 | \n",
+ " 1 | \n",
+ " 2 | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 0 | \n",
+ " -2.0 | \n",
+ " 0 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 1 | \n",
+ " -1.0 | \n",
+ " 2 | \n",
+ " 3 | \n",
+ "
\n",
+ " \n",
+ " 2 | \n",
+ " NaN | \n",
+ " 4 | \n",
+ " 5 | \n",
+ "
\n",
+ " \n",
+ " 3 | \n",
+ " 1.0 | \n",
+ " 6 | \n",
+ " 7 | \n",
+ "
\n",
+ " \n",
+ " 4 | \n",
+ " 2.0 | \n",
+ " 8 | \n",
+ " 9 | \n",
+ "
\n",
+ " \n",
+ "
\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"
+ ]
+ },
+ "metadata": {},
+ "execution_count": 32
+ }
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "ka7-wNfzSxbx"
+ },
+ "source": [
+ "The mean of the column is"
+ ]
},
{
"cell_type": "code",
- "execution_count": 27,
+ "metadata": {
+ "id": "XYtYEf5BSxFL",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "outputId": "68a78d18-f0e5-4a9a-a959-2c3676a57c70"
+ },
"source": [
- "example5.fillna(method='ffill')"
+ "np.mean(fill_with_mean[0])"
],
+ "execution_count": 33,
"outputs": [
{
"output_type": "execute_result",
"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"
+ "0.0"
]
},
"metadata": {},
- "execution_count": 27
+ "execution_count": 33
}
- ],
- "metadata": {
- "trusted": false
- }
+ ]
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "oBSRGxKRS39K"
+ },
"source": [
- "You can also **back-fill** to propagate the next valid value backward to fill a null:"
- ],
- "metadata": {}
+ "Filling with mean"
+ ]
},
{
"cell_type": "code",
- "execution_count": 28,
+ "metadata": {
+ "id": "FzncQLmuS5jh",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 204
+ },
+ "outputId": "00f74fff-01f4-4024-c261-796f50f01d2e"
+ },
"source": [
- "example5.fillna(method='bfill')"
+ "fill_with_mean[0].fillna(np.mean(fill_with_mean[0]),inplace=True)\n",
+ "fill_with_mean"
],
+ "execution_count": 34,
"outputs": [
{
"output_type": "execute_result",
"data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " 0 | \n",
+ " 1 | \n",
+ " 2 | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 0 | \n",
+ " -2.0 | \n",
+ " 0 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 1 | \n",
+ " -1.0 | \n",
+ " 2 | \n",
+ " 3 | \n",
+ "
\n",
+ " \n",
+ " 2 | \n",
+ " 0.0 | \n",
+ " 4 | \n",
+ " 5 | \n",
+ "
\n",
+ " \n",
+ " 3 | \n",
+ " 1.0 | \n",
+ " 6 | \n",
+ " 7 | \n",
+ "
\n",
+ " \n",
+ " 4 | \n",
+ " 2.0 | \n",
+ " 8 | \n",
+ " 9 | \n",
+ "
\n",
+ " \n",
+ "
\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"
+ ]
+ },
+ "metadata": {},
+ "execution_count": 34
+ }
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "CwpVFCrPTC5z"
+ },
+ "source": [
+ "As we can see, the missing value has been replaced with its mean."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "jIvF13a1i00Z"
+ },
+ "source": [
+ "Now let us try another dataframe, and this time we will replace the None values with the median of the column."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "metadata": {
+ "id": "DA59Bqo3jBYZ",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 204
+ },
+ "outputId": "85dae6ec-7394-4c36-fda0-e04769ec4a32"
+ },
+ "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"
+ ],
+ "execution_count": 35,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " 0 | \n",
+ " 1 | \n",
+ " 2 | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 0 | \n",
+ " -2 | \n",
+ " 0.0 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 1 | \n",
+ " -1 | \n",
+ " 2.0 | \n",
+ " 3 | \n",
+ "
\n",
+ " \n",
+ " 2 | \n",
+ " 0 | \n",
+ " NaN | \n",
+ " 5 | \n",
+ "
\n",
+ " \n",
+ " 3 | \n",
+ " 1 | \n",
+ " 6.0 | \n",
+ " 7 | \n",
+ "
\n",
+ " \n",
+ " 4 | \n",
+ " 2 | \n",
+ " 8.0 | \n",
+ " 9 | \n",
+ "
\n",
+ " \n",
+ "
\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"
+ ]
+ },
+ "metadata": {},
+ "execution_count": 35
+ }
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "mM1GpXYmjHnc"
+ },
+ "source": [
+ "The median of the second column is"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "metadata": {
+ "id": "uiDy5v3xjHHX",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "outputId": "564b6b74-2004-4486-90d4-b39330a64b88"
+ },
+ "source": [
+ "fill_with_median[1].median()"
+ ],
+ "execution_count": 36,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ "4.0"
+ ]
+ },
+ "metadata": {},
+ "execution_count": 36
+ }
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "z9PLF75Jj_1s"
+ },
+ "source": [
+ "Filling with median"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "metadata": {
+ "id": "lFKbOxCMkBbg",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 204
+ },
+ "outputId": "a8bd18fb-2765-47d4-e5fe-e965f57ed1f4"
+ },
+ "source": [
+ "fill_with_median[1].fillna(fill_with_median[1].median(),inplace=True)\n",
+ "fill_with_median"
+ ],
+ "execution_count": 37,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " 0 | \n",
+ " 1 | \n",
+ " 2 | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 0 | \n",
+ " -2 | \n",
+ " 0.0 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 1 | \n",
+ " -1 | \n",
+ " 2.0 | \n",
+ " 3 | \n",
+ "
\n",
+ " \n",
+ " 2 | \n",
+ " 0 | \n",
+ " 4.0 | \n",
+ " 5 | \n",
+ "
\n",
+ " \n",
+ " 3 | \n",
+ " 1 | \n",
+ " 6.0 | \n",
+ " 7 | \n",
+ "
\n",
+ " \n",
+ " 4 | \n",
+ " 2 | \n",
+ " 8.0 | \n",
+ " 9 | \n",
+ "
\n",
+ " \n",
+ "
\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"
+ ]
+ },
+ "metadata": {},
+ "execution_count": 37
+ }
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "8JtQ53GSkKWC"
+ },
+ "source": [
+ "As we can see, the NaN value has been replaced by the median of the column"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "metadata": {
+ "trusted": false,
+ "id": "0ybtWLDdgRsG",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "outputId": "b8c238ef-6024-4ee2-be2b-aa1f0fcac61d"
+ },
+ "source": [
+ "example5 = pd.Series([1, np.nan, 2, None, 3], index=list('abcde'))\n",
+ "example5"
+ ],
+ "execution_count": 38,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ "a 1.0\n",
+ "b NaN\n",
+ "c 2.0\n",
+ "d NaN\n",
+ "e 3.0\n",
+ "dtype: float64"
+ ]
+ },
+ "metadata": {},
+ "execution_count": 38
+ }
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "yrsigxRggRsH"
+ },
+ "source": [
+ "You can fill all of the null entries with a single value, such as `0`:"
+ ]
+ },
+ {
+ "cell_type": "code",
+
+ "metadata": {
+ "trusted": false,
+ "id": "KXMIPsQdgRsH",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "outputId": "aeedfa0a-a421-4c2f-cb0d-183ce8f0c91d"
+ },
+ "source": [
+ "example5.fillna(0)"
+ ],
+ "execution_count": 39,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "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"
+ ]
+ },
+ "metadata": {},
+
+ "execution_count": 39
+ }
+ ]
+ },
+ {
+ "cell_type": "markdown",
+
+ "metadata": {
+ "id": "RRlI5f_hkfKe"
+ },
+ "source": [
+ "> Key takeaways:\n",
+ "1. Filling in missing values should be done when either there is less data or there is a strategy to fill in the missing data.\n",
+ "2. Domain knowledge can be used to fill in missing values by approximating them.\n",
+ "3. For Categorical data, mostly, missing values are substituted with the mode of the column. \n",
+ "4. For numeric data, missing values are usually filled in with the mean(for normalized datasets) or the median of the columns. "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "FI9MmqFJgRsH"
+ },
+ "source": [
+ "### Exercise:"
+ ]
+ },
+ {
+ "cell_type": "code",
+
+ "metadata": {
+ "collapsed": true,
+ "trusted": false,
+ "id": "af-ezpXdgRsH"
+ },
+ "source": [
+ "# What happens if you try to fill null values with a string, like ''?\n"
+ ],
+ "execution_count": 40,
+ "outputs": []
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "kq3hw1kLgRsI"
+ },
+ "source": [
+ "You can **forward-fill** null values, which is to use the last valid value to fill a null:"
+ ]
+ },
+ {
+ "cell_type": "code",
+
+ "metadata": {
+ "trusted": false,
+ "id": "vO3BuNrggRsI",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "outputId": "e2bc591b-0b48-4e88-ee65-754f2737c196"
+ },
+ "source": [
+ "example5.fillna(method='ffill')"
+ ],
+ "execution_count": 41,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "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"
+ ]
+ },
+ "metadata": {},
+
+ "execution_count": 41
+ }
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "nDXeYuHzgRsI"
+ },
+ "source": [
+ "You can also **back-fill** to propagate the next valid value backward to fill a null:"
+ ]
+ },
+ {
+ "cell_type": "code",
+
+ "metadata": {
+ "trusted": false,
+ "id": "4M5onHcEgRsI",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "outputId": "8f32b185-40dd-4a9f-bd85-54d6b6a414fe"
+ },
+ "source": [
+ "example5.fillna(method='bfill')"
+ ],
+ "execution_count": 42,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "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"
+ ]
+ },
+ "metadata": {},
+
+ "execution_count": 42
+ }
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "collapsed": true,
+ "id": "MbBzTom5gRsI"
+ },
+ "source": [
+ "As you might guess, this works the same with DataFrames, but you can also specify an `axis` along which to fill null values:"
+ ]
+ },
+ {
+ "cell_type": "code",
+
+ "metadata": {
+ "trusted": false,
+ "id": "aRpIvo4ZgRsI",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 142
+ },
+ "outputId": "905a980a-a808-4eca-d0ba-224bd7d85955"
+ },
+ "source": [
+ "example4"
+ ],
+ "execution_count": 43,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " 0 | \n",
+ " 1 | \n",
+ " 2 | \n",
+ " 3 | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 0 | \n",
+ " 1.0 | \n",
+ " NaN | \n",
+ " 7 | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ " 1 | \n",
+ " 2.0 | \n",
+ " 5.0 | \n",
+ " 8 | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ " 2 | \n",
+ " NaN | \n",
+ " 6.0 | \n",
+ " 9 | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ "
\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"
+ ]
+ },
+ "metadata": {},
+
+ "execution_count": 43
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "metadata": {
+ "trusted": false,
+ "id": "VM1qtACAgRsI",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 142
+ },
+ "outputId": "71f2ad28-9b4e-4ff4-f5c3-e731eb489ade"
+ },
+ "source": [
+ "example4.fillna(method='ffill', axis=1)"
+ ],
+ "execution_count": 44,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " 0 | \n",
+ " 1 | \n",
+ " 2 | \n",
+ " 3 | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 0 | \n",
+ " 1.0 | \n",
+ " 1.0 | \n",
+ " 7.0 | \n",
+ " 7.0 | \n",
+ "
\n",
+ " \n",
+ " 1 | \n",
+ " 2.0 | \n",
+ " 5.0 | \n",
+ " 8.0 | \n",
+ " 8.0 | \n",
+ "
\n",
+ " \n",
+ " 2 | \n",
+ " NaN | \n",
+ " 6.0 | \n",
+ " 9.0 | \n",
+ " 9.0 | \n",
+ "
\n",
+ " \n",
+ "
\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"
+ ]
+ },
+ "metadata": {},
+ "execution_count": 44
+ }
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "ZeMc-I1EgRsI"
+ },
+ "source": [
+ "Notice that when a previous value is not available for forward-filling, the null value remains."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "eeAoOU0RgRsJ"
+ },
+ "source": [
+ "### Exercise:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "metadata": {
+ "collapsed": true,
+ "trusted": false,
+ "id": "e8S-CjW8gRsJ"
+ },
+ "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"
+ ],
+ "execution_count": 45,
+ "outputs": []
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "YHgy0lIrgRsJ"
+ },
+ "source": [
+ "You can be creative about how you use `fillna`. For example, let's look at `example4` again, but this time let's fill the missing values with the average of all of the values in the `DataFrame`:"
+ ]
+ },
+ {
+ "cell_type": "code",
+
+ "metadata": {
+ "trusted": false,
+ "id": "OtYVErEygRsJ",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 142
+ },
+ "outputId": "708b1e67-45ca-44bf-a5ee-8b2de09ece73"
+ },
+ "source": [
+ "example4.fillna(example4.mean())"
+ ],
+ "execution_count": 46,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " 0 | \n",
+ " 1 | \n",
+ " 2 | \n",
+ " 3 | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 0 | \n",
+ " 1.0 | \n",
+ " 5.5 | \n",
+ " 7 | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ " 1 | \n",
+ " 2.0 | \n",
+ " 5.0 | \n",
+ " 8 | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ " 2 | \n",
+ " 1.5 | \n",
+ " 6.0 | \n",
+ " 9 | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ "
\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"
+ ]
+ },
+ "metadata": {},
+
+ "execution_count": 46
+ }
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "zpMvCkLSgRsJ"
+ },
+ "source": [
+ "Notice that column 3 is still valueless: the default direction is to fill values row-wise.\n",
+ "\n",
+ "> **Takeaway:** There are multiple ways to deal with missing values in your datasets. The specific strategy you use (removing them, replacing them, or even how you replace them) should be dictated by the particulars of that data. You will develop a better sense of how to deal with missing values the more you handle and interact with datasets."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "bauDnESIl9FH"
+ },
+ "source": [
+ "### Encoding Categorical Data\n",
+ "\n",
+ "Machine learning models only deal with numbers and any form of numeric data. It won't be able to tell the difference between a Yes and a No, but it would be able to distinguish between 0 and 1. So, after filling in the missing values, we need to do encode the categorical data to some numeric form for the model to understand.\n",
+ "\n",
+ "Encoding can be done in two ways. We will be discussing them next.\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "uDq9SxB7mu5i"
+ },
+ "source": [
+ "**LABEL ENCODING**\n",
+ "\n",
+ "\n",
+ "Label encoding is basically converting each category to a number. For example, say we have a dataset of airline passengers and there is a column containing their class among the following ['business class', 'economy class','first class']. If Label encoding is done on this, this would be transformed to [0,1,2]. Let us see an example via code. As we would be learning `scikit-learn` in the upcoming notebooks, we won't use it here."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "metadata": {
+ "id": "1vGz7uZyoWHL",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 235
+ },
+ "outputId": "9e252855-d193-4103-a54d-028ea7787b34"
+ },
+ "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"
+ ],
+ "execution_count": 47,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " ID | \n",
+ " class | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 0 | \n",
+ " 10 | \n",
+ " business class | \n",
+ "
\n",
+ " \n",
+ " 1 | \n",
+ " 20 | \n",
+ " first class | \n",
+ "
\n",
+ " \n",
+ " 2 | \n",
+ " 30 | \n",
+ " economy class | \n",
+ "
\n",
+ " \n",
+ " 3 | \n",
+ " 40 | \n",
+ " economy class | \n",
+ "
\n",
+ " \n",
+ " 4 | \n",
+ " 50 | \n",
+ " economy class | \n",
+ "
\n",
+ " \n",
+ " 5 | \n",
+ " 60 | \n",
+ " business class | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
"text/plain": [
- "a 1.0\n",
- "b 2.0\n",
- "c 2.0\n",
- "d 3.0\n",
- "e 3.0\n",
- "dtype: float64"
+ " 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"
]
},
"metadata": {},
- "execution_count": 28
+ "execution_count": 47
}
- ],
- "metadata": {
- "trusted": false
- }
+ ]
},
{
"cell_type": "markdown",
- "source": [
- "As you might guess, this works the same with `DataFrame`s, but you can also specify an `axis` along which to fill null values:"
- ],
"metadata": {
- "collapsed": true
- }
+ "id": "IDHnkwTYov-h"
+ },
+ "source": [
+ "To perform label encoding on the 1st column, we have to first describe a mapping from each class to a number, before replacing"
+ ]
},
{
"cell_type": "code",
- "execution_count": 29,
- "source": [
- "example4"
- ],
+ "metadata": {
+ "id": "ZC5URJG3o1ES",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 235
+ },
+ "outputId": "aab0f1e7-e0f3-4c14-8459-9f9168c85437"
+ },
+ "source": [
+ "class_labels = {'business class':0,'economy class':1,'first class':2}\n",
+ "label['class'] = label['class'].replace(class_labels)\n",
+ "label"
+ ],
+ "execution_count": 48,
"outputs": [
{
"output_type": "execute_result",
@@ -1290,59 +3163,106 @@
" \n",
" \n",
" | \n",
- " 0 | \n",
- " 1 | \n",
- " 2 | \n",
- " 3 | \n",
+ " ID | \n",
+ " class | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
- " 1.0 | \n",
- " NaN | \n",
- " 7 | \n",
- " NaN | \n",
+ " 10 | \n",
+ " 0 | \n",
"
\n",
" \n",
" 1 | \n",
- " 2.0 | \n",
- " 5.0 | \n",
- " 8 | \n",
- " NaN | \n",
+ " 20 | \n",
+ " 2 | \n",
"
\n",
" \n",
" 2 | \n",
- " NaN | \n",
- " 6.0 | \n",
- " 9 | \n",
- " NaN | \n",
+ " 30 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 3 | \n",
+ " 40 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 4 | \n",
+ " 50 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 5 | \n",
+ " 60 | \n",
+ " 0 | \n",
"
\n",
" \n",
"\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"
+ " 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"
]
},
"metadata": {},
- "execution_count": 29
+ "execution_count": 48
}
- ],
+ ]
+ },
+ {
+ "cell_type": "markdown",
"metadata": {
- "trusted": false
- }
+ "id": "ftnF-TyapOPt"
+ },
+ "source": [
+ "As we can see, the output matches what we thought would happen. So, when do we use label encoding? Label encoding is used in either or both of the following cases :\n",
+ "1. When the number of categories is large\n",
+ "2. When the categories are in order. "
+ ]
},
{
- "cell_type": "code",
- "execution_count": 30,
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "eQPAPVwsqWT7"
+ },
"source": [
- "example4.fillna(method='ffill', axis=1)"
- ],
+ "**ONE HOT ENCODING**\n",
+ "\n",
+ "Another type of encoding is One Hot Encoding. In this type of encoding, each category of the column gets added as a separate column and each datapoint will get a 0 or a 1 based on whether it contains that category. So, if there are n different categories, n columns will be appended to the dataframe.\n",
+ "\n",
+ "For example, let us take the same aeroplane class example. The categories were: ['business class', 'economy class','first class'] . So, if we perform one hot encoding, the following three columns will be added to the dataset: ['class_business class','class_economy class','class_first class']."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "metadata": {
+ "id": "ZM0eVh0ArKUL",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 235
+ },
+ "outputId": "83238a76-b3a5-418d-c0b6-605b02b6891b"
+ },
+ "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"
+ ],
+ "execution_count": 49,
"outputs": [
{
"output_type": "execute_result",
@@ -1366,94 +3286,94 @@
" \n",
" \n",
" | \n",
- " 0 | \n",
- " 1 | \n",
- " 2 | \n",
- " 3 | \n",
+ " ID | \n",
+ " class | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
- " 1.0 | \n",
- " 1.0 | \n",
- " 7.0 | \n",
- " 7.0 | \n",
+ " 10 | \n",
+ " business class | \n",
"
\n",
" \n",
" 1 | \n",
- " 2.0 | \n",
- " 5.0 | \n",
- " 8.0 | \n",
- " 8.0 | \n",
+ " 20 | \n",
+ " first class | \n",
"
\n",
" \n",
" 2 | \n",
- " NaN | \n",
- " 6.0 | \n",
- " 9.0 | \n",
- " 9.0 | \n",
+ " 30 | \n",
+ " economy class | \n",
+ "
\n",
+ " \n",
+ " 3 | \n",
+ " 40 | \n",
+ " economy class | \n",
+ "
\n",
+ " \n",
+ " 4 | \n",
+ " 50 | \n",
+ " economy class | \n",
+ "
\n",
+ " \n",
+ " 5 | \n",
+ " 60 | \n",
+ " business class | \n",
"
\n",
" \n",
"\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"
+ " 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"
]
},
"metadata": {},
- "execution_count": 30
+ "execution_count": 49
}
- ],
- "metadata": {
- "trusted": false
- }
- },
- {
- "cell_type": "markdown",
- "source": [
- "Notice that when a previous value is not available for forward-filling, the null value remains."
- ],
- "metadata": {}
+ ]
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "aVnZ7paDrWmb"
+ },
"source": [
- "### Exercise:"
- ],
- "metadata": {}
+ "Let us perform one hot encoding on the 1st column"
+ ]
},
{
"cell_type": "code",
- "execution_count": 31,
- "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"
- ],
- "outputs": [],
"metadata": {
- "collapsed": true,
- "trusted": false
- }
- },
- {
- "cell_type": "markdown",
+ "id": "RUPxf7egrYKr"
+ },
"source": [
- "You can be creative about how you use `fillna`. For example, let's look at `example4` again, but this time let's fill the missing values with the average of all of the values in the `DataFrame`:"
+ "one_hot_data = pd.get_dummies(one_hot,columns=['class'])"
],
- "metadata": {}
+ "execution_count": 50,
+ "outputs": []
},
{
"cell_type": "code",
- "execution_count": 32,
+ "metadata": {
+ "id": "TM37pHsFr4ge",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 235
+ },
+ "outputId": "7be15f53-79b2-447a-979c-822658339a9e"
+ },
"source": [
- "example4.fillna(example4.mean())"
+ "one_hot_data"
],
+ "execution_count": 51,
"outputs": [
{
"output_type": "execute_result",
@@ -1477,90 +3397,148 @@
" \n",
" \n",
" | \n",
- " 0 | \n",
- " 1 | \n",
- " 2 | \n",
- " 3 | \n",
+ " ID | \n",
+ " class_business class | \n",
+ " class_economy class | \n",
+ " class_first class | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
- " 1.0 | \n",
- " 5.5 | \n",
- " 7 | \n",
- " NaN | \n",
+ " 10 | \n",
+ " 1 | \n",
+ " 0 | \n",
+ " 0 | \n",
"
\n",
" \n",
" 1 | \n",
- " 2.0 | \n",
- " 5.0 | \n",
- " 8 | \n",
- " NaN | \n",
+ " 20 | \n",
+ " 0 | \n",
+ " 0 | \n",
+ " 1 | \n",
"
\n",
" \n",
" 2 | \n",
- " 1.5 | \n",
- " 6.0 | \n",
- " 9 | \n",
- " NaN | \n",
+ " 30 | \n",
+ " 0 | \n",
+ " 1 | \n",
+ " 0 | \n",
+ "
\n",
+ " \n",
+ " 3 | \n",
+ " 40 | \n",
+ " 0 | \n",
+ " 1 | \n",
+ " 0 | \n",
+ "
\n",
+ " \n",
+ " 4 | \n",
+ " 50 | \n",
+ " 0 | \n",
+ " 1 | \n",
+ " 0 | \n",
+ "
\n",
+ " \n",
+ " 5 | \n",
+ " 60 | \n",
+ " 1 | \n",
+ " 0 | \n",
+ " 0 | \n",
"
\n",
" \n",
"\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"
+ " 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"
]
},
"metadata": {},
- "execution_count": 32
+ "execution_count": 51
}
- ],
+ ]
+ },
+ {
+ "cell_type": "markdown",
"metadata": {
- "trusted": false
- }
+ "id": "_zXRLOjXujdA"
+ },
+ "source": [
+ "Each one hot encoded column contains 0 or 1, which specifies whether that category exists for that datapoint."
+ ]
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "bDnC4NQOu0qr"
+ },
"source": [
- "Notice that column 3 is still valueless: the default direction is to fill values row-wise.\n",
+ "When do we use one hot encoding? One hot encoding is used in either or both of the following cases :\n",
"\n",
- "> **Takeaway:** There are multiple ways to deal with missing values in your datasets. The specific strategy you use (removing them, replacing them, or even how you replace them) should be dictated by the particulars of that data. You will develop a better sense of how to deal with missing values the more you handle and interact with datasets."
- ],
- "metadata": {}
+ "1. When the number of categories and the size of the dataset is smaller.\n",
+ "2. When the categories follow no particular order."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "XnUmci_4uvyu"
+ },
+ "source": [
+ "> Key Takeaways:\n",
+ "1. Encoding is done to convert non-numeric data to numeric data.\n",
+ "2. There are two types of encoding: Label encoding and One Hot encoding, both of which can be performed based on the demands of the dataset. "
+ ]
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "K8UXOJYRgRsJ"
+ },
"source": [
"## Removing duplicate data\n",
"\n",
"> **Learning goal:** By the end of this subsection, you should be comfortable identifying and removing duplicate values from DataFrames.\n",
"\n",
"In addition to missing data, you will often encounter duplicated data in real-world datasets. Fortunately, pandas provides an easy means of detecting and removing duplicate entries."
- ],
- "metadata": {}
+ ]
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "qrEG-Wa0gRsJ"
+ },
"source": [
"### Identifying duplicates: `duplicated`\n",
"\n",
"You can easily spot duplicate values using the `duplicated` method in pandas, which returns a Boolean mask indicating whether an entry in a `DataFrame` is a duplicate of an ealier one. Let's create another example `DataFrame` to see this in action."
- ],
- "metadata": {}
+ ]
},
{
"cell_type": "code",
- "execution_count": 33,
+
+ "metadata": {
+ "trusted": false,
+ "id": "ZLu6FEnZgRsJ",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 204
+ },
+ "outputId": "376512d1-d842-4db1-aea3-71052aeeecaf"
+ },
"source": [
"example6 = pd.DataFrame({'letters': ['A','B'] * 2 + ['B'],\n",
" 'numbers': [1, 2, 1, 3, 3]})\n",
"example6"
],
+ "execution_count": 52,
"outputs": [
{
"output_type": "execute_result",
@@ -1628,19 +3606,25 @@
]
},
"metadata": {},
- "execution_count": 33
+
+ "execution_count": 52
}
- ],
- "metadata": {
- "trusted": false
- }
+ ]
},
{
"cell_type": "code",
- "execution_count": 34,
+ "metadata": {
+ "trusted": false,
+ "id": "cIduB5oBgRsK",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "outputId": "3da27b3d-4d69-4e1d-bb52-0af21bae87f2"
+ },
"source": [
"example6.duplicated()"
],
+ "execution_count": 53,
"outputs": [
{
"output_type": "execute_result",
@@ -1655,27 +3639,36 @@
]
},
"metadata": {},
- "execution_count": 34
+ "execution_count": 53
}
- ],
- "metadata": {
- "trusted": false
- }
+ ]
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "0eDRJD4SgRsK"
+ },
"source": [
"### Dropping duplicates: `drop_duplicates`\n",
"`drop_duplicates` simply returns a copy of the data for which all of the `duplicated` values are `False`:"
- ],
- "metadata": {}
+ ]
},
{
"cell_type": "code",
- "execution_count": 35,
+
+ "metadata": {
+ "trusted": false,
+ "id": "w_YPpqIqgRsK",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 142
+ },
+ "outputId": "ac66bd2f-8671-4744-87f5-8b8d96553dea"
+ },
"source": [
"example6.drop_duplicates()"
],
+ "execution_count": 54,
"outputs": [
{
"output_type": "execute_result",
@@ -1731,26 +3724,35 @@
]
},
"metadata": {},
- "execution_count": 35
+
+ "execution_count": 54
}
- ],
- "metadata": {
- "trusted": false
- }
+ ]
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "69AqoCZAgRsK"
+ },
"source": [
"Both `duplicated` and `drop_duplicates` default to consider all columnsm but you can specify that they examine only a subset of columns in your `DataFrame`:"
- ],
- "metadata": {}
+ ]
},
{
"cell_type": "code",
- "execution_count": 36,
+ "metadata": {
+ "trusted": false,
+ "id": "BILjDs67gRsK",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 111
+ },
+ "outputId": "ef6dcc08-db8b-4352-c44e-5aa9e2bec0d3"
+ },
"source": [
"example6.drop_duplicates(['letters'])"
],
+ "execution_count": 55,
"outputs": [
{
"output_type": "execute_result",
@@ -1800,43 +3802,20 @@
]
},
"metadata": {},
- "execution_count": 36
+
+ "execution_count": 55
}
- ],
- "metadata": {
- "trusted": false
- }
+ ]
},
{
"cell_type": "markdown",
+ "metadata": {
+ "id": "GvX4og1EgRsL"
+ },
"source": [
"> **Takeaway:** Removing duplicate data is an essential part of almost every data-science project. Duplicate data can change the results of your analyses and give you inaccurate results!"
- ],
- "metadata": {}
- }
- ],
- "metadata": {
- "anaconda-cloud": {},
- "kernelspec": {
- "name": "python3",
- "display_name": "Python 3.8.8 64-bit ('base': conda)"
- },
- "language_info": {
- "mimetype": "text/x-python",
- "nbconvert_exporter": "python",
- "name": "python",
- "file_extension": ".py",
- "version": "3.8.8",
- "pygments_lexer": "ipython3",
- "codemirror_mode": {
- "version": 3,
- "name": "ipython"
- }
- },
- "interpreter": {
- "hash": "ac36fb7022a775f2750f61e1a6104d2d5a9eb3fb9bd004b80f1c771537b93945"
+ ]
}
- },
- "nbformat": 4,
- "nbformat_minor": 1
+
+ ]
}
\ No newline at end of file
diff --git a/4-Data-Science-Lifecycle/translations/README.hi.md b/4-Data-Science-Lifecycle/translations/README.hi.md
new file mode 100644
index 0000000..a5e2f6b
--- /dev/null
+++ b/4-Data-Science-Lifecycle/translations/README.hi.md
@@ -0,0 +1,13 @@
+# डेटा विज्ञान के जीवनचक्र
+![संचार](../images/communication.jpg)
+>तस्वीर Headway द्वारा Unsplash पर
+
+इन पाठों में, आप डेटा विज्ञान जीवनचक्र के कुछ पहलुओं का पता लगाएंगे, जिसमें डेटा के आसपास विश्लेषण और संचार शामिल है।
+
+### विषय
+1. [परिचय](../14-Introduction/README.md)
+2. [विश्लेषण](../15-analyzing/README.md)
+3. [संचार](../16-communication/README.md)
+
+### क्रेडिट
+ये पाठ [जालेन मैक्गी](https://twitter.com/JalenMCG) और [जैस्मीन ग्रीनवे](https://twitter.com/paladique) द्वारा ❤️ से लिखे गए हैं।
diff --git a/README.md b/README.md
index 7b2a9e8..79225b3 100644
--- a/README.md
+++ b/README.md
@@ -14,7 +14,7 @@ Azure Cloud Advocates at Microsoft are pleased to offer a 10-week, 20-lesson cur
**Hearty thanks to our authors:** [Jasmine Greenaway](https://www.twitter.com/paladique), [Dmitry Soshnikov](http://soshnikov.com), [Nitya Narasimhan](https://twitter.com/nitya), [Jalen McGee](https://twitter.com/JalenMcG), [Jen Looper](https://twitter.com/jenlooper), [Maud Levy](https://twitter.com/maudstweets), [Tiffany Souterre](https://twitter.com/TiffanySouterre), [Christopher Harrison](https://www.twitter.com/geektrainer).
-**🙏 Special thanks 🙏 to our Microsoft Student Ambassador authors, reviewers and content contributors,** notably [Raymond Wangsa Putra](https://www.linkedin.com/in/raymond-wp/), [Ankita Singh](https://www.linkedin.com/in/ankitasingh007), [Rohit Yadav](https://www.linkedin.com/in/rty2423), [Arpita Das](https://www.linkedin.com/in/arpitadas01/), [Mohamma Iftekher (Iftu) Ebne Jalal](https://twitter.com/iftu119), [Dishita Bhasin](https://www.linkedin.com/in/dishita-bhasin-7065281bb), [Miguel Correa](https://www.linkedin.com/in/miguelmque/), [Nawrin Tabassum](https://www.linkedin.com/in/nawrin-tabassum), [Sanya Sinha](https://www.linkedin.com/mwlite/in/sanya-sinha-13aab1200), [Majd Safi](https://www.linkedin.com/in/majd-s/), [Sheena Narula](https://www.linkedin.com/in/sheena-narula-n/), [Anupam Mishra](https://www.linkedin.com/in/anupam--mishra/), [Dibri Nsofor](https://www.linkedin.com/in/dibrinsofor), [Aditya Garg](https://github.com/AdityaGarg00), [Alondra Sanchez](https://www.linkedin.com/in/alondra-sanchez-molina/), Yogendrasingh Pawar, Max Blum, Samridhi Sharma, Tauqeer Ahmad, Aaryan Arora, ChhailBihari Dubey
+**🙏 Special thanks 🙏 to our [Microsoft Student Ambassador](https://studentambassadors.microsoft.com/) authors, reviewers and content contributors,** notably [Raymond Wangsa Putra](https://www.linkedin.com/in/raymond-wp/), [Ankita Singh](https://www.linkedin.com/in/ankitasingh007), [Rohit Yadav](https://www.linkedin.com/in/rty2423), [Arpita Das](https://www.linkedin.com/in/arpitadas01/), [Mohamma Iftekher (Iftu) Ebne Jalal](https://twitter.com/iftu119), [Dishita Bhasin](https://www.linkedin.com/in/dishita-bhasin-7065281bb), [Miguel Correa](https://www.linkedin.com/in/miguelmque/), [Nawrin Tabassum](https://www.linkedin.com/in/nawrin-tabassum), [Sanya Sinha](https://www.linkedin.com/mwlite/in/sanya-sinha-13aab1200), [Majd Safi](https://www.linkedin.com/in/majd-s/), [Sheena Narula](https://www.linkedin.com/in/sheena-narula-n/), [Anupam Mishra](https://www.linkedin.com/in/anupam--mishra/), [Dibri Nsofor](https://www.linkedin.com/in/dibrinsofor), [Aditya Garg](https://github.com/AdityaGarg00), [Alondra Sanchez](https://www.linkedin.com/in/alondra-sanchez-molina/), [Max Blum](https://www.linkedin.com/in/max-blum-6036a1186/), Yogendrasingh Pawar, Samridhi Sharma, Tauqeer Ahmad, Aaryan Arora, ChhailBihari Dubey
|![ Sketchnote by [(@sketchthedocs)](https://sketchthedocs.dev) ](./sketchnotes/00-Title.png)|
|:---:|
@@ -64,7 +64,7 @@ In addition, a low-stakes quiz before a class sets the intention of the student
| Lesson Number | Topic | Lesson Grouping | Learning Objectives | Linked Lesson | Author |
| :-----------: | :----------------------------------------: | :--------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------: | :----: |
-| 01 | Defining Data Science | [Introduction](1-Introduction/README.md) | Learn the basic concepts behind data science and how it’s related to artificial intelligence, machine learning, and big data. | [lesson](1-Introduction/01-defining-data-science/README.md) [video](https://youtu.be/pqqsm5reGvs) | [Dmitry](http://soshnikov.com) |
+| 01 | Defining Data Science | [Introduction](1-Introduction/README.md) | Learn the basic concepts behind data science and how it’s related to artificial intelligence, machine learning, and big data. | [lesson](1-Introduction/01-defining-data-science/README.md) [video](https://youtu.be/beZ7Mb_oz9I) | [Dmitry](http://soshnikov.com) |
| 02 | Data Science Ethics | [Introduction](1-Introduction/README.md) | Data Ethics Concepts, Challenges & Frameworks. | [lesson](1-Introduction/02-ethics/README.md) | [Nitya](https://twitter.com/nitya) |
| 03 | Defining Data | [Introduction](1-Introduction/README.md) | How data is classified and its common sources. | [lesson](1-Introduction/03-defining-data/README.md) | [Jasmine](https://www.twitter.com/paladique) |
| 04 | Introduction to Statistics & Probability | [Introduction](1-Introduction/README.md) | The mathematical techniques of probability and statistics to understand data. | [lesson](1-Introduction/04-stats-and-probability/README.md) [video](https://youtu.be/Z5Zy85g4Yjw) | [Dmitry](http://soshnikov.com) |
@@ -78,8 +78,8 @@ In addition, a low-stakes quiz before a class sets the intention of the student
| 12 | Visualizing Relationships | [Data Visualization](3-Data-Visualization/README.md) | Visualizing connections and correlations between sets of data and their variables. | [lesson](3-Data-Visualization/12-visualization-relationships/README.md) | [Jen](https://twitter.com/jenlooper) |
| 13 | Meaningful Visualizations | [Data Visualization](3-Data-Visualization/README.md) | Techniques and guidance for making your visualizations valuable for effective problem solving and insights. | [lesson](3-Data-Visualization/13-meaningful-visualizations/README.md) | [Jen](https://twitter.com/jenlooper) |
| 14 | Introduction to the Data Science lifecycle | [Lifecycle](4-Data-Science-Lifecycle/README.md) | Introduction to the data science lifecycle and its first step of acquiring and extracting data. | [lesson](4-Data-Science-Lifecycle/14-Introduction/README.md) | [Jasmine](https://twitter.com/paladique) |
-| 15 | Analyzing | [Lifecycle](4-Data-Science-Lifecycle/README.md) | This phase of the data science lifecycle focuses on techniques to analyze data. | [lesson](4-Data-Science-Lifecycle/15-Analyzing/README.md) | [Jasmine](https://twitter.com/paladique) | | |
-| 16 | Communication | [Lifecycle](4-Data-Science-Lifecycle/README.md) | This phase of the data science lifecycle focuses on presenting the insights from the data in a way that makes it easier for decision makers to understand. | [lesson](4-Data-Science-Lifecycle/16-Communication/README.md) | [Jalen](https://twitter.com/JalenMcG) | | |
+| 15 | Analyzing | [Lifecycle](4-Data-Science-Lifecycle/README.md) | This phase of the data science lifecycle focuses on techniques to analyze data. | [lesson](4-Data-Science-Lifecycle/15-analyzing/README.md) | [Jasmine](https://twitter.com/paladique) | | |
+| 16 | Communication | [Lifecycle](4-Data-Science-Lifecycle/README.md) | This phase of the data science lifecycle focuses on presenting the insights from the data in a way that makes it easier for decision makers to understand. | [lesson](4-Data-Science-Lifecycle/16-communication/README.md) | [Jalen](https://twitter.com/JalenMcG) | | |
| 17 | Data Science in the Cloud | [Cloud Data](5-Data-Science-In-Cloud/README.md) | This series of lessons introduces data science in the cloud and its benefits. | [lesson](5-Data-Science-In-Cloud/17-Introduction/README.md) | [Tiffany](https://twitter.com/TiffanySouterre) and [Maud](https://twitter.com/maudstweets) |
| 18 | Data Science in the Cloud | [Cloud Data](5-Data-Science-In-Cloud/README.md) | Training models using Low Code tools. |[lesson](5-Data-Science-In-Cloud/18-Low-Code/README.md) | [Tiffany](https://twitter.com/TiffanySouterre) and [Maud](https://twitter.com/maudstweets) |
| 19 | Data Science in the Cloud | [Cloud Data](5-Data-Science-In-Cloud/README.md) | Deploying models with Azure Machine Learning Studio. | [lesson](5-Data-Science-In-Cloud/19-Azure/README.md)| [Tiffany](https://twitter.com/TiffanySouterre) and [Maud](https://twitter.com/maudstweets) |
diff --git a/translations/README.fa.md b/translations/README.fa.md
new file mode 100644
index 0000000..d8de4c5
--- /dev/null
+++ b/translations/README.fa.md
@@ -0,0 +1,111 @@
+
+
+# علم داده برای مبتدیان - برنامه درسی
+
+
+[![GitHub license](https://img.shields.io/github/license/microsoft/Data-Science-For-Beginners.svg)](https://github.com/microsoft/Data-Science-For-Beginners/blob/master/LICENSE)
+[![GitHub contributors](https://img.shields.io/github/contributors/microsoft/Data-Science-For-Beginners.svg)](https://GitHub.com/microsoft/Data-Science-For-Beginners/graphs/contributors/)
+[![GitHub issues](https://img.shields.io/github/issues/microsoft/Data-Science-For-Beginners.svg)](https://GitHub.com/microsoft/Data-Science-For-Beginners/issues/)
+[![GitHub pull-requests](https://img.shields.io/github/issues-pr/microsoft/Data-Science-For-Beginners.svg)](https://GitHub.com/microsoft/Data-Science-For-Beginners/pulls/)
+[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
+
+[![GitHub watchers](https://img.shields.io/github/watchers/microsoft/Data-Science-For-Beginners.svg?style=social&label=Watch)](https://GitHub.com/microsoft/Data-Science-For-Beginners/watchers/)
+[![GitHub forks](https://img.shields.io/github/forks/microsoft/Data-Science-For-Beginners.svg?style=social&label=Fork)](https://GitHub.com/microsoft/Data-Science-For-Beginners/network/)
+[![GitHub stars](https://img.shields.io/github/stars/microsoft/Data-Science-For-Beginners.svg?style=social&label=Star)](https://GitHub.com/microsoft/Data-Science-For-Beginners/stargazers/)
+
+طرفداران Azure Cloud در مایکروسافت مفتخر هستند که یک برنامه درسی 10 هفته ای و 20 درسی درباره علم داده ارائه دهند. هر درس شامل کوییزهای پیش از درس و پس از درس، دستورالعمل های کتبی برای تکمیل درس، راه حل و تکلیف است. آموزش پروژه محور ما به شما این امکان را می دهد در حین ساختن یاد بگیرید، راهی ثابت شده جهت "ماندگاری" مهارت های جدید.
+
+**تشکر از صمیم قلب از نویسندگانمان:** [Jasmine Greenaway](https://www.twitter.com/paladique), [Dmitry Soshnikov](http://soshnikov.com), [Nitya Narasimhan](https://twitter.com/nitya), [Jalen McGee](https://twitter.com/JalenMcG), [Jen Looper](https://twitter.com/jenlooper), [Maud Levy](https://twitter.com/maudstweets), [Tiffany Souterre](https://twitter.com/TiffanySouterre), [Christopher Harrison](https://www.twitter.com/geektrainer).
+
+**🙏 تشکر ویژه 🙏 از نویسندگان سفیر دانشجویی مایکروسافت، بازبینی کنندگان، و مشارکت کنندگان در محتوا،** به ویژه [Raymond Wangsa Putra](https://www.linkedin.com/in/raymond-wp/), [Ankita Singh](https://www.linkedin.com/in/ankitasingh007), [Rohit Yadav](https://www.linkedin.com/in/rty2423), [Arpita Das](https://www.linkedin.com/in/arpitadas01/), [Mohamma Iftekher (Iftu) Ebne Jalal](https://twitter.com/iftu119), [Dishita Bhasin](https://www.linkedin.com/in/dishita-bhasin-7065281bb), [Miguel Correa](https://www.linkedin.com/in/miguelmque/), [Nawrin Tabassum](https://www.linkedin.com/in/nawrin-tabassum), [Sanya Sinha](https://www.linkedin.com/mwlite/in/sanya-sinha-13aab1200), [Majd Safi](https://www.linkedin.com/in/majd-s/), [Sheena Narula](https://www.linkedin.com/in/sheena-narula-n/), [Anupam Mishra](https://www.linkedin.com/in/anupam--mishra/), [Dibri Nsofor](https://www.linkedin.com/in/dibrinsofor), [Aditya Garg](https://github.com/AdityaGarg00), [Alondra Sanchez](https://www.linkedin.com/in/alondra-sanchez-molina/), Yogendrasingh Pawar, Max Blum, Samridhi Sharma, Tauqeer Ahmad, Aaryan Arora, ChhailBihari Dubey
+
+ |![ Sketchnote by [(@sketchthedocs)](https://sketchthedocs.dev) ](../sketchnotes/00-Title.png)|
+|:---:|
+| علم داده برای مبتدیان - یادداشت بصری (sketchnote) از [@nitya](https://twitter.com/nitya)_ |
+
+
+# شروع به کار
+
+> **معلمان**، ما در مورد نحوه استفاده از این برنامه درسی [برخی از پیشنهادات را درج کرده ایم](../for-teachers.md). بسیار خوشحال می شویم که بازخوردهای شما را در [انجمن بحث و گفت و گوی](https://github.com/microsoft/Data-Science-For-Beginners/discussions) خود داشته باشیم!
+
+> **دانش آموزان**، اگر قصد دارید به تنهایی از این برنامه درسی استفاده کنید، کل مخزن را فورک کنید و تمرینات را خودتان به تنهایی انجام دهید. ابتدا با آزمون قبل از درس آغاز کنید، سپس درسنامه را خوانده و باقی فعالیت ها را تکمیل کنید. سعی کنید به جای کپی کردن کد راه حل، خودتان پروژه ها را با درک مفاهیم درسنامه ایجاد کنید. با این حال،کد راه حل در پوشه های /solutions داخل هر درس پروژه محور موجود می باشد. ایده دیگر تشکیل گروه مطالعه با دوستان است تا بتوانید مطالب را با هم مرور کنید، پیشنهاد ما [Microsoft Learn](https://docs.microsoft.com/en-us/users/jenlooper-2911/collections/qprpajyoy3x0g7?WT.mc_id=academic-40229-cxa) می باشد.
+
+
+
+
+## آموزش
+
+ما هنگام تدوین این برنامه درسی دو اصل آموزشی را انتخاب کرده ایم: اطمینان حاصل کنیم که پروژه محور است و شامل آزمونهای مکرر می باشد. دانش آموزان به محض تکمیل این سری آموزشی، اصول اولیه علم داده، شامل اصول اخلاقی، آماده سازی داده ها، روش های مختلف کار با داده ها، تصویرسازی داده ها، تجزیه و تحلیل داده ها، موارد استفاده از علم داده در دنیای واقعی و بسیاری مورد دیگر را فرا می گیرند.
+
+علاوه بر این، یک کوییز با امتیاز کم قبل از کلاس، مقصود دانش آموز درجهت یادگیری یک موضوع را مشخص می کند، در حالی که کوییز دوم بعد از کلاس ماندگاری بیشتر مطالب را تضمین می کند. این برنامه درسی طوری طراحی شده است که انعطاف پذیر و سرگرم کننده باشد و می تواند به طور کامل یا جزئی مورد استفاده قرار گیرد. پروژه از کوچک شروع می شوند و تا پایان چرخه ۱۰ هفته ای همینطور پیچیده تر می شوند.
+
+> دستورالعمل های ما را درباره [کد رفتار](../CODE_OF_CONDUCT.md), [مشارکت](../CONTRIBUTING.md), [ترجمه](../TRANSLATIONS.md) ببینید. ما از بازخورد سازنده شما استقبال می کنیم!
+
+ ## هر درس شامل:
+
+- یادداشت های بصری (sketchnote) اختیاری
+- فیلم های مکمل اختیاری
+- کوییز های دست گرمی قبل از درس
+- درسنامه مکتوب
+- راهنمای گام به گام نحوه ساخت پروژه برای درس های مبتنی بر پروژه
+- بررسی دانش
+- یک چالش
+- منابع خواندنی مکمل
+- تمرین
+- کوییز پس از درس
+
+> **نکته ای در مورد آزمونها**: همه آزمون ها در [این برنامه](https://red-water-0103e7a0f.azurestaticapps.net/) موجود هستند، برای در مجموع ۴۰ کوییز که هرکدام شامل سه سوال می باشد. کوییزها از داخل درسنامه لینک داده شده اند اما برنامه کوییز را می توان به صورت محلی اجرا کرد. برای اینکار، دستورالعمل موجود در پوشه `quiz-app` را دنبال کنید. سوالات به تدریج در حال محلی سازی هستند.
+
+## درسنامه
+
+
+|![ یادداشت بصری (Sketchnote) از [(@sketchthedocs)](https://sketchthedocs.dev) ](../sketchnotes/00-Roadmap.png)|
+|:---:|
+| علم داده برای مبتدیان: نقشه راه - یادداشت بصری از [@nitya](https://twitter.com/nitya)_ |
+
+
+| شماره درس | موضوع | گروه بندی درس | اهداف یادگیری | درس پیوند شده | نویسنده |
+| :-----------: | :----------------------------------------: | :--------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------: | :----: |
+| ۱ | تعریف علم داده | [معرفی](../1-Introduction/README.md) | مفاهیم اساسی علم داده و نحوه ارتباط آن با هوش مصنوعی، یادگیری ماشین و کلان داده را بیاموزید. | [درسنامه](../1-Introduction/01-defining-data-science/README.md) [ویدیو](https://youtu.be/pqqsm5reGvs) | [Dmitry](http://soshnikov.com) |
+| ۲ | اصول اخلاقی علم داده | [معرفی](../1-Introduction/README.md) | مفاهیم اخلاق داده ها، چالش ها و چارچوب ها. | [درسنامه](../1-Introduction/02-ethics/README.md) | [Nitya](https://twitter.com/nitya) |
+| ۳ | تعریف داده | [معرفی](../1-Introduction/README.md) | نحوه دسته بندی داده ها و منابع رایج آن. | [درسنامه](../1-Introduction/03-defining-data/README.md) | [Jasmine](https://www.twitter.com/paladique) |
+| ۴ | مقدمه ای بر آمار و احتمال | [معرفی](../1-Introduction/README.md) | تکنیک های ریاضی آمار و احتمال برای درک داده ها. | [درسنامه](../1-Introduction/04-stats-and-probability/README.md) [ویدیو](https://youtu.be/Z5Zy85g4Yjw) | [Dmitry](http://soshnikov.com) |
+| ۵ | کار با داده های رابطه ای | [کار با داده ها](../2-Working-With-Data/README.md) | مقدمه ای بر داده های رابطه ای و مبانی اکتشاف و تجزیه و تحلیل داده های رابطه ای با زبان پرس و جوی ساختار یافته ، که به SQL نیز معروف است (تلفظ کنید “see-quell”). | [درسنامه](../2-Working-With-Data/05-relational-databases/README.md) | [Christopher](https://www.twitter.com/geektrainer) | | |
+| ۶ | کار با داده های NoSQL | [کار با داده ها](../2-Working-With-Data/README.md) | مقدمه ای بر داده های غیر رابطه ای، انواع مختلف آن و مبانی کاوش و تجزیه و تحلیل پایگاه داده های اسناد(document databases). | [درسنامه](../2-Working-With-Data/06-non-relational/README.md) | [Jasmine](https://twitter.com/paladique)|
+| ۷ | کار با پایتون | [کار با داده ها](../2-Working-With-Data/README.md) | اصول استفاده از پایتون برای کاوش داده با کتابخانه هایی مانند Pandas. توصیه می شود مبانی برنامه نویسی پایتون را بلد باشید. | [درسنامه](../2-Working-With-Data/07-python/README.md) [ویدیو](https://youtu.be/dZjWOGbsN4Y) | [Dmitry](http://soshnikov.com) |
+| ۸ | آماده سازی داده ها | [کار با داده ها](../2-Working-With-Data/README.md) | مباحث مربوط به تکنیک های داده ای برای پاکسازی و تبدیل داده ها به منظور رسیدگی به چالش های داده های مفقود شده، نادرست یا ناقص. | [درسنامه](../2-Working-With-Data/08-data-preparation/README.md) | [Jasmine](https://www.twitter.com/paladique) |
+| ۹ | تصویرسازی مقادیر | [تصویرسازی داده ها](../3-Data-Visualization/README.md) | نحوه استفاده از Matplotlib برای تصویرسازی داده های پرندگان را می آموزید. 🦆 | [درسنامه](../3-Data-Visualization/09-visualization-quantities/README.md) | [Jen](https://twitter.com/jenlooper) |
+| ۱۰ | تصویرسازی توزیع داده ها | [تصویرسازی داده ها](../3-Data-Visualization/README.md) | تصویرسازی مشاهدات و روندها در یک بازه زمانی. | [درسنامه](../3-Data-Visualization/10-visualization-distributions/README.md) | [Jen](https://twitter.com/jenlooper) |
+| ۱۱ | تصویرسازی نسبت ها | [تصویرسازی داده ها](../3-Data-Visualization/README.md) | تصویرسازی درصدهای مجزا و گروهی. | [درسنامه](../3-Data-Visualization/11-visualization-proportions/README.md) | [Jen](https://twitter.com/jenlooper) |
+| ۱۲ | تصویرسازی روابط | [تصویرسازی داده ها](../3-Data-Visualization/README.md) | تصویرسازی ارتباطات و همبستگی بین مجموعه داده ها و متغیرهای آنها. | [درسنامه](../3-Data-Visualization/12-visualization-relationships/README.md) | [Jen](https://twitter.com/jenlooper) |
+| ۱۳ | تصویرسازی های معنی دار | [تصویرسازی داده ها](../3-Data-Visualization/README.md) | تکنیک ها و راهنمایی هایی برای تبدیل تصویرسازی های شما به خروجی های ارزشمندی جهت حل موثرتر مشکلات و بینش ها. | [درسنامه](../3-Data-Visualization/13-meaningful-visualizations/README.md) | [Jen](https://twitter.com/jenlooper) |
+| ۱۴ | مقدمه ای بر چرخه حیات علم داده | [چرخه حیات](../4-Data-Science-Lifecycle/README.md) | مقدمه ای بر چرخه حیات علم داده و اولین گام آن برای دستیابی به داده ها و استخراج آن ها. | [درسنامه](../4-Data-Science-Lifecycle/14-Introduction/README.md) | [Jasmine](https://twitter.com/paladique) |
+| ۱۵ | تجزیه و تحلیل | [چرخه حیات](../4-Data-Science-Lifecycle/README.md) | این مرحله از چرخه حیات علم داده بر تکنیک های تجزیه و تحلیل داده ها متمرکز است. | [درسنامه](../4-Data-Science-Lifecycle/15-Analyzing/README.md) | [Jasmine](https://twitter.com/paladique) | | |
+| ۱۶ | ارتباطات | [چرخه حیات](../4-Data-Science-Lifecycle/README.md) | این مرحله از چرخه حیات علم داده بر روی ارائه بینش از داده ها به نحوی که درک آنها را برای تصمیم گیرندگان آسان تر بکند، متمرکز است. | [درسنامه](../4-Data-Science-Lifecycle/16-Communication/README.md) | [Jalen](https://twitter.com/JalenMcG) | | |
+| ۱۷ | علم داده در فضای ابری | [داده های ابری](../5-Data-Science-In-Cloud/README.md) | این سری از درسنامه ها علم داده در فضای ابری و مزایای آن را معرفی می کند. | [درسنامه](../5-Data-Science-In-Cloud/17-Introduction/README.md) | [Tiffany](https://twitter.com/TiffanySouterre) و [Maud](https://twitter.com/maudstweets) |
+| ۱۸ | علم داده در فضای ابری | [داده های ابری](../5-Data-Science-In-Cloud/README.md) | آموزش مدل ها با استفاده از ابزارهای کد کمتر(low code). |[درسنامه](../5-Data-Science-In-Cloud/18-Low-Code/README.md) | [Tiffany](https://twitter.com/TiffanySouterre) و [Maud](https://twitter.com/maudstweets) |
+| ۱۹ | علم داده در فضای | [داده های ابری](../5-Data-Science-In-Cloud/README.md) | استقرار(Deploy) مدل ها با استفاده از استودیوی یادگیری ماشین آژور(Azure Machine Learning Studio). | [درسنامه](../5-Data-Science-In-Cloud/19-Azure/README.md)| [Tiffany](https://twitter.com/TiffanySouterre) و [Maud](https://twitter.com/maudstweets) |
+| ۲۰ | علم داده در طبیعت | [در طبیعت](../6-Data-Science-In-Wild/README.md) | پروژه های علم داده در دنیای واقعی. | [درسنامه](../6-Data-Science-In-Wild/20-Real-World-Examples/README.md) | [Nitya](https://twitter.com/nitya) |
+## دسترسی آفلاین
+
+شما می توانید این سند را به با استفاده از [Docsify](https://docsify.js.org/#/) به صورت آفلاین اجرا کنید. این مخزن را فورک کنید، [Docsify را روی دستگاه محلی خود نصب کنید](https://docsify.js.org/#/quickstart)، سپس در شاخه اصلی(root) این مخزن، بنویسید `docsify serve`. وب سایت در پورت 3000 روی localhost شما ارائه می شود: `localhost:3000`.
+
+> توجه داشته باشید، نوت بوک ها توسط Docsify ترجمه نمی شوند، بنابراین هنگامی که شما نیاز به اجرای یک نوت بوک دارید، این کار را به صورت جداگانه در VS Code با اجرای یک کرنل پایتون انجام دهید.
+## پی دی اف
+
+یک پی دی اف شامل همه درسها را می توان [اینجا](https://microsoft.github.io/Data-Science-For-Beginners/pdf/readme.pdf) یافت.
+
+## به کمک شما نیازمندیم!
+
+اگر می خواهید تمام یا بخشی از برنامه درسی را ترجمه کنید، لطفاً ظبق راهنمای [ترجمه ها](../TRANSLATIONS.md)ی ما عمل کنید.
+
+## سایر برنامه های درسی
+تیم ما برنامه های درسی دیگری نیز تولید می کند! بدین منظور ببینید:
+
+- [یادگیری ماشین برای مبتدیان](https://aka.ms/ml-beginners)
+- [اینترنت اشیا برای مبتدیان](https://aka.ms/iot-beginners)
+- [توسعه سایت برای مبتدیان](https://aka.ms/webdev-beginners)
+
+
diff --git a/translations/README.fr.md b/translations/README.fr.md
new file mode 100644
index 0000000..65eb3a8
--- /dev/null
+++ b/translations/README.fr.md
@@ -0,0 +1,106 @@
+# La Data Science pour les débutants - Curriculum
+
+[![GitHub license](https://img.shields.io/github/license/microsoft/Data-Science-For-Beginners.svg)](https://github.com/microsoft/Data-Science-For-Beginners/blob/master/LICENSE)
+[![GitHub contributors](https://img.shields.io/github/contributors/microsoft/Data-Science-For-Beginners.svg)](https://GitHub.com/microsoft/Data-Science-For-Beginners/graphs/contributors/)
+[![GitHub issues](https://img.shields.io/github/issues/microsoft/Data-Science-For-Beginners.svg)](https://GitHub.com/microsoft/Data-Science-For-Beginners/issues/)
+[![GitHub pull-requests](https://img.shields.io/github/issues-pr/microsoft/Data-Science-For-Beginners.svg)](https://GitHub.com/microsoft/Data-Science-For-Beginners/pulls/)
+[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
+
+[![GitHub watchers](https://img.shields.io/github/watchers/microsoft/Data-Science-For-Beginners.svg?style=social&label=Watch)](https://GitHub.com/microsoft/Data-Science-For-Beginners/watchers/)
+[![GitHub forks](https://img.shields.io/github/forks/microsoft/Data-Science-For-Beginners.svg?style=social&label=Fork)](https://GitHub.com/microsoft/Data-Science-For-Beginners/network/)
+[![GitHub stars](https://img.shields.io/github/stars/microsoft/Data-Science-For-Beginners.svg?style=social&label=Star)](https://GitHub.com/microsoft/Data-Science-For-Beginners/stargazers/)
+
+L'équipe Azure Cloud Advocates de Microsoft a le plaisir de vous offrir un curriculum d'apprentissage de la Data Science, ou "science des données" en français, comprenant vingt cours à étudier sur une durée d'environ dix semaines. Chaque cours comprend un quiz préalable, un quiz à effectuer après le cours, ainsi que des instructions, un exercice et une solution. Notre pédagogie est basée vous permet d'apprendre tout en réalisant des projets, ce qui permet de bien intégrer les nouvelles compétences que vous allez acquérir.
+
+**Un grand merci à nos auteurs :** [Jasmine Greenaway](https://www.twitter.com/paladique), [Dmitry Soshnikov](http://soshnikov.com), [Nitya Narasimhan](https://twitter.com/nitya), [Jalen McGee](https://twitter.com/JalenMcG), [Jen Looper](https://twitter.com/jenlooper), [Maud Levy](https://twitter.com/maudstweets), [Tiffany Souterre](https://twitter.com/TiffanySouterre), [Christopher Harrison](https://www.twitter.com/geektrainer).
+
+**🙏 Nous remercions également particulièrement 🙏 les auteurs, correcteurs et contributeurs membres du programme Microsoft Learn Student Ambassadors**, notamment [Raymond Wangsa Putra](https://www.linkedin.com/in/raymond-wp/), [Ankita Singh](https://www.linkedin.com/in/ankitasingh007), [Rohit Yadav](https://www.linkedin.com/in/rty2423), [Arpita Das](https://www.linkedin.com/in/arpitadas01/), [Mohamma Iftekher (Iftu) Ebne Jalal](https://twitter.com/iftu119), [Dishita Bhasin](https://www.linkedin.com/in/dishita-bhasin-7065281bb), [Miguel Correa](https://www.linkedin.com/in/miguelmque/), [Nawrin Tabassum](https://www.linkedin.com/in/nawrin-tabassum), [Sanya Sinha](https://www.linkedin.com/mwlite/in/sanya-sinha-13aab1200), [Majd Safi](https://www.linkedin.com/in/majd-s/), [Sheena Narula](https://www.linkedin.com/in/sheena-narula-n/), [Anupam Mishra](https://www.linkedin.com/in/anupam--mishra/), [Dibri Nsofor](https://www.linkedin.com/in/dibrinsofor), [Aditya Garg](https://github.com/AdityaGarg00), [Alondra Sanchez](https://www.linkedin.com/in/alondra-sanchez-molina/), Yogendrasingh Pawar, Max Blum, Samridhi Sharma, Tauqeer Ahmad, Aaryan Arora, ChhailBihari Dubey
+
+|![ Sketchnote by [(@sketchthedocs)](https://sketchthedocs.dev) ](../sketchnotes/00-Title.png)|
+|:---:|
+| Data Science For Beginners - _Sketchnote réalisé par [@nitya](https://twitter.com/nitya)_ |
+
+
+# Prise en main
+
+> **Enseignants**, nous avons [inclus des suggestions](../for-teachers.md) concernant la manière dont vous pouvez utiliser ce curriculum. Nous aimerions beaucoup lire vos feedbacks [dans notre forum de discussion](https://github.com/microsoft/Data-Science-For-Beginners/discussions) !
+
+> **Etudiants**, pour suivre ce curriculum, la première chose à faire est de forker ce repository en entier, vous pourrez ensuite réaliser les exercices de votre côté, en commençant un quiz préalable, en lisant le contenu des cours, et en complétant le reste des activités. Essayez de créer les projets en intégrant bien les cours, plutôt qu'en copiant les solutions. Vous verrez que chaque cours orientée projet contient un dossier dossier /solutions dans lequel vous trouverez la solution des exercices. Vous pouvez aussi former un groupe d'apprentissage avec des amis et vous former ensemble. Pour poursuivre votre apprentissage, nous recommandons d'aller consulter [Microsoft Learn](https://docs.microsoft.com/en-us/users/jenlooper-2911/collections/qprpajyoy3x0g7?WT.mc_id=academic-40229-cxa).
+
+
+
+## Pédagogie
+
+Nous avons choisi deux principes pédagogiques lors de la création de ce programme d'études : veiller à ce qu'il soit basé sur des projets et à ce qu'il comprenne des quiz fréquents. À la fin de cette série, les élèves auront appris les principes de base de la data science, notamment les concepts éthiques, la préparation des données, les différentes façons de travailler avec les données, la visualisation des données, l'analyse des données, des cas d'utilisation réels de data science, etc.
+
+De plus, un quiz à faible enjeu à réaliser avant chaque cours permet de préparer l'étudiant à l'apprentissage du sujet, et un second quiz après le cours permet de fixer encore davantage le contenu dans l'esprit des apprenants. Ce curriculum se veut flexible et ammusant et il peut être suivi dans son intégralité ou en partie. Les premiers projets sont modestes et deviennent de plus en plus ardus.
+
+> Qeulques liens utiles : [Code de conduite](../CODE_OF_CONDUCT.md), [Comment contribuer](../CONTRIBUTING.md), [Traductions](../TRANSLATIONS.md). Tout feedback constructif sera le bienvenu !
+
+## Chaque cours comprend :
+
+- Un sketchnote optionnel
+- Une vidéo complémentaire optionnelle
+- Un quiz préalable
+- Un cours écrit
+- Pour les cours basés sur des projets à réaliser : un guide de création du projet
+- Des vérifications de connaissances
+- Un challenge
+- De la lecture complémentaire
+- Un exercice
+- Un quiz de fin
+
+> **Concernant les quiz** : Vous pourrez retrouver tous les quiz [dans cette application](https://red-water-0103e7a0f.azurestaticapps.net/). Il y a 40 quiz, avec trois questions chacun. Vous les retrouverez dans chaque cours correspondant, mais vous pouvez aussi utiliser l'application de quiz en local en suivant les instruction disponibles dans le dossier `quiz-app`. Les quiz sont en cours de localisation.
+
+## Cours
+
+
+|![ Sketchnote réalisé par [(@sketchthedocs)](https://sketchthedocs.dev) ](../sketchnotes/00-Roadmap.png)|
+|:---:|
+| Data Science For Beginners: Roadmap - _Sketchnote réalisé par [@nitya](https://twitter.com/nitya)_ |
+
+
+| Numéro du cours | Topic | Chapitre | Objectifs d'apprentissage | Liens vers les cours | Auteurs |
+| :-----------: | :----------------------------------------: | :--------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------: | :----: |
+| 01 | Qu'est-ce que la Data Science ? | [Introduction](../1-Introduction/README.md) | Apprenez les concepts de base de la data science et le lien entre la data science, l'intelligence artificielle, le machine learning et la big data. | [cours](../1-Introduction/01-defining-data-science/README.md) [vidéo](https://youtu.be/pqqsm5reGvs) | [Dmitry](http://soshnikov.com) |
+| 02 | Data Science et éthique | [Introduction](../1-Introduction/README.md) | Les concepts d'éthique dans le domaine des données, les challenges et les principes d'encadrement. | [cours](../1-Introduction/02-ethics/README.md) | [Nitya](https://twitter.com/nitya) |
+| 03 | Définition de la data | [Introduction](../1-Introduction/README.md) | Comment classifier les données et d'où viennent-elles principalement ? | [cours](../1-Introduction/03-defining-data/README.md) | [Jasmine](https://www.twitter.com/paladique) |
+| 04 | Introduction aux statistiques et aux probabilités | [Introduction](../1-Introduction/README.md) | Techniques mathématiques de probabilités et de statistiques au service de la data. | [cours](../1-Introduction/04-stats-and-probability/README.md) [vidéo](https://youtu.be/Z5Zy85g4Yjw) | [Dmitry](http://soshnikov.com) |
+| 05 | Utilisation de données relationnelles | [Exploiter des données](../2-Working-With-Data/README.md) | Introduction aux données relationnelles et aux bases d'exploration et d'analyse des données relationnelles avec le Structured Query Language, alias SQL (pronouncé “sicouel”). | [cours](../2-Working-With-Data/05-relational-databases/README.md) | [Christopher](https://www.twitter.com/geektrainer) | | |
+| 06 | Utilisation de données NoSQL | [Exploiter des données](../2-Working-With-Data/README.md) | Présentation des données non relationelles, les types de données et les fondamentaux de l'exploration et de l'analyse de bases de données documentaires. | [cours](../2-Working-With-Data/06-non-relational/README.md) | [Jasmine](https://twitter.com/paladique)|
+| 07 | Utilisation de Python | [Exploiter des données](../2-Working-With-Data/README.md) | Les principes de base de Python pour l'exploration de données, et les librairies courantes telles que Pandas. Des connaissances de base de la programmation Python sont recommandées pour ce cours.| [cours](../2-Working-With-Data/07-python/README.md) [vidéo](https://youtu.be/dZjWOGbsN4Y) | [Dmitry](http://soshnikov.com) |
+| 08 | Préparation des données | [Working With Data](../2-Working-With-Data/README.md) | Techniques de nettoyage et de transformation des données pour gérer des données manquantes, inexactesou incomplètes. | [cours](../2-Working-With-Data/08-data-preparation/README.md) | [Jasmine](https://www.twitter.com/paladique) |
+| 09 | Visualisation des quantités | [Data Visualization](../3-Data-Visualization/README.md) | Apprendre à utiliser Matplotlib pour visualiser des données sur les oiseaux 🦆 | [cours](../3-Data-Visualization/09-visualization-quantities/README.md) | [Jen](https://twitter.com/jenlooper) |
+| 10 | Visualisation de la distribution des données | [Data Visualization](../3-Data-Visualization/README.md) | Visualisation d'observations et de tendances dans un intervalle. | [cours](../3-Data-Visualization/10-visualization-distributions/README.md) | [Jen](https://twitter.com/jenlooper) |
+| 11 | Visualiser des proportions | [Data Visualization](../3-Data-Visualization/README.md) | Visualisation de pourcentages discrets et groupés. | [cours](../3-Data-Visualization/11-visualization-proportions/README.md) | [Jen](https://twitter.com/jenlooper) |
+| 12 | Visualisation de relations | [Data Visualization](../3-Data-Visualization/README.md) | Visualisation de connections et de corrélations entre différents sets de données et leurs variables. | [cours](../3-Data-Visualization/12-visualization-relationships/README.md) | [Jen](https://twitter.com/jenlooper) |
+| 13 | Visualisations significatives | [Data Visualization](../3-Data-Visualization/README.md) | Techniques et conseils pour donner de la valeur à vos visualisations, les rendre utiles à la compréhension et à la résolution de problèmes. | [cours](../3-Data-Visualization/13-meaningful-visualizations/README.md) | [Jen](https://twitter.com/jenlooper) |
+| 14 | Introduction au cycle de vie de la Data Science | [Cycle de vie](../4-Data-Science-Lifecycle/README.md) | Présentation du cycle de la data science et des premières étapes d'acquisition et d'extraction des données. | [cours](../4-Data-Science-Lifecycle/14-Introduction/README.md) | [Jasmine](https://twitter.com/paladique) |
+| 15 | Analyse | [Cycle de vie](../4-Data-Science-Lifecycle/README.md) | Cette étape du cycle de vie de la data science se concentre sur les techniques d'analysation des données. | [cours](../4-Data-Science-Lifecycle/15-Analyzing/README.md) | [Jasmine](https://twitter.com/paladique) | | |
+| 16 | Communication | [Cycle de vie](../4-Data-Science-Lifecycle/README.md) | Cette étape du cycle de vie de la data science se concentre sur la présentation des informations tirées des données de manière à faciliter la compréhension d'une situation par des décisionnaires. | [cours](../4-Data-Science-Lifecycle/16-Communication/README.md) | [Jalen](https://twitter.com/JalenMcG) | | |
+| 17 | La Data Science dans le Cloud | [Cloud Data](../5-Data-Science-In-Cloud/README.md) | Ce cours présente le Cloud et l'intérêt du Cloud pour la Data Science. | [cours](../5-Data-Science-In-Cloud/17-Introduction/README.md) | [Tiffany](https://twitter.com/TiffanySouterre) et [Maud](https://twitter.com/maudstweets) |
+| 18 | La Data Science dans le Cloud | [Cloud Data](../5-Data-Science-In-Cloud/README.md) | Entraîner un modèle avec des outils de low code. |[cours](../5-Data-Science-In-Cloud/18-Low-Code/README.md) | [Tiffany](https://twitter.com/TiffanySouterre) et [Maud](https://twitter.com/maudstweets) |
+| 19 | La Data Science dans le Cloud | [Cloud Data](../5-Data-Science-In-Cloud/README.md) | Déployer des modèles avec Azure Machine Learning Studio. | [cours](../5-Data-Science-In-Cloud/19-Azure/README.md)| [Tiffany](https://twitter.com/TiffanySouterre) et [Maud](https://twitter.com/maudstweets) |
+| 20 | La Data Science dans la nature | [In the Wild](../6-Data-Science-In-Wild/README.md) | Des projets concrets de data science sur le terrain. | [cours](../6-Data-Science-In-Wild/20-Real-World-Examples/README.md) | [Nitya](https://twitter.com/nitya) |
+## Accès hors ligne
+
+Vous pouvez retrouver cette documentation hors ligne à l'aide de [Docsify](https://docsify.js.org/#/). Forkez ce repository, [installez Docsify](https://docsify.js.org/#/quickstart) sur votre machine locale, et tapez `docsify serve` dans le dossier racine de ce repository. Vous retrouverez le site web sur le port 3000 de votre localhost : `localhost:3000`.
+
+> Remarque : vous ne pourrez pas utiliser de notebook avec Docsify. Si vous vouhaitez utilisr un notebook, vous pouvez le faire séparémmnt à l'aide d'un kernel Python dans VS Code.
+## PDF
+
+Vous trouverez un PDF contenant tous les cours du curriculum [ici](https://microsoft.github.io/Data-Science-For-Beginners/pdf/readme.pdf).
+
+## Appel à contribution
+
+Si vous souhaitez traduire le curriculum entier ou en partie, veuillez suivre notre guide de [traduction](../TRANSLATIONS.md).
+
+## Autres Curricula
+
+Notre équipe a créé d'autres cours ! Ne manquez pas :
+
+- [Le Machine Learning pour les débutants](https://aka.ms/ml-beginners)
+- [L'IoT pour les débutants](https://aka.ms/iot-beginners)
+- [Le développement Web pour les débutants](https://aka.ms/webdev-beginners)