{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Python: Drugie zadanie domowe" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Drugie zadanie domowe będzie polegać na opracowaniu danych zawartych w pliku `gapminder.csv`, który znajduje się w tym katalogu (proszę wykorzystać ten plik, a nie ten w katalogu labs04). Ten arkusz poprowadzi Cię krok po kroku po zadaniu domowym." ] }, { "cell_type": "code", "execution_count": 97, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**zad. 1** Wczytaj dane do zmiennej `data`, w taki sposób, żeby nazwa Państwa była kluczem." ] }, { "cell_type": "code", "execution_count": 86, "metadata": {}, "outputs": [], "source": [ "data = pd.read_csv(\"gapminder.csv\", index_col=0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**zad. 2** Znajdź najbardziej i najmniej zaludnione państwa na świecie." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**zad. 3** W ilu państwach współczynnik `female_BMI` jest większy od `male_BMI`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**zad. 4**\n", " 1. Zainstaluj bibliotekę `pycountry_convert` i zaimportuj ją.\n", " 1. Dodaj do danych kolumnę `continent`, która będzie zawierać nazwę kontynentu, na którym jest położone dane państwo. Wykorzystaj bibliotekę `pycountry_convert`. *Uwaga*: trzeba najpierw uzystać kod państwa w fomacie ISO-2, następnie uzystkać kod kontynentu, a na końcu uzyskać nazwę kontynentu." ] }, { "cell_type": "code", "execution_count": 92, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Afghanistan Asia\n", "Albania Europe\n", "Algeria Africa\n", "Angola Africa\n", "Antigua and Barbuda North America\n", "Argentina South America\n", "Armenia Asia\n", "Australia Oceania\n", "Austria Europe\n", "Azerbaijan Asia\n", "Bahamas North America\n", "Bahrain Asia\n", "Bangladesh Asia\n", "Barbados North America\n", "Belarus Europe\n", "Belgium Europe\n", "Belize North America\n", "Benin Africa\n", "Bhutan Asia\n", "Bolivia South America\n", "Bosnia and Herzegovina Europe\n", "Botswana Africa\n", "Brazil South America\n", "Brunei Asia\n", "Bulgaria Europe\n", "Burkina Faso Africa\n", "Burundi Africa\n", "Cambodia Asia\n", "Cameroon Africa\n", "Canada North America\n", " ... \n", "Spain Europe\n", "Sri Lanka Asia\n", "Sudan Africa\n", "Suriname South America\n", "Swaziland Africa\n", "Sweden Europe\n", "Switzerland Europe\n", "Syria Asia\n", "Tajikistan Asia\n", "Tanzania Africa\n", "Thailand Asia\n", "Togo Africa\n", "Tonga Oceania\n", "Trinidad and Tobago North America\n", "Tunisia Africa\n", "Turkey Asia\n", "Turkmenistan Asia\n", "Uganda Africa\n", "Ukraine Europe\n", "United Arab Emirates Asia\n", "United Kingdom Europe\n", "United States North America\n", "Uruguay South America\n", "Uzbekistan Asia\n", "Vanuatu Oceania\n", "Venezuela South America\n", "Vietnam Asia\n", "Palestine Asia\n", "Zambia Africa\n", "Zimbabwe Africa\n", "Name: continent, Length: 175, dtype: object" ] }, "execution_count": 92, "metadata": {}, "output_type": "execute_result" } ], "source": [ "conts = []\n", "for name in data.index:\n", " country_code = pycountry_convert.convert_countries.country_name_to_country_alpha2(name)\n", " cont_code = pycountry_convert.convert_country_alpha2_to_continent_code.country_alpha2_to_continent_code(country_code)\n", " cont = pycountry_convert.convert_continent_code_to_continent_name(cont_code)\n", " conts.append(cont)\n", " \n", "data['continent'] = conts\n", "data['continent']" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**zad. 5**\n", "Oblicz ile osób mieszka na każdym z kontynentów." ] }, { "cell_type": "code", "execution_count": 103, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | female_BMI | \n", "male_BMI | \n", "gdp | \n", "population | \n", "under5mortality | \n", "life_expectancy | \n", "fertility | \n", "
---|---|---|---|---|---|---|---|
continent | \n", "\n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " |
Africa | \n", "1259.33213 | \n", "1181.44512 | \n", "280335.0 | \n", "9.772803e+08 | \n", "4763.00 | \n", "3136.10 | \n", "246.50 | \n", "
Asia | \n", "1114.28765 | \n", "1084.74598 | \n", "1038232.0 | \n", "3.949400e+09 | \n", "1302.98 | \n", "3201.41 | \n", "108.48 | \n", "
Europe | \n", "980.30978 | \n", "1009.60877 | \n", "1173410.0 | \n", "7.219954e+08 | \n", "273.60 | \n", "2929.30 | \n", "59.56 | \n", "
North America | \n", "526.06040 | \n", "497.74034 | \n", "338430.0 | \n", "5.235798e+08 | \n", "392.38 | \n", "1412.20 | \n", "45.00 | \n", "
Oceania | \n", "297.20093 | \n", "279.58957 | \n", "102803.0 | \n", "3.425711e+07 | \n", "310.00 | \n", "683.20 | \n", "34.02 | \n", "
South America | \n", "322.37322 | \n", "308.59791 | \n", "139888.0 | \n", "3.881582e+08 | \n", "288.70 | \n", "886.80 | \n", "30.10 | \n", "