{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "##**Using pandas**"
      ],
      "metadata": {
        "id": "PNOU7LLrQ8Ox"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "import pandas as pd\n",
        "\n",
        "\n",
        "data = {\n",
        "    'Employee_ID': [10, 20, 15, 25, 30],\n",
        "    'Gender': ['M', 'F', 'F', 'M', 'F'],\n",
        "    'Remarks': ['Good', 'Nice', 'Good', 'Great', 'Nice']\n",
        "}\n",
        "\n",
        "df = pd.DataFrame(data)\n",
        "\n",
        "print(\"Original Data:\")\n",
        "print(df)\n",
        "\n",
        "\n",
        "encoded_df = pd.get_dummies(\n",
        "    df,\n",
        "    columns=['Gender', 'Remarks'],\n",
        "    drop_first=True\n",
        ")\n",
        "\n",
        "print(\"\\nOne-Hot Encoded Data:\")\n",
        "print(encoded_df)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "L0-Ov9eCHTsZ",
        "outputId": "aaed3b44-aef1-4146-ec28-a4fa7484faf4"
      },
      "execution_count": 2,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Original Data:\n",
            "   Employee_ID Gender Remarks\n",
            "0           10      M    Good\n",
            "1           20      F    Nice\n",
            "2           15      F    Good\n",
            "3           25      M   Great\n",
            "4           30      F    Nice\n",
            "\n",
            "One-Hot Encoded Data:\n",
            "   Employee_ID  Gender_M  Remarks_Great  Remarks_Nice\n",
            "0           10      True          False         False\n",
            "1           20     False          False          True\n",
            "2           15     False          False         False\n",
            "3           25      True           True         False\n",
            "4           30     False          False          True\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "##**Using scikit learn**"
      ],
      "metadata": {
        "id": "ZbIMVwaiT-j7"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "import pandas as pd\n",
        "from sklearn.preprocessing import OneHotEncoder\n",
        "\n",
        "data = {\n",
        "    'Employee_ID': [10, 20, 15, 25, 30],\n",
        "    'Gender': ['M', 'F', 'F', 'M', 'F'],\n",
        "    'Remarks': ['Good', 'Nice', 'Good', 'Great', 'Nice']\n",
        "}\n",
        "\n",
        "df = pd.DataFrame(data)\n",
        "\n",
        "print(\"Original Data:\")\n",
        "print(df)\n",
        "\n",
        "categorical_columns = df.select_dtypes(include=['object']).columns\n",
        "\n",
        "encoder = OneHotEncoder(sparse_output=False)\n",
        "\n",
        "encoded_data = encoder.fit_transform(df[categorical_columns])\n",
        "\n",
        "encoded_df = pd.DataFrame(\n",
        "    encoded_data,\n",
        "    columns=encoder.get_feature_names_out(categorical_columns)\n",
        ")\n",
        "\n",
        "final_df = pd.concat(\n",
        "    [df.drop(columns=categorical_columns), encoded_df],\n",
        "    axis=1\n",
        ")\n",
        "\n",
        "print(\"\\nOne-Hot Encoded Data:\")\n",
        "print(final_df)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "RhOUDR_LHTuo",
        "outputId": "de44aee1-c04b-4411-d676-825920d0f992"
      },
      "execution_count": 3,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Original Data:\n",
            "   Employee_ID Gender Remarks\n",
            "0           10      M    Good\n",
            "1           20      F    Nice\n",
            "2           15      F    Good\n",
            "3           25      M   Great\n",
            "4           30      F    Nice\n",
            "\n",
            "One-Hot Encoded Data:\n",
            "   Employee_ID  Gender_F  Gender_M  Remarks_Good  Remarks_Great  Remarks_Nice\n",
            "0           10       0.0       1.0           1.0            0.0           0.0\n",
            "1           20       1.0       0.0           0.0            0.0           1.0\n",
            "2           15       1.0       0.0           1.0            0.0           0.0\n",
            "3           25       0.0       1.0           0.0            1.0           0.0\n",
            "4           30       1.0       0.0           0.0            0.0           1.0\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [],
      "metadata": {
        "id": "stBpzqjgHTyz"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [],
      "metadata": {
        "id": "zkpKwWZXHT1Z"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [],
      "metadata": {
        "id": "n12brn4pHT7p"
      },
      "execution_count": null,
      "outputs": []
    }
  ]
}