{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "df = pd.read_csv(\"C://Users//annal//aim//static//csv//Forbes_Billionaires.csv\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Определим бизнес цели:\n",
    "## 1- Прогнозирование места в рейтинге\n",
    "## 2- Оценка факторов, влияющих на место в рейтинге"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Определим цели технического проекта:\n",
    "## Построить модель, которая будет прогнозировать место в рейтинге на основе представленных данных об участнике\n",
    "## Провести анализ данных для выявления важнейших характеристик для прогнозирования"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Проверим выбросы и усредним"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Колонка Networth:\n",
      "  Есть выбросы: Да\n",
      "  Количество выбросов: 226\n",
      "  Минимальное значение: 1.0\n",
      "  Максимальное значение: 9.0\n",
      "  1-й квантиль (Q1): 1.5\n",
      "  3-й квантиль (Q3): 4.5\n",
      "\n",
      "Колонка Age:\n",
      "  Есть выбросы: Да\n",
      "  Количество выбросов: 6\n",
      "  Минимальное значение: 26.5\n",
      "  Максимальное значение: 100.0\n",
      "  1-й квантиль (Q1): 55.0\n",
      "  3-й квантиль (Q3): 74.0\n",
      "\n"
     ]
    }
   ],
   "source": [
    "numeric_columns = ['Networth', 'Age']\n",
    "for column in numeric_columns:\n",
    "    if pd.api.types.is_numeric_dtype(df[column]):  # Проверяем, является ли колонка числовой\n",
    "        q1 = df[column].quantile(0.25)  # Находим 1-й квантиль (Q1)\n",
    "        q3 = df[column].quantile(0.75)  # Находим 3-й квантиль (Q3)\n",
    "        iqr = q3 - q1  # Вычисляем межквантильный размах (IQR)\n",
    "\n",
    "        # Определяем границы для выбросов\n",
    "        lower_bound = q1 - 1.5 * iqr  # Нижняя граница\n",
    "        upper_bound = q3 + 1.5 * iqr  # Верхняя граница\n",
    "\n",
    "        # Подсчитываем количество выбросов\n",
    "        outliers = df[(df[column] < lower_bound) | (df[column] > upper_bound)]\n",
    "        outlier_count = outliers.shape[0]\n",
    "\n",
    "        # Устраняем выбросы: заменяем значения ниже нижней границы на саму нижнюю границу, а выше верхней — на верхнюю\n",
    "        df[column] = df[column].apply(lambda x: lower_bound if x < lower_bound else upper_bound if x > upper_bound else x)\n",
    "\n",
    "        print(f\"Колонка {column}:\")\n",
    "        print(f\"  Есть выбросы: {'Да' if outlier_count > 0 else 'Нет'}\")\n",
    "        print(f\"  Количество выбросов: {outlier_count}\")\n",
    "        print(f\"  Минимальное значение: {df[column].min()}\")\n",
    "        print(f\"  Максимальное значение: {df[column].max()}\")\n",
    "        print(f\"  1-й квантиль (Q1): {q1}\")\n",
    "        print(f\"  3-й квантиль (Q3): {q3}\\n\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Превратим номинальные столбцы в числовые"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   Rank   Networth   Age  Country  Source  Industry  \\\n",
      "0      1       9.0  50.0       70     123         0   \n",
      "1      2       9.0  58.0       70       5        15   \n",
      "2      3       9.0  73.0       20      73         3   \n",
      "3      4       9.0  66.0       70      81        15   \n",
      "4      5       9.0  91.0       70      11         4   \n",
      "\n",
      "   Name_Abdulla Al Futtaim & family   \\\n",
      "0                                0.0   \n",
      "1                                0.0   \n",
      "2                                0.0   \n",
      "3                                0.0   \n",
      "4                                0.0   \n",
      "\n",
      "   Name_Abdulla bin Ahmad Al Ghurair & family   Name_Abdulsamad Rabiu   \\\n",
      "0                                          0.0                     0.0   \n",
      "1                                          0.0                     0.0   \n",
      "2                                          0.0                     0.0   \n",
      "3                                          0.0                     0.0   \n",
      "4                                          0.0                     0.0   \n",
      "\n",
      "   Name_Abhay Firodia   ...  Name_Zhu Yan & family   Name_Zhu Yiming   \\\n",
      "0                  0.0  ...                     0.0               0.0   \n",
      "1                  0.0  ...                     0.0               0.0   \n",
      "2                  0.0  ...                     0.0               0.0   \n",
      "3                  0.0  ...                     0.0               0.0   \n",
      "4                  0.0  ...                     0.0               0.0   \n",
      "\n",
      "   Name_Zhu Yiwen & family   Name_Zhuo Jun   Name_Ziv Aviram   \\\n",
      "0                       0.0             0.0               0.0   \n",
      "1                       0.0             0.0               0.0   \n",
      "2                       0.0             0.0               0.0   \n",
      "3                       0.0             0.0               0.0   \n",
      "4                       0.0             0.0               0.0   \n",
      "\n",
      "   Name_Zong Qinghou   Name_Zong Yanmin   Name_Zugen Ni   Name_Zuowen Song   \\\n",
      "0                 0.0                0.0             0.0                0.0   \n",
      "1                 0.0                0.0             0.0                0.0   \n",
      "2                 0.0                0.0             0.0                0.0   \n",
      "3                 0.0                0.0             0.0                0.0   \n",
      "4                 0.0                0.0             0.0                0.0   \n",
      "\n",
      "   Name_Zygmunt Solorz-Zak   \n",
      "0                       0.0  \n",
      "1                       0.0  \n",
      "2                       0.0  \n",
      "3                       0.0  \n",
      "4                       0.0  \n",
      "\n",
      "[5 rows x 2603 columns]\n"
     ]
    }
   ],
   "source": [
    "from sklearn.preprocessing import OneHotEncoder, LabelEncoder\n",
    "\n",
    "# Определение категориальных признаков для преобразования\n",
    "categorical_columns = ['Name']\n",
    "\n",
    "# Инициализация OneHotEncoder\n",
    "encoder = OneHotEncoder(sparse_output=False, drop=\"first\")\n",
    "\n",
    "# Применение OneHotEncoder к выбранным категориальным признакам\n",
    "encoded_values = encoder.fit_transform(df[categorical_columns])\n",
    "\n",
    "# Получение имен новых закодированных столбцов\n",
    "encoded_columns = encoder.get_feature_names_out(categorical_columns)\n",
    "\n",
    "# Преобразование в DataFrame\n",
    "encoded_values_df = pd.DataFrame(encoded_values, columns=encoded_columns)\n",
    "\n",
    "# Объединение закодированных значений с оригинальным DataFrame, исключив исходные категориальные столбцы\n",
    "df = df.drop(columns=categorical_columns)\n",
    "df = pd.concat([df.reset_index(drop=True), encoded_values_df.reset_index(drop=True)], axis=1)\n",
    "\n",
    "# Применение Label Encoding для столбца 'Country', 'Source', 'Industry'\n",
    "label_encoder = LabelEncoder()\n",
    "df['Country'] = label_encoder.fit_transform(df['Country'])\n",
    "df['Source'] = label_encoder.fit_transform(df['Source'])\n",
    "df['Industry'] = label_encoder.fit_transform(df['Industry'])\n",
    "\n",
    "\n",
    "print(df.head())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Создадим выборки данных по параметру места в рейтинге"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Размер обучающей выборки: (1560, 2602)\n",
      "Размер контрольной выборки: (520, 2602)\n",
      "Размер тестовой выборки: (520, 2602)\n"
     ]
    }
   ],
   "source": [
    "from sklearn.model_selection import train_test_split\n",
    "\n",
    "# Выделение признаков (X) и целевой переменной (y)\n",
    "X = df.drop(columns=['Rank '])  # Признаки\n",
    "y = df['Rank ']                 # Целевая переменная\n",
    "\n",
    "# Разделение данных на обучающую и временную выборки\n",
    "X_train, X_temp, y_train, y_temp = train_test_split(X, y, test_size=0.4, random_state=42)\n",
    "\n",
    "# Разделение временной выборки на контрольную и тестовую выборки\n",
    "X_val, X_test, y_val, y_test = train_test_split(X_temp, y_temp, test_size=0.5, random_state=42)\n",
    "\n",
    "# Проверка размеров выборок\n",
    "print(f\"Размер обучающей выборки: {X_train.shape}\")\n",
    "print(f\"Размер контрольной выборки: {X_val.shape}\")\n",
    "print(f\"Размер тестовой выборки: {X_test.shape}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 40648 characters]",
      "text/plain": [
       "<Figure size 1000x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 42512 characters]",
      "text/plain": [
       "<Figure size 1000x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 40576 characters]",
      "text/plain": [
       "<Figure size 1000x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import seaborn as sns\n",
    "import matplotlib.pyplot as plt\n",
    "# Функция для оценки распределения цены\n",
    "def plot_distribution(y_data, title):\n",
    "    plt.figure(figsize=(10, 6))\n",
    "    sns.histplot(y_data, kde=True, bins=50)\n",
    "    plt.title(title)\n",
    "    plt.xlabel('Rank ')\n",
    "    plt.ylabel('Frequency')\n",
    "    plt.grid(True)\n",
    "    plt.show()\n",
    "\n",
    "# Оценка распределения цены в каждой выборке\n",
    "plot_distribution(y_train, \"Распределение места в обучающей выборке\")\n",
    "plot_distribution(y_val, \"Распределение места в контрольной выборке\")\n",
    "plot_distribution(y_test, \"Распределение места в тестовой выборке\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Применим min-max нормировку для улучшения качества работы модели"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Нормированные данные:\n",
      "   Networth       Age   Country    Source  Industry  \\\n",
      "0       1.0  0.319728  0.945946  0.137584  0.000000   \n",
      "1       1.0  0.428571  0.945946  0.005593  0.882353   \n",
      "2       1.0  0.632653  0.270270  0.081655  0.176471   \n",
      "3       1.0  0.537415  0.945946  0.090604  0.882353   \n",
      "4       1.0  0.877551  0.945946  0.012304  0.235294   \n",
      "\n",
      "   Name_Abdulla Al Futtaim & family   \\\n",
      "0                                0.0   \n",
      "1                                0.0   \n",
      "2                                0.0   \n",
      "3                                0.0   \n",
      "4                                0.0   \n",
      "\n",
      "   Name_Abdulla bin Ahmad Al Ghurair & family   Name_Abdulsamad Rabiu   \\\n",
      "0                                          0.0                     0.0   \n",
      "1                                          0.0                     0.0   \n",
      "2                                          0.0                     0.0   \n",
      "3                                          0.0                     0.0   \n",
      "4                                          0.0                     0.0   \n",
      "\n",
      "   Name_Abhay Firodia   Name_Abigail Johnson   ...  Name_Zhu Yan & family   \\\n",
      "0                  0.0                    0.0  ...                     0.0   \n",
      "1                  0.0                    0.0  ...                     0.0   \n",
      "2                  0.0                    0.0  ...                     0.0   \n",
      "3                  0.0                    0.0  ...                     0.0   \n",
      "4                  0.0                    0.0  ...                     0.0   \n",
      "\n",
      "   Name_Zhu Yiming   Name_Zhu Yiwen & family   Name_Zhuo Jun   \\\n",
      "0               0.0                       0.0             0.0   \n",
      "1               0.0                       0.0             0.0   \n",
      "2               0.0                       0.0             0.0   \n",
      "3               0.0                       0.0             0.0   \n",
      "4               0.0                       0.0             0.0   \n",
      "\n",
      "   Name_Ziv Aviram   Name_Zong Qinghou   Name_Zong Yanmin   Name_Zugen Ni   \\\n",
      "0               0.0                 0.0                0.0             0.0   \n",
      "1               0.0                 0.0                0.0             0.0   \n",
      "2               0.0                 0.0                0.0             0.0   \n",
      "3               0.0                 0.0                0.0             0.0   \n",
      "4               0.0                 0.0                0.0             0.0   \n",
      "\n",
      "   Name_Zuowen Song   Name_Zygmunt Solorz-Zak   \n",
      "0                0.0                       0.0  \n",
      "1                0.0                       0.0  \n",
      "2                0.0                       0.0  \n",
      "3                0.0                       0.0  \n",
      "4                0.0                       0.0  \n",
      "\n",
      "[5 rows x 2602 columns]\n",
      "\n",
      "Стандартизированные данные:\n",
      "   Networth       Age   Country    Source  Industry  \\\n",
      "0  2.266803 -1.081352  1.173910 -1.505003 -1.701719   \n",
      "1  2.266803 -0.475422  1.173910 -2.004526  1.339990   \n",
      "2  2.266803  0.660697 -0.805574 -1.716665 -1.093377   \n",
      "3  2.266803  0.130508  1.173910 -1.682800  1.339990   \n",
      "4  2.266803  2.024040  1.173910 -1.979126 -0.890597   \n",
      "\n",
      "   Name_Abdulla Al Futtaim & family   \\\n",
      "0                          -0.019615   \n",
      "1                          -0.019615   \n",
      "2                          -0.019615   \n",
      "3                          -0.019615   \n",
      "4                          -0.019615   \n",
      "\n",
      "   Name_Abdulla bin Ahmad Al Ghurair & family   Name_Abdulsamad Rabiu   \\\n",
      "0                                    -0.019615               -0.019615   \n",
      "1                                    -0.019615               -0.019615   \n",
      "2                                    -0.019615               -0.019615   \n",
      "3                                    -0.019615               -0.019615   \n",
      "4                                    -0.019615               -0.019615   \n",
      "\n",
      "   Name_Abhay Firodia   Name_Abigail Johnson   ...  Name_Zhu Yan & family   \\\n",
      "0            -0.019615              -0.019615  ...               -0.019615   \n",
      "1            -0.019615              -0.019615  ...               -0.019615   \n",
      "2            -0.019615              -0.019615  ...               -0.019615   \n",
      "3            -0.019615              -0.019615  ...               -0.019615   \n",
      "4            -0.019615              -0.019615  ...               -0.019615   \n",
      "\n",
      "   Name_Zhu Yiming   Name_Zhu Yiwen & family   Name_Zhuo Jun   \\\n",
      "0         -0.019615                 -0.019615       -0.019615   \n",
      "1         -0.019615                 -0.019615       -0.019615   \n",
      "2         -0.019615                 -0.019615       -0.019615   \n",
      "3         -0.019615                 -0.019615       -0.019615   \n",
      "4         -0.019615                 -0.019615       -0.019615   \n",
      "\n",
      "   Name_Ziv Aviram   Name_Zong Qinghou   Name_Zong Yanmin   Name_Zugen Ni   \\\n",
      "0         -0.019615           -0.019615          -0.019615       -0.019615   \n",
      "1         -0.019615           -0.019615          -0.019615       -0.019615   \n",
      "2         -0.019615           -0.019615          -0.019615       -0.019615   \n",
      "3         -0.019615           -0.019615          -0.019615       -0.019615   \n",
      "4         -0.019615           -0.019615          -0.019615       -0.019615   \n",
      "\n",
      "   Name_Zuowen Song   Name_Zygmunt Solorz-Zak   \n",
      "0          -0.019615                 -0.019615  \n",
      "1          -0.019615                 -0.019615  \n",
      "2          -0.019615                 -0.019615  \n",
      "3          -0.019615                 -0.019615  \n",
      "4          -0.019615                 -0.019615  \n",
      "\n",
      "[5 rows x 2602 columns]\n"
     ]
    }
   ],
   "source": [
    "from sklearn.preprocessing import MinMaxScaler, StandardScaler\n",
    "\n",
    "# Предполагаем, что вы уже выделили ваши признаки X\n",
    "# Применение нормировки Min-Max к всем числовым признакам\n",
    "min_max_scaler = MinMaxScaler()\n",
    "X_normalized = pd.DataFrame(min_max_scaler.fit_transform(X), columns=X.columns)\n",
    "\n",
    "# Применение стандартизации к всем числовым признакам\n",
    "standard_scaler = StandardScaler()\n",
    "X_standardized = pd.DataFrame(standard_scaler.fit_transform(X), columns=X.columns)\n",
    "\n",
    "# Проверка первых 5 строк после нормировки\n",
    "print(\"Нормированные данные:\")\n",
    "print(X_normalized.head())\n",
    "\n",
    "# Проверка первых 5 строк после стандартизации\n",
    "print(\"\\nСтандартизированные данные:\")\n",
    "print(X_standardized.head())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Приведём пример использования future tools\n",
    "## Попробую вынести страну в отдельную таблицу"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting featuretoolsNote: you may need to restart the kernel to use updated packages.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n",
      "[notice] A new release of pip is available: 24.2 -> 24.3.1\n",
      "[notice] To update, run: python.exe -m pip install --upgrade pip\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "  Downloading featuretools-1.31.0-py3-none-any.whl.metadata (15 kB)\n",
      "Collecting cloudpickle>=1.5.0 (from featuretools)\n",
      "  Downloading cloudpickle-3.1.0-py3-none-any.whl.metadata (7.0 kB)\n",
      "Collecting holidays>=0.17 (from featuretools)\n",
      "  Downloading holidays-0.59-py3-none-any.whl.metadata (25 kB)\n",
      "Requirement already satisfied: numpy>=1.25.0 in c:\\users\\annal\\aim\\.venv\\lib\\site-packages (from featuretools) (2.1.1)\n",
      "Requirement already satisfied: packaging>=20.0 in c:\\users\\annal\\aim\\.venv\\lib\\site-packages (from featuretools) (24.1)\n",
      "Requirement already satisfied: pandas>=2.0.0 in c:\\users\\annal\\aim\\.venv\\lib\\site-packages (from featuretools) (2.2.2)\n",
      "Requirement already satisfied: psutil>=5.7.0 in c:\\users\\annal\\aim\\.venv\\lib\\site-packages (from featuretools) (6.0.0)\n",
      "Requirement already satisfied: scipy>=1.10.0 in c:\\users\\annal\\aim\\.venv\\lib\\site-packages (from featuretools) (1.14.1)\n",
      "Collecting tqdm>=4.66.3 (from featuretools)\n",
      "  Downloading tqdm-4.66.6-py3-none-any.whl.metadata (57 kB)\n",
      "Collecting woodwork>=0.28.0 (from featuretools)\n",
      "  Downloading woodwork-0.31.0-py3-none-any.whl.metadata (10 kB)\n",
      "Requirement already satisfied: python-dateutil in c:\\users\\annal\\aim\\.venv\\lib\\site-packages (from holidays>=0.17->featuretools) (2.9.0.post0)\n",
      "Requirement already satisfied: pytz>=2020.1 in c:\\users\\annal\\aim\\.venv\\lib\\site-packages (from pandas>=2.0.0->featuretools) (2024.1)\n",
      "Requirement already satisfied: tzdata>=2022.7 in c:\\users\\annal\\aim\\.venv\\lib\\site-packages (from pandas>=2.0.0->featuretools) (2024.1)\n",
      "Requirement already satisfied: colorama in c:\\users\\annal\\aim\\.venv\\lib\\site-packages (from tqdm>=4.66.3->featuretools) (0.4.6)\n",
      "Requirement already satisfied: scikit-learn>=1.1.0 in c:\\users\\annal\\aim\\.venv\\lib\\site-packages (from woodwork>=0.28.0->featuretools) (1.5.2)\n",
      "Collecting importlib-resources>=5.10.0 (from woodwork>=0.28.0->featuretools)\n",
      "  Downloading importlib_resources-6.4.5-py3-none-any.whl.metadata (4.0 kB)\n",
      "Requirement already satisfied: six>=1.5 in c:\\users\\annal\\aim\\.venv\\lib\\site-packages (from python-dateutil->holidays>=0.17->featuretools) (1.16.0)\n",
      "Requirement already satisfied: joblib>=1.2.0 in c:\\users\\annal\\aim\\.venv\\lib\\site-packages (from scikit-learn>=1.1.0->woodwork>=0.28.0->featuretools) (1.4.2)\n",
      "Requirement already satisfied: threadpoolctl>=3.1.0 in c:\\users\\annal\\aim\\.venv\\lib\\site-packages (from scikit-learn>=1.1.0->woodwork>=0.28.0->featuretools) (3.5.0)\n",
      "Downloading featuretools-1.31.0-py3-none-any.whl (587 kB)\n",
      "   ---------------------------------------- 0.0/587.9 kB ? eta -:--:--\n",
      "   ----------------- ---------------------- 262.1/587.9 kB ? eta -:--:--\n",
      "   ---------------------------------------- 587.9/587.9 kB 1.5 MB/s eta 0:00:00\n",
      "Downloading cloudpickle-3.1.0-py3-none-any.whl (22 kB)\n",
      "Downloading holidays-0.59-py3-none-any.whl (1.1 MB)\n",
      "   ---------------------------------------- 0.0/1.1 MB ? eta -:--:--\n",
      "   --------- ------------------------------ 0.3/1.1 MB ? eta -:--:--\n",
      "   ---------------------------- ----------- 0.8/1.1 MB 1.9 MB/s eta 0:00:01\n",
      "   ---------------------------------------- 1.1/1.1 MB 2.2 MB/s eta 0:00:00\n",
      "Downloading tqdm-4.66.6-py3-none-any.whl (78 kB)\n",
      "Downloading woodwork-0.31.0-py3-none-any.whl (215 kB)\n",
      "Downloading importlib_resources-6.4.5-py3-none-any.whl (36 kB)\n",
      "Installing collected packages: tqdm, importlib-resources, cloudpickle, holidays, woodwork, featuretools\n",
      "Successfully installed cloudpickle-3.1.0 featuretools-1.31.0 holidays-0.59 importlib-resources-6.4.5 tqdm-4.66.6 woodwork-0.31.0\n"
     ]
    }
   ],
   "source": [
    "pip install --upgrade featuretools"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting setuptools\n",
      "  Downloading setuptools-75.3.0-py3-none-any.whl.metadata (6.9 kB)\n",
      "Downloading setuptools-75.3.0-py3-none-any.whl (1.3 MB)\n",
      "   ---------------------------------------- 0.0/1.3 MB ? eta -:--:--\n",
      "   ---------------- ----------------------- 0.5/1.3 MB 3.4 MB/s eta 0:00:01\n",
      "   ---------------------------------------- 1.3/1.3 MB 3.7 MB/s eta 0:00:00\n",
      "Installing collected packages: setuptools\n",
      "Successfully installed setuptools-75.3.0\n",
      "Note: you may need to restart the kernel to use updated packages.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n",
      "[notice] A new release of pip is available: 24.2 -> 24.3.1\n",
      "[notice] To update, run: python.exe -m pip install --upgrade pip\n"
     ]
    }
   ],
   "source": [
    "pip install --upgrade setuptools"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Users\\annal\\aim\\.venv\\Lib\\site-packages\\featuretools\\entityset\\entityset.py:1733: UserWarning: index billioner_id not found in dataframe, creating new integer column\n",
      "  warnings.warn(\n",
      "c:\\Users\\annal\\aim\\.venv\\Lib\\site-packages\\woodwork\\type_sys\\utils.py:33: UserWarning: Could not infer format, so each element will be parsed individually, falling back to `dateutil`. To ensure parsing is consistent and as-expected, please specify a format.\n",
      "  pd.to_datetime(\n",
      "c:\\Users\\annal\\aim\\.venv\\Lib\\site-packages\\woodwork\\type_sys\\utils.py:33: UserWarning: Could not infer format, so each element will be parsed individually, falling back to `dateutil`. To ensure parsing is consistent and as-expected, please specify a format.\n",
      "  pd.to_datetime(\n",
      "c:\\Users\\annal\\aim\\.venv\\Lib\\site-packages\\woodwork\\type_sys\\utils.py:33: UserWarning: Could not infer format, so each element will be parsed individually, falling back to `dateutil`. To ensure parsing is consistent and as-expected, please specify a format.\n",
      "  pd.to_datetime(\n",
      "c:\\Users\\annal\\aim\\.venv\\Lib\\site-packages\\woodwork\\type_sys\\utils.py:33: UserWarning: Could not infer format, so each element will be parsed individually, falling back to `dateutil`. To ensure parsing is consistent and as-expected, please specify a format.\n",
      "  pd.to_datetime(\n",
      "c:\\Users\\annal\\aim\\.venv\\Lib\\site-packages\\woodwork\\type_sys\\utils.py:33: UserWarning: Could not infer format, so each element will be parsed individually, falling back to `dateutil`. To ensure parsing is consistent and as-expected, please specify a format.\n",
      "  pd.to_datetime(\n",
      "c:\\Users\\annal\\aim\\.venv\\Lib\\site-packages\\woodwork\\type_sys\\utils.py:33: UserWarning: Could not infer format, so each element will be parsed individually, falling back to `dateutil`. To ensure parsing is consistent and as-expected, please specify a format.\n",
      "  pd.to_datetime(\n",
      "c:\\Users\\annal\\aim\\.venv\\Lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function max at 0x000001952157A520> is currently using SeriesGroupBy.max. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"max\" instead.\n",
      "  ).agg(to_agg)\n",
      "c:\\Users\\annal\\aim\\.venv\\Lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function std at 0x000001952157B060> is currently using SeriesGroupBy.std. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"std\" instead.\n",
      "  ).agg(to_agg)\n",
      "c:\\Users\\annal\\aim\\.venv\\Lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function sum at 0x0000019521579B20> is currently using SeriesGroupBy.sum. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"sum\" instead.\n",
      "  ).agg(to_agg)\n",
      "c:\\Users\\annal\\aim\\.venv\\Lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function min at 0x000001952157A660> is currently using SeriesGroupBy.min. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"min\" instead.\n",
      "  ).agg(to_agg)\n",
      "c:\\Users\\annal\\aim\\.venv\\Lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:785: FutureWarning: The provided callable <function mean at 0x000001952157AF20> is currently using SeriesGroupBy.mean. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"mean\" instead.\n",
      "  ).agg(to_agg)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Rank</th>\n",
       "      <th>Networth</th>\n",
       "      <th>Age</th>\n",
       "      <th>Industry</th>\n",
       "      <th>id</th>\n",
       "      <th>country_id</th>\n",
       "      <th>country_table.id</th>\n",
       "      <th>country_table.Country</th>\n",
       "      <th>country_table.COUNT(other_about_billioner)</th>\n",
       "      <th>country_table.MAX(other_about_billioner.Age)</th>\n",
       "      <th>...</th>\n",
       "      <th>country_table.SKEW(other_about_billioner.Rank )</th>\n",
       "      <th>country_table.SKEW(other_about_billioner.id)</th>\n",
       "      <th>country_table.STD(other_about_billioner.Age)</th>\n",
       "      <th>country_table.STD(other_about_billioner.Networth)</th>\n",
       "      <th>country_table.STD(other_about_billioner.Rank )</th>\n",
       "      <th>country_table.STD(other_about_billioner.id)</th>\n",
       "      <th>country_table.SUM(other_about_billioner.Age)</th>\n",
       "      <th>country_table.SUM(other_about_billioner.Networth)</th>\n",
       "      <th>country_table.SUM(other_about_billioner.Rank )</th>\n",
       "      <th>country_table.SUM(other_about_billioner.id)</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>billioner_id</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>219</td>\n",
       "      <td>50</td>\n",
       "      <td>Automotive</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>United States</td>\n",
       "      <td>1</td>\n",
       "      <td>50.0</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>50.0</td>\n",
       "      <td>219.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>171</td>\n",
       "      <td>58</td>\n",
       "      <td>Technology</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>United States</td>\n",
       "      <td>1</td>\n",
       "      <td>58.0</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>58.0</td>\n",
       "      <td>171.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>158</td>\n",
       "      <td>73</td>\n",
       "      <td>Fashion &amp; Retail</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>France</td>\n",
       "      <td>1</td>\n",
       "      <td>73.0</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>73.0</td>\n",
       "      <td>158.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>129</td>\n",
       "      <td>66</td>\n",
       "      <td>Technology</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>United States</td>\n",
       "      <td>1</td>\n",
       "      <td>66.0</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>66.0</td>\n",
       "      <td>129.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>118</td>\n",
       "      <td>91</td>\n",
       "      <td>Finance &amp; Investments</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>United States</td>\n",
       "      <td>1</td>\n",
       "      <td>91.0</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>91.0</td>\n",
       "      <td>118.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2595</th>\n",
       "      <td>2578</td>\n",
       "      <td>1</td>\n",
       "      <td>80</td>\n",
       "      <td>Healthcare</td>\n",
       "      <td>2595</td>\n",
       "      <td>2595</td>\n",
       "      <td>2595</td>\n",
       "      <td>Spain</td>\n",
       "      <td>1</td>\n",
       "      <td>80.0</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>80.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2578.0</td>\n",
       "      <td>2595.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2596</th>\n",
       "      <td>2578</td>\n",
       "      <td>1</td>\n",
       "      <td>82</td>\n",
       "      <td>Fashion &amp; Retail</td>\n",
       "      <td>2596</td>\n",
       "      <td>2596</td>\n",
       "      <td>2596</td>\n",
       "      <td>Philippines</td>\n",
       "      <td>1</td>\n",
       "      <td>82.0</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>82.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2578.0</td>\n",
       "      <td>2596.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2597</th>\n",
       "      <td>2578</td>\n",
       "      <td>1</td>\n",
       "      <td>71</td>\n",
       "      <td>Fashion &amp; Retail</td>\n",
       "      <td>2597</td>\n",
       "      <td>2597</td>\n",
       "      <td>2597</td>\n",
       "      <td>Philippines</td>\n",
       "      <td>1</td>\n",
       "      <td>71.0</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>71.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2578.0</td>\n",
       "      <td>2597.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2598</th>\n",
       "      <td>2578</td>\n",
       "      <td>1</td>\n",
       "      <td>68</td>\n",
       "      <td>Fashion &amp; Retail</td>\n",
       "      <td>2598</td>\n",
       "      <td>2598</td>\n",
       "      <td>2598</td>\n",
       "      <td>Philippines</td>\n",
       "      <td>1</td>\n",
       "      <td>68.0</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>68.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2578.0</td>\n",
       "      <td>2598.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2599</th>\n",
       "      <td>2578</td>\n",
       "      <td>1</td>\n",
       "      <td>69</td>\n",
       "      <td>Food &amp; Beverage</td>\n",
       "      <td>2599</td>\n",
       "      <td>2599</td>\n",
       "      <td>2599</td>\n",
       "      <td>Germany</td>\n",
       "      <td>1</td>\n",
       "      <td>69.0</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>69.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2578.0</td>\n",
       "      <td>2599.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2600 rows × 35 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "              Rank   Networth  Age                Industry    id  country_id  \\\n",
       "billioner_id                                                                   \n",
       "0                 1       219   50             Automotive      0           0   \n",
       "1                 2       171   58             Technology      1           1   \n",
       "2                 3       158   73       Fashion & Retail      2           2   \n",
       "3                 4       129   66             Technology      3           3   \n",
       "4                 5       118   91  Finance & Investments      4           4   \n",
       "...             ...       ...  ...                     ...   ...         ...   \n",
       "2595           2578         1   80             Healthcare   2595        2595   \n",
       "2596           2578         1   82       Fashion & Retail   2596        2596   \n",
       "2597           2578         1   71       Fashion & Retail   2597        2597   \n",
       "2598           2578         1   68       Fashion & Retail   2598        2598   \n",
       "2599           2578         1   69        Food & Beverage   2599        2599   \n",
       "\n",
       "              country_table.id country_table.Country  \\\n",
       "billioner_id                                           \n",
       "0                            0         United States   \n",
       "1                            1         United States   \n",
       "2                            2                France   \n",
       "3                            3         United States   \n",
       "4                            4         United States   \n",
       "...                        ...                   ...   \n",
       "2595                      2595                 Spain   \n",
       "2596                      2596           Philippines   \n",
       "2597                      2597           Philippines   \n",
       "2598                      2598           Philippines   \n",
       "2599                      2599               Germany   \n",
       "\n",
       "              country_table.COUNT(other_about_billioner)  \\\n",
       "billioner_id                                               \n",
       "0                                                      1   \n",
       "1                                                      1   \n",
       "2                                                      1   \n",
       "3                                                      1   \n",
       "4                                                      1   \n",
       "...                                                  ...   \n",
       "2595                                                   1   \n",
       "2596                                                   1   \n",
       "2597                                                   1   \n",
       "2598                                                   1   \n",
       "2599                                                   1   \n",
       "\n",
       "              country_table.MAX(other_about_billioner.Age)  ...  \\\n",
       "billioner_id                                                ...   \n",
       "0                                                     50.0  ...   \n",
       "1                                                     58.0  ...   \n",
       "2                                                     73.0  ...   \n",
       "3                                                     66.0  ...   \n",
       "4                                                     91.0  ...   \n",
       "...                                                    ...  ...   \n",
       "2595                                                  80.0  ...   \n",
       "2596                                                  82.0  ...   \n",
       "2597                                                  71.0  ...   \n",
       "2598                                                  68.0  ...   \n",
       "2599                                                  69.0  ...   \n",
       "\n",
       "              country_table.SKEW(other_about_billioner.Rank )  \\\n",
       "billioner_id                                                    \n",
       "0                                                         NaN   \n",
       "1                                                         NaN   \n",
       "2                                                         NaN   \n",
       "3                                                         NaN   \n",
       "4                                                         NaN   \n",
       "...                                                       ...   \n",
       "2595                                                      NaN   \n",
       "2596                                                      NaN   \n",
       "2597                                                      NaN   \n",
       "2598                                                      NaN   \n",
       "2599                                                      NaN   \n",
       "\n",
       "              country_table.SKEW(other_about_billioner.id)  \\\n",
       "billioner_id                                                 \n",
       "0                                                      NaN   \n",
       "1                                                      NaN   \n",
       "2                                                      NaN   \n",
       "3                                                      NaN   \n",
       "4                                                      NaN   \n",
       "...                                                    ...   \n",
       "2595                                                   NaN   \n",
       "2596                                                   NaN   \n",
       "2597                                                   NaN   \n",
       "2598                                                   NaN   \n",
       "2599                                                   NaN   \n",
       "\n",
       "              country_table.STD(other_about_billioner.Age)  \\\n",
       "billioner_id                                                 \n",
       "0                                                      NaN   \n",
       "1                                                      NaN   \n",
       "2                                                      NaN   \n",
       "3                                                      NaN   \n",
       "4                                                      NaN   \n",
       "...                                                    ...   \n",
       "2595                                                   NaN   \n",
       "2596                                                   NaN   \n",
       "2597                                                   NaN   \n",
       "2598                                                   NaN   \n",
       "2599                                                   NaN   \n",
       "\n",
       "              country_table.STD(other_about_billioner.Networth)  \\\n",
       "billioner_id                                                      \n",
       "0                                                           NaN   \n",
       "1                                                           NaN   \n",
       "2                                                           NaN   \n",
       "3                                                           NaN   \n",
       "4                                                           NaN   \n",
       "...                                                         ...   \n",
       "2595                                                        NaN   \n",
       "2596                                                        NaN   \n",
       "2597                                                        NaN   \n",
       "2598                                                        NaN   \n",
       "2599                                                        NaN   \n",
       "\n",
       "              country_table.STD(other_about_billioner.Rank )  \\\n",
       "billioner_id                                                   \n",
       "0                                                        NaN   \n",
       "1                                                        NaN   \n",
       "2                                                        NaN   \n",
       "3                                                        NaN   \n",
       "4                                                        NaN   \n",
       "...                                                      ...   \n",
       "2595                                                     NaN   \n",
       "2596                                                     NaN   \n",
       "2597                                                     NaN   \n",
       "2598                                                     NaN   \n",
       "2599                                                     NaN   \n",
       "\n",
       "              country_table.STD(other_about_billioner.id)  \\\n",
       "billioner_id                                                \n",
       "0                                                     NaN   \n",
       "1                                                     NaN   \n",
       "2                                                     NaN   \n",
       "3                                                     NaN   \n",
       "4                                                     NaN   \n",
       "...                                                   ...   \n",
       "2595                                                  NaN   \n",
       "2596                                                  NaN   \n",
       "2597                                                  NaN   \n",
       "2598                                                  NaN   \n",
       "2599                                                  NaN   \n",
       "\n",
       "              country_table.SUM(other_about_billioner.Age)  \\\n",
       "billioner_id                                                 \n",
       "0                                                     50.0   \n",
       "1                                                     58.0   \n",
       "2                                                     73.0   \n",
       "3                                                     66.0   \n",
       "4                                                     91.0   \n",
       "...                                                    ...   \n",
       "2595                                                  80.0   \n",
       "2596                                                  82.0   \n",
       "2597                                                  71.0   \n",
       "2598                                                  68.0   \n",
       "2599                                                  69.0   \n",
       "\n",
       "              country_table.SUM(other_about_billioner.Networth)  \\\n",
       "billioner_id                                                      \n",
       "0                                                         219.0   \n",
       "1                                                         171.0   \n",
       "2                                                         158.0   \n",
       "3                                                         129.0   \n",
       "4                                                         118.0   \n",
       "...                                                         ...   \n",
       "2595                                                        1.0   \n",
       "2596                                                        1.0   \n",
       "2597                                                        1.0   \n",
       "2598                                                        1.0   \n",
       "2599                                                        1.0   \n",
       "\n",
       "              country_table.SUM(other_about_billioner.Rank )  \\\n",
       "billioner_id                                                   \n",
       "0                                                        1.0   \n",
       "1                                                        2.0   \n",
       "2                                                        3.0   \n",
       "3                                                        4.0   \n",
       "4                                                        5.0   \n",
       "...                                                      ...   \n",
       "2595                                                  2578.0   \n",
       "2596                                                  2578.0   \n",
       "2597                                                  2578.0   \n",
       "2598                                                  2578.0   \n",
       "2599                                                  2578.0   \n",
       "\n",
       "              country_table.SUM(other_about_billioner.id)  \n",
       "billioner_id                                               \n",
       "0                                                     0.0  \n",
       "1                                                     1.0  \n",
       "2                                                     2.0  \n",
       "3                                                     3.0  \n",
       "4                                                     4.0  \n",
       "...                                                   ...  \n",
       "2595                                               2595.0  \n",
       "2596                                               2596.0  \n",
       "2597                                               2597.0  \n",
       "2598                                               2598.0  \n",
       "2599                                               2599.0  \n",
       "\n",
       "[2600 rows x 35 columns]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import featuretools as ft\n",
    "from woodwork.logical_types import Categorical, Integer\n",
    "import pandas as pd\n",
    "df = pd.read_csv(\"C://Users//annal//aim//static//csv//Forbes_Billionaires.csv\")\n",
    "df['id'] = pd.Series(range(len(df))) \n",
    "# Создание двух таблиц: одна с моделью, другая с остальными данными\n",
    "country_df = df[['id', 'Country']].drop_duplicates().reset_index(drop=True)\n",
    "other_df = df.drop(columns=['Country'])\n",
    "\n",
    "# Создание уникального идентификатора для связи\n",
    "country_df['country_id'] = country_df.index\n",
    "other_df['country_id'] = other_df['id'].map(country_df.set_index('id')['country_id'])\n",
    "\n",
    "es = ft.EntitySet(id=\"orders\")\n",
    "es = es.add_dataframe(\n",
    "    dataframe_name=\"country_table\",\n",
    "    dataframe=country_df,\n",
    "    index=\"country_id\",  # Индекс для уникальной идентификации моделей\n",
    "    logical_types={\n",
    "        \"Country\": Categorical  # Определяем логический тип для модели\n",
    "    },\n",
    ")\n",
    "es = es.add_dataframe(\n",
    "    dataframe_name=\"other_about_billioner\",\n",
    "    dataframe=other_df,\n",
    "    index=\"billioner_id\",  # Индекс для уникальной идентификации миллиардеров\n",
    "    logical_types={\n",
    "        \"Rank \": Integer,  # Целевая переменная (цена)\n",
    "        \"Networth\": Integer,  \n",
    "        \"Age\": Integer,\n",
    "        \"country_id\": Integer,  \n",
    "    },\n",
    ")\n",
    "es = es.add_relationship(\"country_table\", \"country_id\", \"other_about_billioner\", \"country_id\")\n",
    "\n",
    "feature_matrix, feature_defs = ft.dfs(\n",
    "    entityset=es,\n",
    "    target_dataframe_name=\"other_about_billioner\"\n",
    ")\n",
    "\n",
    "feature_matrix"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "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.12.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
