Human Interactions#

IN THE SPACE BELOW, WRITE OUT IN FULL AND THEN SIGN THE HONOR PLEDGE:

“I pledge my honor that I have not violated the honor code during this examination.”

PRINT NAME:

If a fellow student has contributed significantly to this work, please acknowledge them here:

Peer(s):

Contribution:

By uploading this assignment through Canvas, I sign off on the document below electronically.


Part I: A modified ranking of costly disasters#

The following table list some recent natural disasters, and the estimated economic losses in the affected country. The economic losses are often hard to estimate, so these are approximate values.

Year

Event

Country

Economic loss

2010

Port-au-Prince Earthquake

Haiti

$3 billion

2014

Laudian Earthquake

China

$10 billion

2005

Hurricane Katrina

USA

$150 billion

2011

M9.1 Earthquake

Japan

$200 billion

2012

Hurricane Sandy

USA

$150 billion

1998

Hurricane Mitch

Honduras

$4 billion

We will rank the severity of the disasters based on the economic losses compared with the national wealth, estimated as their gross domestic products (GDPs, Wikipedia). Here is an example on how to read a .csv file and access the data using a pandas Dataframe.

# import these packages when you read .csv file
import pandas as pd

# this one is only for making interactive plots. You do not need to import this.
import plotly.express as px
# Read a the GDP data file
data = pd.read_csv('Files/GDP_Data.csv')

# Display the content of the dataframe.
# Useful to see the column names. Pay attention to the unit of GDP.
# alternatively, you can open the .csv file
data
Country Name Country Code Indicator Name Indicator Code 1960 1961 1962 1963 1964 1965 ... 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021
0 Tuvalu TUV GDP (current US$) NY.GDP.MKTP.CD NaN NaN NaN NaN NaN NaN ... 3.934562e+07 3.861749e+07 3.875969e+07 3.681166e+07 4.162950e+07 4.521766e+07 4.781829e+07 5.422315e+07 5.505471e+07 6.310096e+07
1 Nauru NRU GDP (current US$) NY.GDP.MKTP.CD NaN NaN NaN NaN NaN NaN ... 9.692720e+07 9.849184e+07 1.046544e+08 8.652966e+07 9.972339e+07 1.093597e+08 1.240214e+08 1.187241e+08 1.146266e+08 1.332189e+08
2 Kiribati KIR GDP (current US$) NY.GDP.MKTP.CD NaN NaN NaN NaN NaN NaN ... 1.896301e+08 1.845507e+08 1.778623e+08 1.702910e+08 1.785098e+08 1.881921e+08 1.962306e+08 1.779353e+08 1.809118e+08 NaN
3 Marshall Islands MHL GDP (current US$) NY.GDP.MKTP.CD NaN NaN NaN NaN NaN NaN ... 1.804363e+08 1.848404e+08 1.821428e+08 1.838143e+08 2.015109e+08 2.132041e+08 2.215889e+08 2.394622e+08 2.444624e+08 2.486656e+08
4 Palau PLW GDP (current US$) NY.GDP.MKTP.CD NaN NaN NaN NaN NaN NaN ... 2.123978e+08 2.211172e+08 2.416698e+08 2.804577e+08 2.983000e+08 2.853000e+08 2.847000e+08 2.742000e+08 2.577000e+08 NaN
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
261 Sint Maarten (Dutch part) SXM GDP (current US$) NY.GDP.MKTP.CD NaN NaN NaN NaN NaN NaN ... 9.858659e+08 1.022905e+09 1.245251e+09 1.253073e+09 1.263687e+09 1.191620e+09 1.185475e+09 NaN NaN NaN
262 Syrian Arab Republic SYR GDP (current US$) NY.GDP.MKTP.CD 8.577044e+08 9.452450e+08 1.110566e+09 1.200447e+09 1.339494e+09 1.329842e+09 ... 4.411780e+10 2.255247e+10 2.207599e+10 1.762206e+10 1.245346e+10 1.634067e+10 2.144578e+10 NaN NaN NaN
263 Turkmenistan TKM GDP (current US$) NY.GDP.MKTP.CD NaN NaN NaN NaN NaN NaN ... 3.516421e+10 3.919754e+10 4.352421e+10 3.579971e+10 3.616943e+10 3.792629e+10 4.076543e+10 4.523143e+10 NaN NaN
264 Venezuela, RB VEN GDP (current US$) NY.GDP.MKTP.CD 7.779091e+09 8.189091e+09 8.946970e+09 9.753333e+09 8.099318e+09 8.427778e+09 ... 3.812860e+11 3.710050e+11 4.823590e+11 NaN NaN NaN NaN NaN NaN NaN
265 British Virgin Islands VGB GDP (current US$) NY.GDP.MKTP.CD NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN

266 rows × 66 columns

# Here is an example on how to obtain Palau's GDP in 2018
Palau_2018_GDP = data[data['Country Name'] == 'Palau']['2018']
Palau_2018_GDP
4    284700000.0
Name: 2018, dtype: float64

Note that the value is not just a number but pandas series. Although you can do most arithmatic operations with pandas series, there are some certain operations that you need to use the actual number (in float data type). The example below illustrate on how to add the GDPs of two countries.

# Here is how to add two countries GDPs

# convert to float
Palau_2018_GDP = data[data['Country Name'] == 'Palau']['2018'].array[0]
Nauru_2018_GDP = data[data['Country Name'] == 'Nauru']['2018'].array[0]

sum_2018_GDP = Palau_2018_GDP + Nauru_2018_GDP

# display the sum
print("The total GDP from Palau and Nauru in 2018 is %.2g US Dollars" % sum_2018_GDP)
The total GDP from Palau and Nauru in 2018 is 4.1e+08 US Dollars
# Now we select a few nations to make a bar chart
countries = data['Country Name']

wh = ((countries == 'Honduras') | 
      (countries == 'Haiti') | 
      (countries == 'United States') | 
      (countries == 'Japan') | 
      (countries == 'China'))
data_selected = data[wh]
data_selected
Country Name Country Code Indicator Name Indicator Code 1960 1961 1962 1963 1964 1965 ... 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021
79 Haiti HTI GDP (current US$) NY.GDP.MKTP.CD 2.731872e+08 2.710660e+08 2.818968e+08 2.948834e+08 3.252812e+08 3.532518e+08 ... 1.370893e+10 1.490247e+10 1.513926e+10 1.483315e+10 1.398769e+10 1.503556e+10 1.645503e+10 1.478584e+10 1.450822e+10 2.094439e+10
97 Honduras HND GDP (current US$) NY.GDP.MKTP.CD 3.356500e+08 3.562000e+08 3.877500e+08 4.102000e+08 4.570000e+08 5.086500e+08 ... 1.852860e+10 1.849971e+10 1.975649e+10 2.097977e+10 2.171762e+10 2.313623e+10 2.406778e+10 2.508998e+10 2.382784e+10 2.848867e+10
229 Japan JPN GDP (current US$) NY.GDP.MKTP.CD 4.430734e+10 5.350862e+10 6.072302e+10 6.949813e+10 8.174901e+10 9.095028e+10 ... 6.272360e+12 5.212330e+12 4.896990e+12 4.444930e+12 5.003680e+12 4.930840e+12 5.037840e+12 5.123320e+12 5.040110e+12 4.937420e+12
233 China CHN GDP (current US$) NY.GDP.MKTP.CD 5.971647e+10 5.005687e+10 4.720936e+10 5.070680e+10 5.970834e+10 7.043627e+10 ... 8.532230e+12 9.570410e+12 1.047570e+13 1.106160e+13 1.123330e+13 1.231040e+13 1.389480e+13 1.427990e+13 1.468770e+13 1.773410e+13
237 United States USA GDP (current US$) NY.GDP.MKTP.CD 5.433000e+11 5.633000e+11 6.051000e+11 6.386000e+11 6.858000e+11 7.437000e+11 ... 1.625400e+13 1.684320e+13 1.755070e+13 1.820600e+13 1.869510e+13 1.947960e+13 2.052720e+13 2.137260e+13 2.089370e+13 2.299610e+13

5 rows × 66 columns

# Plot an interactive bar chart
fig = px.bar(data_selected, x='Country Name', y='2020', 
             title="Countries' GDP in 2020", log_y=True)
fig.update_yaxes(title='2020 GDP')
fig.show()