Guest User

ESC Reddit Thread Analysis

a guest
Apr 22nd, 2025
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 1.84 KB | None | 0 0
  1. {
  2.  "cells": [
  3.   {
  4.    "metadata": {},
  5.    "cell_type": "code",
  6.    "source": [
  7.     "import pandas as pd\n",
  8.     "from collections import defaultdict\n",
  9.     "df = pd.read_pickle('rankings.pkl')\n",
  10.     "df"
  11.    ],
  12.    "id": "8a40282b57030ec2",
  13.    "outputs": [],
  14.    "execution_count": null
  15.   },
  16.   {
  17.    "metadata": {},
  18.    "cell_type": "markdown",
  19.    "source": [
  20.     "## Overall Scores\n",
  21.     "\n",
  22.     "Each vote is counted based on its position in the list (1st -> 37 points, 2nd -> 36th points, etc.)"
  23.    ],
  24.    "id": "75eec9743ab009a8"
  25.   },
  26.   {
  27.    "metadata": {},
  28.    "cell_type": "code",
  29.    "source": [
  30.     "scores = defaultdict(int)\n",
  31.     "n = df.shape[1]\n",
  32.     "\n",
  33.     "for rank_index, column in enumerate(df.columns):\n",
  34.     "    points = n - rank_index\n",
  35.     "    for candidate in df[column].dropna():\n",
  36.     "        scores[candidate] += points\n",
  37.     "\n",
  38.     "scores_df = pd.DataFrame(scores.items(), columns=[\"Country\", \"Score\"]).sort_values(by=\"Score\", ascending=False)\n",
  39.     "scores_df"
  40.    ],
  41.    "id": "898c4bd6582fa7ab",
  42.    "outputs": [],
  43.    "execution_count": null
  44.   },
  45.   {
  46.    "metadata": {},
  47.    "cell_type": "markdown",
  48.    "source": "## Frequency of occurring in top-10",
  49.    "id": "fa432900b5f43fec"
  50.   },
  51.   {
  52.    "metadata": {},
  53.    "cell_type": "code",
  54.    "source": [
  55.     "top_10_counts = defaultdict(int)\n",
  56.     "\n",
  57.     "for _, row in df[df.columns[:10]].iterrows():\n",
  58.     "    for candidate in row.dropna():\n",
  59.     "        top_10_counts[candidate] += 1\n",
  60.     "\n",
  61.     "top_10_df = pd.DataFrame(top_10_counts.items(), columns=[\"Country\", \"Top 10 Count\"]).sort_values(by=\"Top 10 Count\", ascending=False)\n",
  62.     "top_10_df"
  63.    ],
  64.    "id": "ddd25f243e3796a9",
  65.    "outputs": [],
  66.    "execution_count": null
  67.   }
  68.  ],
  69.  "metadata": {},
  70.  "nbformat": 4,
  71.  "nbformat_minor": 5
  72. }
  73.  
Advertisement
Add Comment
Please, Sign In to add comment