{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "(assignment-3)=\n", "# Home assignment 3" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "tags": [ "remove-input" ] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Last updated: 2022-05-11 11:29:46\n" ] } ], "source": [ "!echo Last updated: `date +\"%Y-%m-%d %H:%M:%S\"`" ] }, { "cell_type": "code", "execution_count": null, "id": "9be78d54", "metadata": { "tags": [ "remove-input" ] }, "outputs": [], "source": [ "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "pd.options.display.max_rows = 10\n", "pd.options.display.max_columns = 10\n", "pd.options.display.max_colwidth = 35\n", "plt.rcParams[\"figure.figsize\"] = (6, 6)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "*****" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Question 1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "> * Read the `world_cities.csv` file into a `DataFrame` object.\n", "> * Calculate and print a new table, where each row represents a *country*, with the following columns:\n", "> * `\"country\"`—Country name\n", "> * `\"capital\"`—The name of the capital city\n", "> * `\"pop_total\"`—The total population (population in all cities summed)\n", "> * Note that for some countries there is more than one value marked as the capital! The resulting table still needs to have one row per country: capital name (`\"capital\"`) should be the *first* if there is more than one, while total population (`\"pop_total\"`) needs to be the sum of all cities (regardless of duplicates)." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "tags": [ "remove-input" ] }, "outputs": [ { "data": { "text/html": [ "
\n", " | country | \n", "capital | \n", "pop_total | \n", "
---|---|---|---|
0 | \n", "Afghanistan | \n", "Kabul | \n", "7543856 | \n", "
1 | \n", "Albania | \n", "Tirana | \n", "1536232 | \n", "
2 | \n", "Algeria | \n", "Algiers | \n", "20508642 | \n", "
3 | \n", "American Samoa | \n", "Pago Pago | \n", "58021 | \n", "
4 | \n", "Andorra | \n", "Andorra la Vella | \n", "69031 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "
223 | \n", "Wallis and Futuna | \n", "Mata'utu | \n", "11380 | \n", "
224 | \n", "Western Sahara | \n", "al-'Ayun | \n", "338786 | \n", "
225 | \n", "Yemen | \n", "San'a | \n", "5492077 | \n", "
226 | \n", "Zambia | \n", "Lusaka | \n", "4032170 | \n", "
227 | \n", "Zimbabwe | \n", "Harare | \n", "4231859 | \n", "
228 rows × 3 columns
\n", "