{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df = pd.read_csv('Gapminder-data.csv', sep=',')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df.head()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df.describe()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df_info = pd.read_csv('Gapminder-info.csv', sep=',', index_col=0)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df_info" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df_info.loc['Population', 'LogScale']" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import plotly.express as px" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "df_2000 = df.query('Year==2000')\n", "df_2000.head()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "color_map = {\n", " 'Asia': '#ff798e',\n", " 'Europe': '#ffeb33',\n", " 'Americas': '#98ef33',\n", " 'Africa': '#33dded'\n", "}" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig = px.scatter(\n", " df_2000, \n", " x='Income',\n", " y='Life expectancy',\n", " color='Region',\n", " size='Population',\n", " size_max=60,\n", " hover_name='Country',\n", " hover_data={'Income': False, 'Life expectancy': False, 'Region': False, 'Population': False},\n", " color_discrete_map=color_map,\n", " log_x=True\n", ")\n", "fig.update_traces(marker=dict(opacity=1, line=dict(color='black', width=0.8)))\n", "fig.update_layout(plot_bgcolor='white')\n", "fig.update_xaxes(linecolor='dimgray', gridcolor='lightgray', linewidth=1)\n", "fig.update_yaxes(linecolor='dimgray', gridcolor='lightgray', linewidth=1)\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": false }, "outputs": [], "source": [ "print(fig)" ] }, { "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.8.6" } }, "nbformat": 4, "nbformat_minor": 4 }