{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import geopandas" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "df = pd.DataFrame(\n", " {'City': ['Buenos Aires', 'Brasilia', 'Santiago', 'Bogota', 'Caracas'],\n", " 'Country': ['Argentina', 'Brazil', 'Chile', 'Colombia', 'Venezuela'],\n", " 'Latitude': [-34.58, -15.78, -33.45, 4.60, 10.48],\n", " 'Longitude': [-58.66, -47.91, -70.66, -74.08, -66.86]})" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "point_gdf = geopandas.GeoDataFrame(df, geometry=geopandas.points_from_xy(df.Longitude, df.Latitude))" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
OBJECTIDZIP_CODEIDgeometry
019410794107POLYGON ((-122.40116 37.78202, -122.40037 37.7...
129410594105POLYGON ((-122.3925 37.79377, -122.39189 37.79...
239412994129POLYGON ((-122.47099 37.78753, -122.47229 37.7...
349412194121POLYGON ((-122.50446 37.78807, -122.50415 37.7...
459411894118POLYGON ((-122.44889 37.77839, -122.44977 37.7...
\n", "
" ], "text/plain": [ " OBJECTID ZIP_CODE ID \\\n", "0 1 94107 94107 \n", "1 2 94105 94105 \n", "2 3 94129 94129 \n", "3 4 94121 94121 \n", "4 5 94118 94118 \n", "\n", " geometry \n", "0 POLYGON ((-122.40116 37.78202, -122.40037 37.7... \n", "1 POLYGON ((-122.3925 37.79377, -122.39189 37.79... \n", "2 POLYGON ((-122.47099 37.78753, -122.47229 37.7... \n", "3 POLYGON ((-122.50446 37.78807, -122.50415 37.7... \n", "4 POLYGON ((-122.44889 37.77839, -122.44977 37.7... " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "zipcode_gdf = geopandas.read_file('sf_zip_geo.json')\n", "display(zipcode_gdf.head(5))" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "e8da0655899f4786aedd855e9d9d5fe8", "version_major": 2, "version_minor": 1 }, "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import keplergl\n", "w1 = keplergl.KeplerGl(height=500)\n", "w1" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "w1.add_data(data=zipcode_gdf, name=\"zipcode\")" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "w1.add_data(data=point_gdf, name='cities')" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Map saved to city_map.html!\n" ] } ], "source": [ "w1.save_to_html(file_name='city_map.html', read_only=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.12.5" } }, "nbformat": 4, "nbformat_minor": 4 }