From 4b84516d523f89fe1300623741d2c34bebe36bd9 Mon Sep 17 00:00:00 2001 From: Kilokem Date: Fri, 6 Dec 2024 10:43:44 +0100 Subject: [PATCH] I had a mental breakdown --- 09_gyak.ipynb | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++ 13_gyak.ipynb | 66 ++++++++++++++++++++++++++++--- 2 files changed, 167 insertions(+), 5 deletions(-) diff --git a/09_gyak.ipynb b/09_gyak.ipynb index 516321d..8d19ca8 100644 --- a/09_gyak.ipynb +++ b/09_gyak.ipynb @@ -43,6 +43,112 @@ "\n", "print([list(map(sum,i)) for i in lines])" ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "A leghosszab szó: 'gépidőelszámolást', ami 17 karakterből áll\n" + ] + } + ], + "source": [ + "lines = []\n", + "with open(\"igazi.txt\") as f:\n", + " lines.extend(f.readlines())\n", + "lines = list(set([i.strip() for i in lines]))\n", + "lenoflines = [len(i) for i in lines]\n", + "\n", + "\n", + "print(f\"A leghosszab szó: '{lines[lenoflines.index(max(lenoflines))]}', ami {max(lenoflines)} karakterből áll\")" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "65 90\n" + ] + } + ], + "source": [ + "print(ord('A'), ord('Z'))" + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Blackburn Rovers 45\n", + "Wolverhampton Wanderers 38\n", + "Fulham FC 55\n", + "Aston Villa 39\n", + "Liverpool FC 43\n", + "Sunderland AFC 45\n", + "Queens Park Rangers 43\n", + "Bolton Wanderers 42\n", + "Wigan Athletic 41\n", + "Norwich City 47\n", + "Newcastle United 48\n", + "Arsenal FC 58\n", + "Stoke City 44\n", + "Chelsea FC 60\n", + "West Bromwich Albion 40\n", + "Manchester United 71\n", + "Manchester City 74\n", + "Swansea City 46\n", + "Tottenham Hotspur 58\n", + "Everton FC 47\n" + ] + } + ], + "source": [ + "class matches:\n", + " def __init__(self):\n", + " pass\n", + "\n", + "A = []\n", + "with open(\"pl.txt\") as f:\n", + " for _ in range(6):\n", + " next(f)\n", + " for i in f.readlines():\n", + " match = matches()\n", + " line = i.strip().split('\\t')\n", + " match.ford = line[0]\n", + " match.hteam = line[1]\n", + " match.vteam = line[2]\n", + " match.hgoal = int(line[3])\n", + " match.vgoal = int(line[4])\n", + " A.append(match)\n", + "\n", + "teams = {}\n", + "for i in A:\n", + " if i.hteam in teams.keys():\n", + " teams[i.hteam] += i.hgoal\n", + " else:\n", + " teams.update({i.hteam : i.hgoal})\n", + " if i.vteam in teams.keys():\n", + " teams[i.vteam] += 1 \n", + " else:\n", + " teams.update({i.vteam : 1})\n", + "\n", + "print(\"\\n\".join(f\"{i.ljust(25)} {j}\" for i, j in teams.items()))" + ] } ], "metadata": { diff --git a/13_gyak.ipynb b/13_gyak.ipynb index f32b8a9..28ee9ed 100644 --- a/13_gyak.ipynb +++ b/13_gyak.ipynb @@ -33,15 +33,71 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 42, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
fordulosum
0538
\n", + "
" + ], + "text/plain": [ + " fordulo sum\n", + "0 5 38" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import pandas as pd\n", + "\n", + "df = pd.read_csv(\"pl.txt\", skiprows=6, sep=\"\\t\", names=[\"fordulo\", \"hcsapat\", \"vcsapat\", \"hgol\", \"vgol\"])\n", + "\n", + "df.groupby(\"fordulo\").count()[\"hcsapat\"]\n", + "\n", + "goals_round = df.groupby(\"fordulo\")[[\"hgol\", \"vgol\"]].sum().sort_values(\"hgol\", ascending=False)[:1]\n", + "goals_round[\"sum\"] = goals_round[\"hgol\"] + goals_round[\"vgol\"]\n", + "\n", + "goals_round.reset_index()[[\"fordulo\", \"sum\"]]" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -55,7 +111,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.3" + "version": "3.12.3" } }, "nbformat": 4,