{ "cells": [ { "cell_type": "markdown", "id": "7aaf9f6f", "metadata": {}, "source": [ "# More Pandas\n", "\n", "## Create a new column\n", "Similar to NumPy, Pandas supports vectorised operations. This means, that we do not need to create loops to \n", "perform basic element-wise operations. In the example below, we create a new column `population_p`, that takes the values \n", "of column `population_t` and divides them by the values of column `land_area`." ] }, { "cell_type": "code", "execution_count": 1, "id": "a09b3478", "metadata": { "tags": [ "output_scroll" ] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(3038, 11)\n", "(3038, 12)\n" ] }, { "data": { "text/html": [ "
\n", " | country | \n", "year | \n", "population_m | \n", "population_f | \n", "population_t | \n", "population_density | \n", "land_area | \n", "life_expectancy_f | \n", "life_expectancy_m | \n", "life_expectancy_t | \n", "co2_emissions_pc | \n", "population_d | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "Afghanistan | \n", "2000 | \n", "10689508.0 | \n", "10090449.0 | \n", "20779957.0 | \n", "31.859861 | \n", "652230.0 | \n", "57.120 | \n", "54.663 | \n", "55.841 | \n", "0.036574 | \n", "31.859861 | \n", "
1 | \n", "Afghanistan | \n", "2001 | \n", "11117754.0 | \n", "10489238.0 | \n", "21606992.0 | \n", "33.127872 | \n", "652230.0 | \n", "57.596 | \n", "55.119 | \n", "56.308 | \n", "0.033785 | \n", "33.127872 | \n", "
2 | \n", "Afghanistan | \n", "2002 | \n", "11642106.0 | \n", "10958668.0 | \n", "22600774.0 | \n", "34.651540 | \n", "652230.0 | \n", "58.080 | \n", "55.583 | \n", "56.784 | \n", "0.045574 | \n", "34.651540 | \n", "
3 | \n", "Afghanistan | \n", "2003 | \n", "12214634.0 | \n", "11466237.0 | \n", "23680871.0 | \n", "36.307546 | \n", "652230.0 | \n", "58.578 | \n", "56.056 | \n", "57.271 | \n", "0.051518 | \n", "36.307546 | \n", "
4 | \n", "Afghanistan | \n", "2004 | \n", "12763726.0 | \n", "11962963.0 | \n", "24726689.0 | \n", "37.910996 | \n", "652230.0 | \n", "59.093 | \n", "56.542 | \n", "57.772 | \n", "0.041655 | \n", "37.910996 | \n", "