diff --git a/.github/assets/logos/Pandas.png b/.github/assets/logos/Pandas.png index ecd1cca40b..7df38146eb 100644 Binary files a/.github/assets/logos/Pandas.png and b/.github/assets/logos/Pandas.png differ diff --git a/Pandas/Pandas_Apply_custom_styles_on_column.ipynb b/Pandas/Pandas_Apply_custom_styles_on_column.ipynb index bff3b46435..1a3016877f 100644 --- a/Pandas/Pandas_Apply_custom_styles_on_column.ipynb +++ b/Pandas/Pandas_Apply_custom_styles_on_column.ipynb @@ -364,4 +364,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +} diff --git a/Pandas/Pandas_Performing_mathematical_operations_on_dataframe.ipynb b/Pandas/Pandas_Performing_mathematical_operations_on_dataframe.ipynb new file mode 100644 index 0000000000..1a747bcc85 --- /dev/null +++ b/Pandas/Pandas_Performing_mathematical_operations_on_dataframe.ipynb @@ -0,0 +1,398 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "bda4f92a-5665-47de-af7c-a849f55131fa", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "\"Pandas.png\"" + ] + }, + { + "cell_type": "markdown", + "id": "1ed72b90-de08-425a-8a76-f4175a522417", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "# Pandas - Performing mathematical operations on dataframe\n", + "

Give Feedback | Bug report" + ] + }, + { + "cell_type": "markdown", + "id": "3513100b-5299-47f9-be21-a336f3972de1", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Tags:** #pandas #dataframe #style #column #apply #custom" + ] + }, + { + "cell_type": "markdown", + "id": "32fb4036-3916-4d3b-b0bf-859172a35938", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Author:** [Siddharth Goyal](https://www.linkedin.com/in/siddharth-goyal-8b1a4814b/)" + ] + }, + { + "cell_type": "markdown", + "id": "ec10fa8a-dabc-4f5f-b4f5-72fd29771f97", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Last update:** 2023-11-27 (Created: 2023-11-22)" + ] + }, + { + "cell_type": "markdown", + "id": "7f751cdd-5e8a-447c-89e4-3a1bca2047ed", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Description:** This notebook will help the users to perform mathematical operation like, sum, median, mode, mean, standard deviation, count on the data present in a column of dataframe" + ] + }, + { + "cell_type": "markdown", + "id": "1cb0cf94-ae27-4aae-bece-e93d1a874a14", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**References:**\n", + "- [Pandas Documentation - Sum](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.sum.html)\n", + "- [Pandas Documentation - Mean](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.mean.html)\n", + "- [Pandas Documentation - Mode](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.mode.html)\n", + "- [Pandas Documentation - Median](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.median.html)\n", + "- [Pandas Documentation - Standard Deviation](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.std.html)\n", + "- [Pandas Documentation - Count](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.count.html)" + ] + }, + { + "cell_type": "markdown", + "id": "3076e4fe-2b09-44c5-adac-00a6d1f5a747", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Input" + ] + }, + { + "cell_type": "markdown", + "id": "63b43b3a-7bc2-4529-b9f9-4698aadc35c6", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Import libraries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "63fda2d7-d1d9-4fd3-a752-13d9214d9acc", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "import pandas as pd" + ] + }, + { + "cell_type": "markdown", + "id": "22d01f0c-e5f7-4b18-a72a-89d014c1850f", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Model" + ] + }, + { + "cell_type": "markdown", + "id": "8704a59c-d01d-4eba-94a7-2a16a37837df", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Create DataFrame" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "87d45a29-4fc3-4c06-af32-3536d91f6c55", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "# Sample DataFrame\n", + "data = {\n", + " 'Name': ['Alice', 'Bob', 'Charlie', 'Alice', 'Eva'],\n", + " 'Score': [95, -80, 70, -80, 85],\n", + " 'Age': [25, 32, 18, None, 28],\n", + " 'Sales': [1200, 980, 1500, 850, 1750]\n", + "}\n", + "\n", + "df = pd.DataFrame(data)\n", + "df" + ] + }, + { + "cell_type": "markdown", + "id": "3f55ae9b-848a-41dd-9481-81393017fb2b", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Sum\n", + "The `sum` function will help to get the sum of any column in the dataframe" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3e05ee25-4089-44f4-9c8d-4ad1f151e397", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "#We will do this the mathematical operations on column Age\n", + "\n", + "ageSum = df['Age'].sum()\n", + "ageSum" + ] + }, + { + "cell_type": "markdown", + "id": "1e137ae0-e639-4ec0-9ec0-0a1be9d75aac", + "metadata": {}, + "source": [ + "### Mean\n", + "The `mean` function will help to get the mean of any column in the dataframe" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7bd08345-431b-4338-a764-6833eb06b51b", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "#We will do this the mathematical operations on column Age\n", + "\n", + "ageMean = df['Age'].mean()\n", + "ageMean" + ] + }, + { + "cell_type": "markdown", + "id": "d0799092-b280-4ec8-a261-ab08572a7984", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Mode\n", + "The `mode` function will help to get the unique values of a row in the dataframe" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f6cfa95f-8f85-40a3-83cd-18edeb21692b", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "#We will do this the mathematical operation on Age column\n", + "\n", + "NameMode = df['Name'].mode()\n", + "NameMode" + ] + }, + { + "cell_type": "markdown", + "id": "0ed200d1-4ca5-437f-b5d6-4d226a229f26", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Median\n", + "The `median` function will help to get the median of any column in the dataframe" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "27c05a6a-c1e5-4b4f-a575-9b4e3e6ace39", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "#We will do this the mathematical operations on column Age\n", + "\n", + "ageMedian = df['Age'].median()\n", + "ageMedian" + ] + }, + { + "cell_type": "markdown", + "id": "a2e5fbbf-c19e-4b50-aa43-ae0562fc90c3", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Standard Deviation\n", + "The `std` function will help to get the Standard Deviation of any column in the dataframe" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ffd0378b-42a0-4f59-8375-d6427ebc9094", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "#We will do this the mathematical operations on column Age\n", + "\n", + "ageStandDev = df['Age'].std()\n", + "ageStandDev" + ] + }, + { + "cell_type": "markdown", + "id": "61067205-063e-4020-972a-81d40c65c918", + "metadata": {}, + "source": [ + "### Count\n", + "The `count` function will help to get the total number of non Null rows of any column in the dataframe" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "46da4d29-4cf9-4a9e-94cb-1a3d3c60489d", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "#We will do this the mathematical operations on column Age\n", + "\n", + "notNullCount = df['Age'].count()\n", + "notNullCount" + ] + }, + { + "cell_type": "markdown", + "id": "df976c2f-9abb-41e8-8776-a0748d59bb9a", + "metadata": {}, + "source": [ + "## Output" + ] + }, + { + "cell_type": "markdown", + "id": "69942bc8-9505-4a0f-86ef-fe552f8dd02d", + "metadata": {}, + "source": [ + "### Display result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "afd28121-c410-4518-922d-fc866b55282b", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "print(\"Sum of Age Column is: \", ageSum)\n", + "print(\"Mean of Age Column is: \", ageMean)\n", + "print(\"Mode of Name Column is:\\n\", NameMode)\n", + "print(\"Median of Age Column is: \",ageMedian)\n", + "print(\"Standard Deviation of Age Column is: \", ageStandDev)\n", + "print(\"Count of non-null rows in Name column: \", notNullCount)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.6" + }, + "naas": { + "notebook_id": "5d27e3bd7fdfda696205d0e879b9a00e31ece1a64cae3c864ab22b006a0ab495", + "notebook_path": "Pandas/Pandas_Apply_custom_styles_on_column.ipynb" + }, + "papermill": { + "default_parameters": {}, + "environment_variables": {}, + "parameters": {}, + "version": "2.4.0" + }, + "widgets": { + "application/vnd.jupyter.widget-state+json": { + "state": {}, + "version_major": 2, + "version_minor": 0 + } + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}