Pandas feladatok

This commit is contained in:
2024-12-09 19:41:42 +01:00
parent b99346376f
commit 32d805ecf1
3 changed files with 301 additions and 14 deletions

View File

@ -168,16 +168,100 @@
]
},
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": []
"source": [
"### 3. feladat [10p]\n",
"\n",
"Az [unicef.txt](unicef.txt) szövegfájl a világ 5 év alatti népességének élelmezési helyzetéről tartalmaz adatokat. Az egyes sorok felméréseknek felelnek meg, a felmérések országonként időbeli sorrendben vannak felsorolva. Töltsük be az adatokat, határozzuk meg és írjuk ki az alábbi statisztikákat!\n",
"- Hány felmérés készült és hány országot érintett?\n",
"- Az alábbi statisztikákat csak azon felmérések alapján készítsük el, amelyeknél mind a három érintett indikátor (`Severe Wasting`, `Underweight`, `Overweight`) definiált (azaz ezek pozitív adatok). Ha egy országra több ilyen felmérés is van, akkor a legutóbbit vegyük figyelembe!\n",
" - Mely 5 országban a legmagasabb a `Severe Wasting` indikátor?\n",
" - Az országok hányadrészében magasabb az `Underweight` indikátor az `Overweight` indikátornál?"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" Country United Nations Region United Nations Sub-Region \\\n",
"0 AFGHANISTAN Asia Southern Asia \n",
"1 AFGHANISTAN Asia Southern Asia \n",
"2 AFGHANISTAN Asia Southern Asia \n",
"3 ALBANIA Europe Southern Europe \n",
"4 ALBANIA Europe Southern Europe \n",
"\n",
" World Bank Income Classification Survey Year Survey Sample (N) \\\n",
"0 Low Income 1997 4846.0 \n",
"1 Low Income 2004 946.0 \n",
"2 Low Income 2013 21922.0 \n",
"3 Upper Middle Income 1996-98 7642.0 \n",
"4 Upper Middle Income 2000 1382.0 \n",
"\n",
" Severe Wasting Wasting Stunting Underweight Overweight \\\n",
"0 NaN 18,2 53,2 44,9 6,5 \n",
"1 3,5 8,6 59,3 32,9 4,6 \n",
"2 4,0 9,5 40,9 25,0 5,4 \n",
"3 NaN 8,1 20,4 7,1 9,5 \n",
"4 6,2 12,2 39,2 17,0 30,0 \n",
"\n",
" Source Notes \\\n",
"0  Afghanistan 1997 multiple indicator baseline ... Converted estimates \n",
"1 Summary report of the national nutrition surve... NaN \n",
"2 Afghanistan National Nutrition Survey 2013. (pending reanalysis) \n",
"3 National study on nutrition in Albania. Instit... Converted estimates \n",
"4 Multiple indicator cluster survey report Alban... NaN \n",
"\n",
" U5 Population ('000s) \n",
"0 3637,632 \n",
"1 4667,487 \n",
"2 5235,867 \n",
"3 307,887 \n",
"4 278,753 \n"
]
}
],
"source": [
"import pandas as pd\n",
"\n",
"frame = pd.read_csv(\"unicef.txt\", sep=\"|\")\n",
"print(frame[:5])"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"keszult: 854\n",
"Orszag: 152\n"
]
}
],
"source": [
"orszag = frame[\"Country\"].count()\n",
"\n",
"print(\"keszult: \",orszag)\n",
"\n",
"city = frame.groupby(\"Country\")[\"Survey Year\"].count().count()\n",
"\n",
"\n",
"print(\"Orszag: \",city)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
@ -191,7 +275,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.5"
"version": "3.13.0"
}
},
"nbformat": 4,