Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "cells": [
- {
- "metadata": {},
- "cell_type": "code",
- "source": [
- "import pandas as pd\n",
- "from collections import defaultdict\n",
- "df = pd.read_pickle('rankings.pkl')\n",
- "df"
- ],
- "id": "8a40282b57030ec2",
- "outputs": [],
- "execution_count": null
- },
- {
- "metadata": {},
- "cell_type": "markdown",
- "source": [
- "## Overall Scores\n",
- "\n",
- "Each vote is counted based on its position in the list (1st -> 37 points, 2nd -> 36th points, etc.)"
- ],
- "id": "75eec9743ab009a8"
- },
- {
- "metadata": {},
- "cell_type": "code",
- "source": [
- "scores = defaultdict(int)\n",
- "n = df.shape[1]\n",
- "\n",
- "for rank_index, column in enumerate(df.columns):\n",
- " points = n - rank_index\n",
- " for candidate in df[column].dropna():\n",
- " scores[candidate] += points\n",
- "\n",
- "scores_df = pd.DataFrame(scores.items(), columns=[\"Country\", \"Score\"]).sort_values(by=\"Score\", ascending=False)\n",
- "scores_df"
- ],
- "id": "898c4bd6582fa7ab",
- "outputs": [],
- "execution_count": null
- },
- {
- "metadata": {},
- "cell_type": "markdown",
- "source": "## Frequency of occurring in top-10",
- "id": "fa432900b5f43fec"
- },
- {
- "metadata": {},
- "cell_type": "code",
- "source": [
- "top_10_counts = defaultdict(int)\n",
- "\n",
- "for _, row in df[df.columns[:10]].iterrows():\n",
- " for candidate in row.dropna():\n",
- " top_10_counts[candidate] += 1\n",
- "\n",
- "top_10_df = pd.DataFrame(top_10_counts.items(), columns=[\"Country\", \"Top 10 Count\"]).sort_values(by=\"Top 10 Count\", ascending=False)\n",
- "top_10_df"
- ],
- "id": "ddd25f243e3796a9",
- "outputs": [],
- "execution_count": null
- }
- ],
- "metadata": {},
- "nbformat": 4,
- "nbformat_minor": 5
- }
Advertisement
Add Comment
Please, Sign In to add comment