|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 1, |
| 6 | + "metadata": {}, |
| 7 | + "outputs": [ |
| 8 | + { |
| 9 | + "ename": "ModuleNotFoundError", |
| 10 | + "evalue": "No module named 'chart_studio'", |
| 11 | + "output_type": "error", |
| 12 | + "traceback": [ |
| 13 | + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", |
| 14 | + "\u001b[1;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", |
| 15 | + "\u001b[1;32m<ipython-input-1-7db8bd9622ce>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mpandas\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0mpd\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mnumpy\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[1;32mimport\u001b[0m \u001b[0mchart_studio\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mplotly\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0mpy\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 4\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mplotly\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mgraph_objs\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0mgo\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", |
| 16 | + "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'chart_studio'" |
| 17 | + ] |
| 18 | + } |
| 19 | + ], |
| 20 | + "source": [ |
| 21 | + "import pandas as pd\n", |
| 22 | + "import numpy as np\n", |
| 23 | + "import chart_studio.plotly as py\n", |
| 24 | + "import plotly.graph_objs as go" |
| 25 | + ] |
| 26 | + }, |
| 27 | + { |
| 28 | + "cell_type": "code", |
| 29 | + "execution_count": 3, |
| 30 | + "metadata": {}, |
| 31 | + "outputs": [], |
| 32 | + "source": [ |
| 33 | + "co2 = pd.read_csv('../datasets/co2.csv')\n", |
| 34 | + "gm = pd.read_csv('../datasets/gapminder.csv')\n", |
| 35 | + "df_gm = gm[['Country', 'region']].drop_duplicates()\n", |
| 36 | + "df_w_regions = pd.merge(co2, df_gm, left_on='country', right_on='Country', how='inner')\n", |
| 37 | + "df_w_regions = df_w_regions.drop('Country', axis='columns')\n", |
| 38 | + "new_co2 = pd.melt(df_w_regions, id_vars=['country', 'region'])\n", |
| 39 | + "columns = ['country', 'region', 'year', 'co2']\n", |
| 40 | + "new_co2.columns = columns\n", |
| 41 | + "df_co2 = new_co2[new_co2['year'].astype('int64') > 1963]\n", |
| 42 | + "df_co2 = df_co2.sort_values(by=['country', 'year'])\n", |
| 43 | + "df_co2['year'] = df_co2['year'].astype('int64')\n", |
| 44 | + "df_g = gm[['Country', 'Year', 'gdp', 'population', 'fertility', 'life']]\n", |
| 45 | + "df_g.columns = ['country', 'year', 'gdp', 'population', 'fertility', 'life']\n", |
| 46 | + "data = pd.merge(df_co2, df_g, on=['country', 'year'], how='left')\n", |
| 47 | + "data = data.dropna()" |
| 48 | + ] |
| 49 | + }, |
| 50 | + { |
| 51 | + "cell_type": "code", |
| 52 | + "execution_count": 4, |
| 53 | + "metadata": {}, |
| 54 | + "outputs": [ |
| 55 | + { |
| 56 | + "ename": "NameError", |
| 57 | + "evalue": "name 'go' is not defined", |
| 58 | + "output_type": "error", |
| 59 | + "traceback": [ |
| 60 | + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", |
| 61 | + "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", |
| 62 | + "\u001b[1;32m<ipython-input-4-a0b408726242>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m source = [\n\u001b[1;32m----> 2\u001b[1;33m go.Bar(x = data['region'], \n\u001b[0m\u001b[0;32m 3\u001b[0m y = data.co2[data['year'] == 1970]), \n\u001b[0;32m 4\u001b[0m go.Bar(x = data['region'], \n\u001b[0;32m 5\u001b[0m y = data.co2[data['year'] == 1980]), \n", |
| 63 | + "\u001b[1;31mNameError\u001b[0m: name 'go' is not defined" |
| 64 | + ] |
| 65 | + } |
| 66 | + ], |
| 67 | + "source": [ |
| 68 | + "source = [\n", |
| 69 | + " go.Bar(x = data['region'], \n", |
| 70 | + " y = data.co2[data['year'] == 1970]), \n", |
| 71 | + " go.Bar(x = data['region'], \n", |
| 72 | + " y = data.co2[data['year'] == 1980]), \n", |
| 73 | + " go.Bar(x = data['region'], \n", |
| 74 | + " y = data.co2[data['year'] == 1990]),\n", |
| 75 | + " go.Bar(x = data['region'], \n", |
| 76 | + " y = data.co2[data['year'] == 2000]),\n", |
| 77 | + " go.Bar(x = data['region'], \n", |
| 78 | + " y = data.co2[data['year'] == 2010]),\n", |
| 79 | + "]\n", |
| 80 | + "\n", |
| 81 | + "layout = go.Layout(barmode = 'stack')\n", |
| 82 | + "\n", |
| 83 | + "fig = go.Figure(source, layout)\n", |
| 84 | + "\n", |
| 85 | + "fig.show()" |
| 86 | + ] |
| 87 | + }, |
| 88 | + { |
| 89 | + "cell_type": "code", |
| 90 | + "execution_count": null, |
| 91 | + "metadata": {}, |
| 92 | + "outputs": [], |
| 93 | + "source": [] |
| 94 | + } |
| 95 | + ], |
| 96 | + "metadata": { |
| 97 | + "kernelspec": { |
| 98 | + "display_name": "Python 3", |
| 99 | + "language": "python", |
| 100 | + "name": "python3" |
| 101 | + }, |
| 102 | + "language_info": { |
| 103 | + "codemirror_mode": { |
| 104 | + "name": "ipython", |
| 105 | + "version": 3 |
| 106 | + }, |
| 107 | + "file_extension": ".py", |
| 108 | + "mimetype": "text/x-python", |
| 109 | + "name": "python", |
| 110 | + "nbconvert_exporter": "python", |
| 111 | + "pygments_lexer": "ipython3", |
| 112 | + "version": "3.7.3" |
| 113 | + } |
| 114 | + }, |
| 115 | + "nbformat": 4, |
| 116 | + "nbformat_minor": 2 |
| 117 | +} |
0 commit comments