import pandas as pd
import chart_studio.plotly as py
import plotly.graph_objs as go
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
init_notebook_mode(connected=True)
raw_df = pd.read_csv('dataset-gdp/data.csv')
# info()
raw_df.size
17160
raw_df.head(3)
Country Name | Country Code | Indicator Name | Indicator Code | 1960 | 1961 | 1962 | 1963 | 1964 | 1965 | ... | 2011 | 2012 | 2013 | 2014 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | Aruba | ABW | GDP (current US$) | NY.GDP.MKTP.CD | NaN | NaN | NaN | NaN | NaN | NaN | ... | 2.549721e+09 | 2.534637e+09 | 2.701676e+09 | 2.765363e+09 | 2.919553e+09 | 2.965922e+09 | 3.056425e+09 | NaN | NaN | NaN |
1 | Afghanistan | AFG | GDP (current US$) | NY.GDP.MKTP.CD | 5.377778e+08 | 5.488889e+08 | 5.466667e+08 | 7.511112e+08 | 8.000000e+08 | 1.006667e+09 | ... | 1.780429e+10 | 2.000160e+10 | 2.056107e+10 | 2.048489e+10 | 1.990711e+10 | 1.801775e+10 | 1.886995e+10 | 1.835388e+10 | 1.929110e+10 | NaN |
2 | Angola | AGO | GDP (current US$) | NY.GDP.MKTP.CD | NaN | NaN | NaN | NaN | NaN | NaN | ... | 1.117897e+11 | 1.280529e+11 | 1.367099e+11 | 1.457122e+11 | 1.161936e+11 | 1.011239e+11 | 1.221238e+11 | 1.013532e+11 | 8.881570e+10 | NaN |
3 rows × 65 columns
df = [raw_df[raw_df.columns[0]],
raw_df[raw_df.columns[1]],
raw_df[raw_df.columns[63]]]
headers = ["country", "code", "2019"]
df = pd.concat(df,
axis = 1,
keys = headers)
df.head(3)
country | code | 2019 | |
---|---|---|---|
0 | Aruba | ABW | NaN |
1 | Afghanistan | AFG | 1.929110e+10 |
2 | Angola | AGO | 8.881570e+10 |
data = dict(
type = 'choropleth',
locations = df['code'],
z = df['2019'],
colorscale= 'Reds',
colorbar = {
'title': 'USD'
}
)
choromap = go.Figure(
data = [data],
layout = {
'title':'2019 Global GDP in USD',
}
)
iplot(choromap)