{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Project 1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A package is a group of Python modules that, when imported into your Python workspace allow for the use of various, helpful commands. Within each package are a series of libraries that each have a specific function relating to the main package. To install a package and library, you must first make sure the intended package is installed within the Python interpreter - found under Preferences in PyCharm. If it is not installed, a package can be easily found by typing in its name and adding it to the interpreter. Once the package is installed, you then have to import it into the workspace with a line of code. " ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This would import the pandas library into your workspace under an alias 'pd'. Using an alias can be helpful in keeping code short and easy to read." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "from datetime import datetime" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This would import the datetime function from the datetime library. This is helpful when you only need access to a certain function from within a library; rather than importing the entire library, you can import certain functions specifically. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A data frame is a structure that allows for the reading of data sets by organizing data entries into a table of columns and values. When working with dataframes, the pandas library is particularly helpful as it allows for the reading of the data in addition to data subsetting and manipulation. To read a file in its remote location in your file system, you would need to write a `read_()` command, specifying the library you are using and the path to the file. The pandas library has already been imported under an alias, so the code used would look something like this:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "path_to_data = 'gapminder.tsv'" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "data = pd.read_csv(path_to_data, sep = '\\t')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The dataset we're working this is tab-separated; however the pandas library will assume it is a comma-separated file. To get around this, within the `read_()` command, specify that you want data read as a csv file, `read_csv()`, while including that the data originally was tab-separated, `sep = '\\t'`. \n", "\n", "To return a description of the data, use the `describe()` command:" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
yearlifeExppopgdpPercap
count1704.000001704.0000001.704000e+031704.000000
mean1979.5000059.4744392.960121e+077215.327081
std17.2653312.9171071.061579e+089857.454543
min1952.0000023.5990006.001100e+04241.165877
25%1965.7500048.1980002.793664e+061202.060309
50%1979.5000060.7125007.023596e+063531.846989
75%1993.2500070.8455001.958522e+079325.462346
max2007.0000082.6030001.318683e+09113523.132900
\n", "
" ], "text/plain": [ " year lifeExp pop gdpPercap\n", "count 1704.00000 1704.000000 1.704000e+03 1704.000000\n", "mean 1979.50000 59.474439 2.960121e+07 7215.327081\n", "std 17.26533 12.917107 1.061579e+08 9857.454543\n", "min 1952.00000 23.599000 6.001100e+04 241.165877\n", "25% 1965.75000 48.198000 2.793664e+06 1202.060309\n", "50% 1979.50000 60.712500 7.023596e+06 3531.846989\n", "75% 1993.25000 70.845500 1.958522e+07 9325.462346\n", "max 2007.00000 82.603000 1.318683e+09 113523.132900" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data.describe()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To determine how many rows and columns are included in the dataset, use the .shape() command." ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1704" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data.shape[0]" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "6" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data.shape[1]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There are 1704 rows and 6 columns in this dataframe. To get a summary of the names of the columns, use `data.info()`, or `data.columns()` as a list:" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "RangeIndex: 1704 entries, 0 to 1703\n", "Data columns (total 6 columns):\n", "country 1704 non-null object\n", "continent 1704 non-null object\n", "year 1704 non-null int64\n", "lifeExp 1704 non-null float64\n", "pop 1704 non-null int64\n", "gdpPercap 1704 non-null float64\n", "dtypes: float64(2), int64(2), object(2)\n", "memory usage: 80.0+ KB\n" ] } ], "source": [ "data.info()" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['country', 'continent', 'year', 'lifeExp', 'pop', 'gdpPercap']" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "list(data.columns)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 3" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1952, 1957, 1962, 1967, 1972, 1977, 1982, 1987, 1992, 1997, 2002, 2007]" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data['year'].unique().tolist()" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "142" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(data[(data['year'] == data['year'].max())])" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "142" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(data[(data['year'] == 2002)])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Starting in 1952, the years come in five-year increments. To make it more current, data from 2012 and 2017 should be included, adding 142 records for each year to the data frame - 284 in total." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 4" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
countrycontinentyearlifeExppopgdpPercap
1292RwandaAfrica199223.5997290203737.068595
\n", "
" ], "text/plain": [ " country continent year lifeExp pop gdpPercap\n", "1292 Rwanda Africa 1992 23.599 7290203 737.068595" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data[(data['lifeExp'] == data['lifeExp'].min())]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "In this data frame, the lowest life expectancy occured in Rwanda in 1992, where life expectancy was about 23 years. This was around the time of the Rwanda genocide, when up to a million people were killed. This, in addition to the nation's poor public health at the time was likely the biggest factor in driving down average life expectancy. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 5" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "total_gdp = (data['pop'] * data['gdpPercap'])\n", "data['totalGDP'] = total_gdp.tolist()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "In 2007, total GDP for Germany, France, Italy, and Spain were as follows: " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "data_europe2007 = data[(data['continent']=='Europe') & (data['year'] == data['year'].max())]\n", "data_fgis2007 = data_europe2007[(data_europe2007['country']=='Spain') | (data_europe2007['country']=='France') | (data_europe2007['country']=='Germany') | (data_europe2007['country']=='Italy')]\n", "name_gdp = data_fgis2007[['country', 'totalGDP']]\n", "name_gdp.sort_values(by=['totalGDP'], ascending = False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In 2002, total GDP for Germany, France, Italy, and Spain were as follows: " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "data_europe2002 = data[(data['continent']=='Europe') & (data['year'] == 2002)]\n", "data_fgis2002 = data_europe2002[(data_europe2002['country']=='Spain') | (data_europe2002['country']=='France') | (data_europe2002['country']=='Germany') | (data_europe2002['country']=='Italy')]\n", "name_gdp = data_fgis2002[['country', 'totalGDP']]\n", "name_gdp.sort_values(by=['totalGDP'], ascending=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "Spain experienced the greatest increase in total GDP between 2002 and 2007, increasing from .97 trillion USD to 1.16 trillion USD." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 6" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The '&' symbol is used to represent 'and' and would be used in cases where you are looking for data that has both of the given criteria. The '==' symbol is used for checking if a variable is equal to a certain value in conditional statements. Using a single equal sign would only be appropriate when assigning values to a variable name. The following code would return values where country is equal to Europe and the year is equal to 2007." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
countrycontinentyearlifeExppopgdpPercap
23AlbaniaEurope200776.42336005235937.029526
83AustriaEurope200779.829819978336126.492700
119BelgiumEurope200779.4411039222633692.605080
155Bosnia and HerzegovinaEurope200774.85245521987446.298803
191BulgariaEurope200773.005732285810680.792820
383CroatiaEurope200775.748449331214619.222720
407Czech RepublicEurope200776.4861022874422833.308510
419DenmarkEurope200778.332546812035278.418740
527FinlandEurope200779.313523846033207.084400
539FranceEurope200780.6576108391630470.016700
575GermanyEurope200779.4068240099632170.374420
599GreeceEurope200779.4831070629027538.411880
683HungaryEurope200773.338995610818008.944440
695IcelandEurope200781.75730193136180.789190
755IrelandEurope200778.885410908640675.996350
779ItalyEurope200780.5465814773328569.719700
1019MontenegroEurope200774.5436847369253.896111
1091NetherlandsEurope200779.7621657061336797.933320
1151NorwayEurope200780.196462792649357.190170
1235PolandEurope200775.5633851824115389.924680
1247PortugalEurope200778.0981064283620509.647770
1283RomaniaEurope200772.4762227605610808.475610
1343SerbiaEurope200774.002101502659786.534714
1379Slovak RepublicEurope200774.663544750218678.314350
1391SloveniaEurope200777.926200924525768.257590
1427SpainEurope200780.9414044819128821.063700
1475SwedenEurope200780.884903108833859.748350
1487SwitzerlandEurope200781.701755466137506.419070
1583TurkeyEurope200771.777711586478458.276384
1607United KingdomEurope200779.4256077623833203.261280
\n", "
" ], "text/plain": [ " country continent year lifeExp pop gdpPercap\n", "23 Albania Europe 2007 76.423 3600523 5937.029526\n", "83 Austria Europe 2007 79.829 8199783 36126.492700\n", "119 Belgium Europe 2007 79.441 10392226 33692.605080\n", "155 Bosnia and Herzegovina Europe 2007 74.852 4552198 7446.298803\n", "191 Bulgaria Europe 2007 73.005 7322858 10680.792820\n", "383 Croatia Europe 2007 75.748 4493312 14619.222720\n", "407 Czech Republic Europe 2007 76.486 10228744 22833.308510\n", "419 Denmark Europe 2007 78.332 5468120 35278.418740\n", "527 Finland Europe 2007 79.313 5238460 33207.084400\n", "539 France Europe 2007 80.657 61083916 30470.016700\n", "575 Germany Europe 2007 79.406 82400996 32170.374420\n", "599 Greece Europe 2007 79.483 10706290 27538.411880\n", "683 Hungary Europe 2007 73.338 9956108 18008.944440\n", "695 Iceland Europe 2007 81.757 301931 36180.789190\n", "755 Ireland Europe 2007 78.885 4109086 40675.996350\n", "779 Italy Europe 2007 80.546 58147733 28569.719700\n", "1019 Montenegro Europe 2007 74.543 684736 9253.896111\n", "1091 Netherlands Europe 2007 79.762 16570613 36797.933320\n", "1151 Norway Europe 2007 80.196 4627926 49357.190170\n", "1235 Poland Europe 2007 75.563 38518241 15389.924680\n", "1247 Portugal Europe 2007 78.098 10642836 20509.647770\n", "1283 Romania Europe 2007 72.476 22276056 10808.475610\n", "1343 Serbia Europe 2007 74.002 10150265 9786.534714\n", "1379 Slovak Republic Europe 2007 74.663 5447502 18678.314350\n", "1391 Slovenia Europe 2007 77.926 2009245 25768.257590\n", "1427 Spain Europe 2007 80.941 40448191 28821.063700\n", "1475 Sweden Europe 2007 80.884 9031088 33859.748350\n", "1487 Switzerland Europe 2007 81.701 7554661 37506.419070\n", "1583 Turkey Europe 2007 71.777 71158647 8458.276384\n", "1607 United Kingdom Europe 2007 79.425 60776238 33203.261280" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data_europe2007 = data[(data['continent']=='Europe') & (data['year'] == data['year'].max())]\n", "data_europe2007" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "The '|' symbol is used to represent 'or' and would return True as long as at least one of the given arguments is True. The following code will return True even though 3 is not greater than 4, because it is only asking if one of the given arguements is correct." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(1+2 == 3) | (3 > 4)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The '^' symbol is used to represent an exclusive or. It will return True if one argument is True and the other False, but will return False if both are True or both are False. The following will return False as both are False." ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "('cat' == 'dog') ^ (2 > 1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 7" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The .loc command is a location command used to extract a row of data when given its index label as a parameter. The .iloc works similarly but returns a row by it's integer position in the dataset rather than its index label. The following code will return all rows of data between the integer positions 1691 and 1702, not including entry 1702." ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
countrycontinentyearlifeExppopgdpPercap
1691ZambiaAfrica200742.384117460351271.211593
1692ZimbabweAfrica195248.4513080907406.884115
1693ZimbabweAfrica195750.4693646340518.764268
1694ZimbabweAfrica196252.3584277736527.272182
1695ZimbabweAfrica196753.9954995432569.795071
1696ZimbabweAfrica197255.6355861135799.362176
1697ZimbabweAfrica197757.6746642107685.587682
1698ZimbabweAfrica198260.3637636524788.855041
1699ZimbabweAfrica198762.3519216418706.157306
1700ZimbabweAfrica199260.37710704340693.420786
1701ZimbabweAfrica199746.80911404948792.449960
\n", "
" ], "text/plain": [ " country continent year lifeExp pop gdpPercap\n", "1691 Zambia Africa 2007 42.384 11746035 1271.211593\n", "1692 Zimbabwe Africa 1952 48.451 3080907 406.884115\n", "1693 Zimbabwe Africa 1957 50.469 3646340 518.764268\n", "1694 Zimbabwe Africa 1962 52.358 4277736 527.272182\n", "1695 Zimbabwe Africa 1967 53.995 4995432 569.795071\n", "1696 Zimbabwe Africa 1972 55.635 5861135 799.362176\n", "1697 Zimbabwe Africa 1977 57.674 6642107 685.587682\n", "1698 Zimbabwe Africa 1982 60.363 7636524 788.855041\n", "1699 Zimbabwe Africa 1987 62.351 9216418 706.157306\n", "1700 Zimbabwe Africa 1992 60.377 10704340 693.420786\n", "1701 Zimbabwe Africa 1997 46.809 11404948 792.449960" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data.iloc[1691:1702]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The following code will return all observations from the second, third, and fourth columns. " ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
continentyearlifeExp
0Asia195228.801
1Asia195730.332
2Asia196231.997
3Asia196734.020
4Asia197236.088
5Asia197738.438
6Asia198239.854
7Asia198740.822
8Asia199241.674
9Asia199741.763
10Asia200242.129
11Asia200743.828
12Europe195255.230
13Europe195759.280
14Europe196264.820
15Europe196766.220
16Europe197267.690
17Europe197768.930
18Europe198270.420
19Europe198772.000
20Europe199271.581
21Europe199772.950
22Europe200275.651
23Europe200776.423
24Africa195243.077
25Africa195745.685
26Africa196248.303
27Africa196751.407
28Africa197254.518
29Africa197758.014
............
1674Asia198249.113
1675Asia198752.922
1676Asia199255.599
1677Asia199758.020
1678Asia200260.308
1679Asia200762.698
1680Africa195242.038
1681Africa195744.077
1682Africa196246.023
1683Africa196747.768
1684Africa197250.107
1685Africa197751.386
1686Africa198251.821
1687Africa198750.821
1688Africa199246.100
1689Africa199740.238
1690Africa200239.193
1691Africa200742.384
1692Africa195248.451
1693Africa195750.469
1694Africa196252.358
1695Africa196753.995
1696Africa197255.635
1697Africa197757.674
1698Africa198260.363
1699Africa198762.351
1700Africa199260.377
1701Africa199746.809
1702Africa200239.989
1703Africa200743.487
\n", "

1704 rows × 3 columns

\n", "
" ], "text/plain": [ " continent year lifeExp\n", "0 Asia 1952 28.801\n", "1 Asia 1957 30.332\n", "2 Asia 1962 31.997\n", "3 Asia 1967 34.020\n", "4 Asia 1972 36.088\n", "5 Asia 1977 38.438\n", "6 Asia 1982 39.854\n", "7 Asia 1987 40.822\n", "8 Asia 1992 41.674\n", "9 Asia 1997 41.763\n", "10 Asia 2002 42.129\n", "11 Asia 2007 43.828\n", "12 Europe 1952 55.230\n", "13 Europe 1957 59.280\n", "14 Europe 1962 64.820\n", "15 Europe 1967 66.220\n", "16 Europe 1972 67.690\n", "17 Europe 1977 68.930\n", "18 Europe 1982 70.420\n", "19 Europe 1987 72.000\n", "20 Europe 1992 71.581\n", "21 Europe 1997 72.950\n", "22 Europe 2002 75.651\n", "23 Europe 2007 76.423\n", "24 Africa 1952 43.077\n", "25 Africa 1957 45.685\n", "26 Africa 1962 48.303\n", "27 Africa 1967 51.407\n", "28 Africa 1972 54.518\n", "29 Africa 1977 58.014\n", "... ... ... ...\n", "1674 Asia 1982 49.113\n", "1675 Asia 1987 52.922\n", "1676 Asia 1992 55.599\n", "1677 Asia 1997 58.020\n", "1678 Asia 2002 60.308\n", "1679 Asia 2007 62.698\n", "1680 Africa 1952 42.038\n", "1681 Africa 1957 44.077\n", "1682 Africa 1962 46.023\n", "1683 Africa 1967 47.768\n", "1684 Africa 1972 50.107\n", "1685 Africa 1977 51.386\n", "1686 Africa 1982 51.821\n", "1687 Africa 1987 50.821\n", "1688 Africa 1992 46.100\n", "1689 Africa 1997 40.238\n", "1690 Africa 2002 39.193\n", "1691 Africa 2007 42.384\n", "1692 Africa 1952 48.451\n", "1693 Africa 1957 50.469\n", "1694 Africa 1962 52.358\n", "1695 Africa 1967 53.995\n", "1696 Africa 1972 55.635\n", "1697 Africa 1977 57.674\n", "1698 Africa 1982 60.363\n", "1699 Africa 1987 62.351\n", "1700 Africa 1992 60.377\n", "1701 Africa 1997 46.809\n", "1702 Africa 2002 39.989\n", "1703 Africa 2007 43.487\n", "\n", "[1704 rows x 3 columns]" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data.iloc[:, 1:4]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 8" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "An ai is an Application Programming Interface, and it a part of a website's remote server that receives and processes requests. It allows different applications to work together.\n", "\n", "To pull data from a remote server, you first have to send a request using the requests library." ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "import requests" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You then must specify where the data is coming from in a url. " ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "url = \"https://api.covidtracking.com/v1/states/daily.csv\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Then you can write it to a local file in a folder on your server using the os library." ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "import os\n", "\n", "data_folder = 'data'\n", "if not os.path.exists(data_folder):\n", " os.makedirs(data_folder)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "After setting a filename for your data, you can retrieve the data from the request and populate your new file." ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "from datetime import datetime as dt\n", "import pytz\n", " \n", "file_name_short = 'ctp_' + str(dt.now(tz = pytz.utc)).replace(' ', '_') + '.csv'\n", "file_name = os.path.join(data_folder, file_name_short)\n", "\n", "r = requests.get(url)\n", "\n", "with open(file_name, 'wb') as f:\n", " f.write(r.content)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Once your file is written, you cna import it into your workspace using pandas." ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "df = pd.read_csv(file_name)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 9\n", "\n", "The apply() function from the pandas library allows for the user to take any function and apply it to all values in the given series. For example, the apply() function could be used to sum all values for a particular column. Using apply() could be an alternative to writing out an actual function and then having to execute it across all series objects, which could lower output speed and efficiency, while taking up more space and increasing the chance of making a mistake. \n", "\n", "## 10 \n", "\n", "\n", "Instead of using .iloc to filter columns, you could just make a new subset of your data frame. The following two lines of code return the same output; however, using the first option is potentially easier and allows both consecutive and non-consecutive columns to be extracted by name. " ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
countrycontinentyearlifeExp
0AfghanistanAsia195228.801
1AfghanistanAsia195730.332
2AfghanistanAsia196231.997
3AfghanistanAsia196734.020
4AfghanistanAsia197236.088
5AfghanistanAsia197738.438
6AfghanistanAsia198239.854
7AfghanistanAsia198740.822
8AfghanistanAsia199241.674
9AfghanistanAsia199741.763
10AfghanistanAsia200242.129
11AfghanistanAsia200743.828
12AlbaniaEurope195255.230
13AlbaniaEurope195759.280
14AlbaniaEurope196264.820
15AlbaniaEurope196766.220
16AlbaniaEurope197267.690
17AlbaniaEurope197768.930
18AlbaniaEurope198270.420
19AlbaniaEurope198772.000
20AlbaniaEurope199271.581
21AlbaniaEurope199772.950
22AlbaniaEurope200275.651
23AlbaniaEurope200776.423
24AlgeriaAfrica195243.077
25AlgeriaAfrica195745.685
26AlgeriaAfrica196248.303
27AlgeriaAfrica196751.407
28AlgeriaAfrica197254.518
29AlgeriaAfrica197758.014
...............
1674Yemen, Rep.Asia198249.113
1675Yemen, Rep.Asia198752.922
1676Yemen, Rep.Asia199255.599
1677Yemen, Rep.Asia199758.020
1678Yemen, Rep.Asia200260.308
1679Yemen, Rep.Asia200762.698
1680ZambiaAfrica195242.038
1681ZambiaAfrica195744.077
1682ZambiaAfrica196246.023
1683ZambiaAfrica196747.768
1684ZambiaAfrica197250.107
1685ZambiaAfrica197751.386
1686ZambiaAfrica198251.821
1687ZambiaAfrica198750.821
1688ZambiaAfrica199246.100
1689ZambiaAfrica199740.238
1690ZambiaAfrica200239.193
1691ZambiaAfrica200742.384
1692ZimbabweAfrica195248.451
1693ZimbabweAfrica195750.469
1694ZimbabweAfrica196252.358
1695ZimbabweAfrica196753.995
1696ZimbabweAfrica197255.635
1697ZimbabweAfrica197757.674
1698ZimbabweAfrica198260.363
1699ZimbabweAfrica198762.351
1700ZimbabweAfrica199260.377
1701ZimbabweAfrica199746.809
1702ZimbabweAfrica200239.989
1703ZimbabweAfrica200743.487
\n", "

1704 rows × 4 columns

\n", "
" ], "text/plain": [ " country continent year lifeExp\n", "0 Afghanistan Asia 1952 28.801\n", "1 Afghanistan Asia 1957 30.332\n", "2 Afghanistan Asia 1962 31.997\n", "3 Afghanistan Asia 1967 34.020\n", "4 Afghanistan Asia 1972 36.088\n", "5 Afghanistan Asia 1977 38.438\n", "6 Afghanistan Asia 1982 39.854\n", "7 Afghanistan Asia 1987 40.822\n", "8 Afghanistan Asia 1992 41.674\n", "9 Afghanistan Asia 1997 41.763\n", "10 Afghanistan Asia 2002 42.129\n", "11 Afghanistan Asia 2007 43.828\n", "12 Albania Europe 1952 55.230\n", "13 Albania Europe 1957 59.280\n", "14 Albania Europe 1962 64.820\n", "15 Albania Europe 1967 66.220\n", "16 Albania Europe 1972 67.690\n", "17 Albania Europe 1977 68.930\n", "18 Albania Europe 1982 70.420\n", "19 Albania Europe 1987 72.000\n", "20 Albania Europe 1992 71.581\n", "21 Albania Europe 1997 72.950\n", "22 Albania Europe 2002 75.651\n", "23 Albania Europe 2007 76.423\n", "24 Algeria Africa 1952 43.077\n", "25 Algeria Africa 1957 45.685\n", "26 Algeria Africa 1962 48.303\n", "27 Algeria Africa 1967 51.407\n", "28 Algeria Africa 1972 54.518\n", "29 Algeria Africa 1977 58.014\n", "... ... ... ... ...\n", "1674 Yemen, Rep. Asia 1982 49.113\n", "1675 Yemen, Rep. Asia 1987 52.922\n", "1676 Yemen, Rep. Asia 1992 55.599\n", "1677 Yemen, Rep. Asia 1997 58.020\n", "1678 Yemen, Rep. Asia 2002 60.308\n", "1679 Yemen, Rep. Asia 2007 62.698\n", "1680 Zambia Africa 1952 42.038\n", "1681 Zambia Africa 1957 44.077\n", "1682 Zambia Africa 1962 46.023\n", "1683 Zambia Africa 1967 47.768\n", "1684 Zambia Africa 1972 50.107\n", "1685 Zambia Africa 1977 51.386\n", "1686 Zambia Africa 1982 51.821\n", "1687 Zambia Africa 1987 50.821\n", "1688 Zambia Africa 1992 46.100\n", "1689 Zambia Africa 1997 40.238\n", "1690 Zambia Africa 2002 39.193\n", "1691 Zambia Africa 2007 42.384\n", "1692 Zimbabwe Africa 1952 48.451\n", "1693 Zimbabwe Africa 1957 50.469\n", "1694 Zimbabwe Africa 1962 52.358\n", "1695 Zimbabwe Africa 1967 53.995\n", "1696 Zimbabwe Africa 1972 55.635\n", "1697 Zimbabwe Africa 1977 57.674\n", "1698 Zimbabwe Africa 1982 60.363\n", "1699 Zimbabwe Africa 1987 62.351\n", "1700 Zimbabwe Africa 1992 60.377\n", "1701 Zimbabwe Africa 1997 46.809\n", "1702 Zimbabwe Africa 2002 39.989\n", "1703 Zimbabwe Africa 2007 43.487\n", "\n", "[1704 rows x 4 columns]" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data[[\"country\", \"continent\", \"year\", \"lifeExp\"]]" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
countrycontinentyearlifeExp
0AfghanistanAsia195228.801
1AfghanistanAsia195730.332
2AfghanistanAsia196231.997
3AfghanistanAsia196734.020
4AfghanistanAsia197236.088
5AfghanistanAsia197738.438
6AfghanistanAsia198239.854
7AfghanistanAsia198740.822
8AfghanistanAsia199241.674
9AfghanistanAsia199741.763
10AfghanistanAsia200242.129
11AfghanistanAsia200743.828
12AlbaniaEurope195255.230
13AlbaniaEurope195759.280
14AlbaniaEurope196264.820
15AlbaniaEurope196766.220
16AlbaniaEurope197267.690
17AlbaniaEurope197768.930
18AlbaniaEurope198270.420
19AlbaniaEurope198772.000
20AlbaniaEurope199271.581
21AlbaniaEurope199772.950
22AlbaniaEurope200275.651
23AlbaniaEurope200776.423
24AlgeriaAfrica195243.077
25AlgeriaAfrica195745.685
26AlgeriaAfrica196248.303
27AlgeriaAfrica196751.407
28AlgeriaAfrica197254.518
29AlgeriaAfrica197758.014
...............
1674Yemen, Rep.Asia198249.113
1675Yemen, Rep.Asia198752.922
1676Yemen, Rep.Asia199255.599
1677Yemen, Rep.Asia199758.020
1678Yemen, Rep.Asia200260.308
1679Yemen, Rep.Asia200762.698
1680ZambiaAfrica195242.038
1681ZambiaAfrica195744.077
1682ZambiaAfrica196246.023
1683ZambiaAfrica196747.768
1684ZambiaAfrica197250.107
1685ZambiaAfrica197751.386
1686ZambiaAfrica198251.821
1687ZambiaAfrica198750.821
1688ZambiaAfrica199246.100
1689ZambiaAfrica199740.238
1690ZambiaAfrica200239.193
1691ZambiaAfrica200742.384
1692ZimbabweAfrica195248.451
1693ZimbabweAfrica195750.469
1694ZimbabweAfrica196252.358
1695ZimbabweAfrica196753.995
1696ZimbabweAfrica197255.635
1697ZimbabweAfrica197757.674
1698ZimbabweAfrica198260.363
1699ZimbabweAfrica198762.351
1700ZimbabweAfrica199260.377
1701ZimbabweAfrica199746.809
1702ZimbabweAfrica200239.989
1703ZimbabweAfrica200743.487
\n", "

1704 rows × 4 columns

\n", "
" ], "text/plain": [ " country continent year lifeExp\n", "0 Afghanistan Asia 1952 28.801\n", "1 Afghanistan Asia 1957 30.332\n", "2 Afghanistan Asia 1962 31.997\n", "3 Afghanistan Asia 1967 34.020\n", "4 Afghanistan Asia 1972 36.088\n", "5 Afghanistan Asia 1977 38.438\n", "6 Afghanistan Asia 1982 39.854\n", "7 Afghanistan Asia 1987 40.822\n", "8 Afghanistan Asia 1992 41.674\n", "9 Afghanistan Asia 1997 41.763\n", "10 Afghanistan Asia 2002 42.129\n", "11 Afghanistan Asia 2007 43.828\n", "12 Albania Europe 1952 55.230\n", "13 Albania Europe 1957 59.280\n", "14 Albania Europe 1962 64.820\n", "15 Albania Europe 1967 66.220\n", "16 Albania Europe 1972 67.690\n", "17 Albania Europe 1977 68.930\n", "18 Albania Europe 1982 70.420\n", "19 Albania Europe 1987 72.000\n", "20 Albania Europe 1992 71.581\n", "21 Albania Europe 1997 72.950\n", "22 Albania Europe 2002 75.651\n", "23 Albania Europe 2007 76.423\n", "24 Algeria Africa 1952 43.077\n", "25 Algeria Africa 1957 45.685\n", "26 Algeria Africa 1962 48.303\n", "27 Algeria Africa 1967 51.407\n", "28 Algeria Africa 1972 54.518\n", "29 Algeria Africa 1977 58.014\n", "... ... ... ... ...\n", "1674 Yemen, Rep. Asia 1982 49.113\n", "1675 Yemen, Rep. Asia 1987 52.922\n", "1676 Yemen, Rep. Asia 1992 55.599\n", "1677 Yemen, Rep. Asia 1997 58.020\n", "1678 Yemen, Rep. Asia 2002 60.308\n", "1679 Yemen, Rep. Asia 2007 62.698\n", "1680 Zambia Africa 1952 42.038\n", "1681 Zambia Africa 1957 44.077\n", "1682 Zambia Africa 1962 46.023\n", "1683 Zambia Africa 1967 47.768\n", "1684 Zambia Africa 1972 50.107\n", "1685 Zambia Africa 1977 51.386\n", "1686 Zambia Africa 1982 51.821\n", "1687 Zambia Africa 1987 50.821\n", "1688 Zambia Africa 1992 46.100\n", "1689 Zambia Africa 1997 40.238\n", "1690 Zambia Africa 2002 39.193\n", "1691 Zambia Africa 2007 42.384\n", "1692 Zimbabwe Africa 1952 48.451\n", "1693 Zimbabwe Africa 1957 50.469\n", "1694 Zimbabwe Africa 1962 52.358\n", "1695 Zimbabwe Africa 1967 53.995\n", "1696 Zimbabwe Africa 1972 55.635\n", "1697 Zimbabwe Africa 1977 57.674\n", "1698 Zimbabwe Africa 1982 60.363\n", "1699 Zimbabwe Africa 1987 62.351\n", "1700 Zimbabwe Africa 1992 60.377\n", "1701 Zimbabwe Africa 1997 46.809\n", "1702 Zimbabwe Africa 2002 39.989\n", "1703 Zimbabwe Africa 2007 43.487\n", "\n", "[1704 rows x 4 columns]" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data.iloc[:, 0:4]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.5" } }, "nbformat": 4, "nbformat_minor": 2 }