|
290 | 290 | "metadata": {},
|
291 | 291 | "outputs": [],
|
292 | 292 | "source": [
|
293 |
| - "def generate_table(): \n", |
| 293 | + "def init_highest_table(): \n", |
294 | 294 | " df_highest = pd.DataFrame(columns={\"Indicator\"})\n",
|
295 | 295 | " df_highest[\"Indicator\"] = indicators\n",
|
296 | 296 | " df_highest[\"Year range\"] = 0\n",
|
|
317 | 317 | "metadata": {},
|
318 | 318 | "outputs": [],
|
319 | 319 | "source": [
|
320 |
| - "iterable = list(range(min(set(df_gold['Year'])), max(set(df_gold['Year'])) + 1))\n", |
321 |
| - "iterable = list(itertools.combinations(iterable, 2))\n", |
322 |
| - "iterable_aux = iterable.copy()\n", |
323 |
| - "\n", |
324 |
| - "#The year length must be higher than 5. All entries with a lower range are deleted.\n", |
325 |
| - "for years in iterable_aux:\n", |
326 |
| - " if (years[1] - years[0]) < 4:\n", |
327 |
| - " iterable.remove(years)\n", |
328 |
| - "\n", |
329 | 320 | "indicators = list(df_gold.columns[3:])\n",
|
330 | 321 | "indicators.remove('GDP')"
|
331 | 322 | ]
|
332 | 323 | },
|
333 | 324 | {
|
334 | 325 | "cell_type": "code",
|
335 | 326 | "execution_count": 7,
|
| 327 | + "metadata": {}, |
| 328 | + "outputs": [], |
| 329 | + "source": [ |
| 330 | + "def generate_years_combinations(min_diff: int):\n", |
| 331 | + " iterable = list(range(min(set(df_gold['Year'])), max(set(df_gold['Year'])) + 1))\n", |
| 332 | + " iterable = list(itertools.combinations(iterable, 2))\n", |
| 333 | + " \n", |
| 334 | + " #The year length must be higher than min_diff. All entries with a lower range are deleted.\n", |
| 335 | + " for years in iterable.copy():\n", |
| 336 | + " if (years[1] - years[0]) < min_diff:\n", |
| 337 | + " iterable.remove(years)\n", |
| 338 | + " \n", |
| 339 | + " return iterable" |
| 340 | + ] |
| 341 | + }, |
336 | 342 | "metadata": {},
|
337 | 343 | "outputs": [
|
338 | 344 | {
|
|
377 | 383 | " #Search for the entries of the region and normalize.\n",
|
378 | 384 | " df_zone = countries_by_region[Zone]\n",
|
379 | 385 | "\n",
|
380 |
| - " df_highest = generate_table()\n", |
| 386 | + " df_highest = init_highest_table()\n", |
381 | 387 | " \n",
|
382 | 388 | " i = 0\n",
|
383 | 389 | " computing_text = \"Loading \"\n",
|
384 | 390 | " print (computing_text, end=\"\\r\")\n",
|
385 | 391 | "\n",
|
386 | 392 | "\n",
|
387 | 393 | " #For all the combination of years...\n",
|
388 |
| - " for years in iterable:\n", |
| 394 | + " for years in generate_years_combinations(5):\n", |
389 | 395 | " i = (i + 1) % 50\n",
|
390 | 396 | " print (computing_text + \"\".join([\".\" for _ in range(i)]), end=\"\\r\")\n",
|
| 397 | + " \n", |
391 | 398 | " df_aux = searchTimeSeries(0, years[0], years[1], True, df_zone)\n",
|
392 | 399 | " #Delete indicators which are not available that year\n",
|
393 | 400 | " indicators_inter = list(set(indicators) & set(list(df_aux.index)))\n",
|
|
476 | 483 | "def plotYearRange(Zone, Indicator, Years):\n",
|
477 | 484 | " df_aux = df_gold_index.loc[df_gold_index.index.get_level_values('Country') == Zone]\n",
|
478 | 485 | " df_aux = df_aux.loc[(df_aux.index.get_level_values(\"Year\") >= Years[0]) & (df_aux.index.get_level_values(\"Year\") <= Years[1])]\n",
|
| 486 | + " # TODO: Country or Region??\n", |
479 | 487 | " spear = stats.spearmanr(df_aux[Indicator], df_aux['GDP'])\n",
|
480 | 488 | " df_aux = normalize_by_country(df_aux).reset_index(drop=False)\n",
|
481 | 489 | " \n",
|
482 | 490 | " print(spear)\n",
|
483 | 491 | " plt.figure(figsize=(6,6))\n",
|
484 |
| - " plt.plot(df_aux[\"GDP\"], color=\"red\", label = 'GDP')\n", |
485 |
| - " plt.plot(df_aux[Indicator], color=\"green\", label = Indicator)\n", |
| 492 | + " plt.plot(df_aux[\"Year\"], df_aux[\"GDP\"], color=\"red\", label = 'GDP')\n", |
| 493 | + " plt.plot(df_aux[\"Year\"], df_aux[Indicator], color=\"green\", label = Indicator)\n", |
486 | 494 | " plt.legend(loc=\"lower right\")\n",
|
487 | 495 | " \n",
|
488 | 496 | "\n",
|
|
509 | 517 | ")\n",
|
510 | 518 | "\n",
|
511 | 519 | "\n",
|
512 |
| - "\n", |
513 | 520 | "# TODO By Region: Say Y axis is Qualitative (Not real values but Normalized to observe evolution vs GDP - Tendendency)\n",
|
514 | 521 | "widgets.interact(plotYearRange, Zone = country_drop, Indicator = indicator_drop, Years = intslider)"
|
515 | 522 | ]
|
|
0 commit comments