Skip to content

Instantly share code, notes, and snippets.

@immuntasir
Last active September 27, 2020 12:25
Show Gist options
  • Save immuntasir/f86160493a4b5f712a007142ddf89be5 to your computer and use it in GitHub Desktop.
Save immuntasir/f86160493a4b5f712a007142ddf89be5 to your computer and use it in GitHub Desktop.
The Beginner's Guide to Choropleth Maps in Python: How to Read the Data?
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['naturalearth_lowres', 'naturalearth_cities', 'nybb']\n"
]
}
],
"source": [
"import geopandas as gpd\n",
"print(gpd.datasets.available)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Number of rows: 177\n"
]
}
],
"source": [
"gdf = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))\n",
"print('Number of rows:', len(gdf))"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>pop_est</th>\n",
" <th>continent</th>\n",
" <th>name</th>\n",
" <th>iso_a3</th>\n",
" <th>gdp_md_est</th>\n",
" <th>geometry</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>920938</td>\n",
" <td>Oceania</td>\n",
" <td>Fiji</td>\n",
" <td>FJI</td>\n",
" <td>8374.0</td>\n",
" <td>MULTIPOLYGON (((180.00000 -16.06713, 180.00000...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>53950935</td>\n",
" <td>Africa</td>\n",
" <td>Tanzania</td>\n",
" <td>TZA</td>\n",
" <td>150600.0</td>\n",
" <td>POLYGON ((33.90371 -0.95000, 34.07262 -1.05982...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>603253</td>\n",
" <td>Africa</td>\n",
" <td>W. Sahara</td>\n",
" <td>ESH</td>\n",
" <td>906.5</td>\n",
" <td>POLYGON ((-8.66559 27.65643, -8.66512 27.58948...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>35623680</td>\n",
" <td>North America</td>\n",
" <td>Canada</td>\n",
" <td>CAN</td>\n",
" <td>1674000.0</td>\n",
" <td>MULTIPOLYGON (((-122.84000 49.00000, -122.9742...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>326625791</td>\n",
" <td>North America</td>\n",
" <td>United States of America</td>\n",
" <td>USA</td>\n",
" <td>18560000.0</td>\n",
" <td>MULTIPOLYGON (((-122.84000 49.00000, -120.0000...</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" pop_est continent name iso_a3 gdp_md_est \\\n",
"0 920938 Oceania Fiji FJI 8374.0 \n",
"1 53950935 Africa Tanzania TZA 150600.0 \n",
"2 603253 Africa W. Sahara ESH 906.5 \n",
"3 35623680 North America Canada CAN 1674000.0 \n",
"4 326625791 North America United States of America USA 18560000.0 \n",
"\n",
" geometry \n",
"0 MULTIPOLYGON (((180.00000 -16.06713, 180.00000... \n",
"1 POLYGON ((33.90371 -0.95000, 34.07262 -1.05982... \n",
"2 POLYGON ((-8.66559 27.65643, -8.66512 27.58948... \n",
"3 MULTIPOLYGON (((-122.84000 49.00000, -122.9742... \n",
"4 MULTIPOLYGON (((-122.84000 49.00000, -120.0000... "
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gdf.head()"
]
},
{
"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.2"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment