In [2]:
import pandas as pd

table1columns = [  "country-year",       "type",   "count"]
table1data =[ ["Afghanistan-1999",      "cases",       745],
              ["Afghanistan-1999", "population",  19987071],
              ["Afghanistan-2000",      "cases",      2666],
              ["Afghanistan-2000", "population",  20595360],
              [     "Brazil-1999",      "cases",     37737],
              [     "Brazil-1999", "population", 172006362],
              [     "Brazil-2000",      "cases",     80488],
              [     "Brazil-2000", "population", 174504898],
              [      "China-1999",      "cases",    212258],
              [      "China-1999", "population",1272915272],
              [      "China-2000",      "cases",    213766],
              [      "China-2000", "population",1280428583] ]
table1 = pd.DataFrame(table1data, columns=table1columns)
table1
Out[2]:
country-year type count
0 Afghanistan-1999 cases 745
1 Afghanistan-1999 population 19987071
2 Afghanistan-2000 cases 2666
3 Afghanistan-2000 population 20595360
4 Brazil-1999 cases 37737
5 Brazil-1999 population 172006362
6 Brazil-2000 cases 80488
7 Brazil-2000 population 174504898
8 China-1999 cases 212258
9 China-1999 population 1272915272
10 China-2000 cases 213766
11 China-2000 population 1280428583
In [3]:
table1columns = ["country",  "year",       "type",     "count"]
table1data =[ ["Afghanistan",  1999,      "cases",       745],
              ["Afghanistan",  1999, "population",  19987071],
              ["Afghanistan",  2000,      "cases",      2666],
              ["Afghanistan",  2000, "population",  20595360],
              [     "Brazil",  1999,      "cases",     37737],
              [     "Brazil",  1999, "population", 172006362],
              [     "Brazil",  2000,      "cases",     80488],
              [     "Brazil",  2000, "population", 174504898],
              [      "China",  1999,      "cases",    212258],
              [      "China",  1999, "population",1272915272],
              [      "China",  2000,      "cases",    213766],
              [      "China",  2000, "population",1280428583] ]

table1 = pd.DataFrame(table1data, columns=table1columns)
table1
Out[3]:
country year type count
0 Afghanistan 1999 cases 745
1 Afghanistan 1999 population 19987071
2 Afghanistan 2000 cases 2666
3 Afghanistan 2000 population 20595360
4 Brazil 1999 cases 37737
5 Brazil 1999 population 172006362
6 Brazil 2000 cases 80488
7 Brazil 2000 population 174504898
8 China 1999 cases 212258
9 China 1999 population 1272915272
10 China 2000 cases 213766
11 China 2000 population 1280428583
In [4]:
casescolumns = ["country", "1999", "2000"]
casesdata = [ ["Afghanistan",    745,   2666],
                [     "Brazil",  37737,  80488],
                [      "China", 212258, 213766] ]

cases = pd.DataFrame(casesdata, columns=casescolumns)
cases
Out[4]:
country 1999 2000
0 Afghanistan 745 2666
1 Brazil 37737 80488
2 China 212258 213766
In [5]:
popcolumns = ["country", "1999", "2000"]
popdata = [ ["Afghanistan",   19987071,   20595360],
                [      "China", 1272915272, 1280428583],
                [     "Brazil",  172006362,  174504898]]
population = pd.DataFrame(popdata, columns=popcolumns)
population
Out[5]:
country 1999 2000
0 Afghanistan 19987071 20595360
1 China 1272915272 1280428583
2 Brazil 172006362 174504898
In [8]:
table3acolumns = ["country", "year", "cases"]
table3adata = [ ["Afghanistan",  1999,    745],
                ["Afghanistan",  2000,   2666],
                [     "Brazil",  1999,  37737],
                [     "Brazil",  2000,  80488],
                [      "China",  1999, 212258],
                [      "China",  2000, 213766] ]

table3bcolumns = ["country", "year", "population"]
table3bdata =[ ["Afghanistan",  1999,   19987071],
               ["Afghanistan",  2000,   20595360],
               [     "Brazil",  1999,  172006362],
               [     "Brazil",  2000,  174504898],
               [      "China",  1999, 1272915272],
               [      "China",  2000, 1280428583] ]
cases = pd.DataFrame(table3adata, columns=table3acolumns)
population = pd.DataFrame(table3bdata, columns=table3bcolumns)
In [9]:
cases
Out[9]:
country year cases
0 Afghanistan 1999 745
1 Afghanistan 2000 2666
2 Brazil 1999 37737
3 Brazil 2000 80488
4 China 1999 212258
5 China 2000 213766
In [10]:
population
Out[10]:
country year population
0 Afghanistan 1999 19987071
1 Afghanistan 2000 20595360
2 Brazil 1999 172006362
3 Brazil 2000 174504898
4 China 1999 1272915272
5 China 2000 1280428583
In [11]:
topnamesDoL = {'year': [2018, 2018, 2017, 2017, 2016, 2016],
               'sex': ['Male', 'Female', 'Male',
                       'Female', 'Male', 'Female'],
               'name': ['Liam', 'Emma', 'Liam', 'Emma',
                        'Noah', 'Emma'],
               'count': [19837, 18688, 18798, 19800, 
                        19117, 19496]}
In [ ]:
 
In [12]:
indicatorDoL = {
 'country': ['Canada', 'China', 'India', 
              'Russia', 'United States', 'Vietnam'],
 'pop': [36.26, 1378.66, 1324.17, 144.34, 323.13, 94.59],
 'gdp': [1535.77, 11199.15, 2263.79, 1283.16, 18624.47, 205.28],
 'life': [82.30, 76.25, 68.56, 71.59, 78.69, 76.25],
 'cell': [30.75, 1364.93, 1127.81, 229.13, 395.88, 120.60]}

codes = pd.Index(['CAN', 'CHN', 'IND', 'RUS', 'USA', 'VNM'],
                 name='code')
In [ ]:
 
In [ ]:
# Use read_csv()

Whole Dataframe Operations:

Methods

  • head()
  • tail()
  • info()
  • astype({})

Functions

  • len()

Attributes

  • .shape
  • .columns
  • .index
In [ ]: