From e5c84bf238dd8c5182d4e381c369dbfac7967edf Mon Sep 17 00:00:00 2001 From: Silvana654 <155696192+Silvana654@users.noreply.github.com> Date: Fri, 12 Jan 2024 20:50:06 -0500 Subject: [PATCH 1/2] #342 map 7 and map 8 --- assignments/assignment_4/Assignment_4.ipynb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/assignments/assignment_4/Assignment_4.ipynb b/assignments/assignment_4/Assignment_4.ipynb index a5461648..dd8ef3e7 100644 --- a/assignments/assignment_4/Assignment_4.ipynb +++ b/assignments/assignment_4/Assignment_4.ipynb @@ -613,7 +613,9 @@ { "cell_type": "code", "execution_count": 21, - "metadata": {}, + "metadata": { + "scrolled": true + }, "outputs": [ { "data": { @@ -640,7 +642,7 @@ ], "source": [ "fig, ax = plt.subplots(figsize=(20, 20))\n", - "dpt_shp.plot( ax = ax )" + "dpt_shp.plot( ax = ax )\n" ] }, { @@ -698,7 +700,7 @@ "metadata": { "hide_input": false, "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -712,7 +714,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.6" + "version": "3.11.5" }, "toc": { "base_numbering": 1, From b7709b224c1a0b5a14a4b0ca5063eb6b63a0f3b9 Mon Sep 17 00:00:00 2001 From: Silvana654 <155696192+Silvana654@users.noreply.github.com> Date: Fri, 12 Jan 2024 20:52:40 -0500 Subject: [PATCH 2/2] Create group_4_ass_4_2024.ipynb --- .../assignment_4/group_4_ass_4_2024.ipynb | 491 ++++++++++++++++++ 1 file changed, 491 insertions(+) create mode 100644 assignments/assignment_4/group_4_ass_4_2024.ipynb diff --git a/assignments/assignment_4/group_4_ass_4_2024.ipynb b/assignments/assignment_4/group_4_ass_4_2024.ipynb new file mode 100644 index 00000000..c05c3524 --- /dev/null +++ b/assignments/assignment_4/group_4_ass_4_2024.ipynb @@ -0,0 +1,491 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Requirement already satisfied: folium in c:\\users\\antoni\\anaconda3\\lib\\site-packages (0.15.1)\n", + "Requirement already satisfied: branca>=0.6.0 in c:\\users\\antoni\\anaconda3\\lib\\site-packages (from folium) (0.7.0)\n", + "Requirement already satisfied: jinja2>=2.9 in c:\\users\\antoni\\anaconda3\\lib\\site-packages (from folium) (3.1.2)\n", + "Requirement already satisfied: numpy in c:\\users\\antoni\\anaconda3\\lib\\site-packages (from folium) (1.24.3)\n", + "Requirement already satisfied: requests in c:\\users\\antoni\\anaconda3\\lib\\site-packages (from folium) (2.31.0)\n", + "Requirement already satisfied: xyzservices in c:\\users\\antoni\\anaconda3\\lib\\site-packages (from folium) (2022.9.0)\n", + "Requirement already satisfied: MarkupSafe>=2.0 in c:\\users\\antoni\\anaconda3\\lib\\site-packages (from jinja2>=2.9->folium) (2.1.1)\n", + "Requirement already satisfied: charset-normalizer<4,>=2 in c:\\users\\antoni\\anaconda3\\lib\\site-packages (from requests->folium) (2.0.4)\n", + "Requirement already satisfied: idna<4,>=2.5 in c:\\users\\antoni\\anaconda3\\lib\\site-packages (from requests->folium) (3.4)\n", + "Requirement already satisfied: urllib3<3,>=1.21.1 in c:\\users\\antoni\\anaconda3\\lib\\site-packages (from requests->folium) (1.26.16)\n", + "Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\antoni\\anaconda3\\lib\\site-packages (from requests->folium) (2023.11.17)\n", + "Requirement already satisfied: geopandas in c:\\users\\antoni\\anaconda3\\lib\\site-packages (0.14.2)\n", + "Requirement already satisfied: fiona>=1.8.21 in c:\\users\\antoni\\anaconda3\\lib\\site-packages (from geopandas) (1.9.5)\n", + "Requirement already satisfied: packaging in c:\\users\\antoni\\anaconda3\\lib\\site-packages (from geopandas) (23.1)\n", + "Requirement already satisfied: pandas>=1.4.0 in c:\\users\\antoni\\anaconda3\\lib\\site-packages (from geopandas) (2.0.3)\n", + "Requirement already satisfied: pyproj>=3.3.0 in c:\\users\\antoni\\anaconda3\\lib\\site-packages (from geopandas) (3.6.1)\n", + "Requirement already satisfied: shapely>=1.8.0 in c:\\users\\antoni\\anaconda3\\lib\\site-packages (from geopandas) (2.0.2)\n", + "Requirement already satisfied: attrs>=19.2.0 in c:\\users\\antoni\\anaconda3\\lib\\site-packages (from fiona>=1.8.21->geopandas) (22.1.0)\n", + "Requirement already satisfied: certifi in c:\\users\\antoni\\anaconda3\\lib\\site-packages (from fiona>=1.8.21->geopandas) (2023.11.17)\n", + "Requirement already satisfied: click~=8.0 in c:\\users\\antoni\\anaconda3\\lib\\site-packages (from fiona>=1.8.21->geopandas) (8.0.4)\n", + "Requirement already satisfied: click-plugins>=1.0 in c:\\users\\antoni\\anaconda3\\lib\\site-packages (from fiona>=1.8.21->geopandas) (1.1.1)\n", + "Requirement already satisfied: cligj>=0.5 in c:\\users\\antoni\\anaconda3\\lib\\site-packages (from fiona>=1.8.21->geopandas) (0.7.2)\n", + "Requirement already satisfied: six in c:\\users\\antoni\\anaconda3\\lib\\site-packages (from fiona>=1.8.21->geopandas) (1.16.0)\n", + "Requirement already satisfied: setuptools in c:\\users\\antoni\\anaconda3\\lib\\site-packages (from fiona>=1.8.21->geopandas) (68.0.0)\n", + "Requirement already satisfied: python-dateutil>=2.8.2 in c:\\users\\antoni\\anaconda3\\lib\\site-packages (from pandas>=1.4.0->geopandas) (2.8.2)\n", + "Requirement already satisfied: pytz>=2020.1 in c:\\users\\antoni\\anaconda3\\lib\\site-packages (from pandas>=1.4.0->geopandas) (2023.3.post1)\n", + "Requirement already satisfied: tzdata>=2022.1 in c:\\users\\antoni\\anaconda3\\lib\\site-packages (from pandas>=1.4.0->geopandas) (2023.3)\n", + "Requirement already satisfied: numpy>=1.21.0 in c:\\users\\antoni\\anaconda3\\lib\\site-packages (from pandas>=1.4.0->geopandas) (1.24.3)\n", + "Requirement already satisfied: colorama in c:\\users\\antoni\\anaconda3\\lib\\site-packages (from click~=8.0->fiona>=1.8.21->geopandas) (0.4.6)\n" + ] + } + ], + "source": [ + "! pip install folium\n", + "! pip install geopandas\n" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "#cargando las bibliotecas\n", + "import pandas as pd\n", + "#from pandas import Series, DataFrame\n", + "import numpy as np\n", + "import matplotlib.pyplot as plt \n", + "import chardet\n", + "\n", + "import folium as fm\n", + "from folium import Marker, GeoJson\n", + "from folium.plugins import MarkerCluster, HeatMap, StripePattern\n", + "\n", + "import geopandas as gpd\n", + "from geopandas import GeoSeries\n", + "from shapely.geometry import Point, LineString\n", + "\n", + "\n", + "import branca.colormap as br " + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "from IPython.display import display, HTML\n", + "\n", + "display(HTML(data=\"\"\"\n", + "\n", + "\"\"\"))" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'c:\\\\Users\\\\Antoni\\\\Documents\\\\GitHub\\\\QLAB_Summer_Python\\\\assignments\\\\assignment_4'" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pwd" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "# Get data of labor\n", + "sex_work = pd.read_stata(r'../../../QLAB_Summer_Python/_data/8_trab_sex_20.dta' )\n", + "sex_work[ 'dpt_code' ] = sex_work.cod_ubigeo.str[ :2 ].copy()\n", + "sex_work[ 'prov_code' ] = sex_work.cod_ubigeo.str[ :4 ].copy()\n", + "\n", + "# Sex work\n", + "women_work = sex_work[ sex_work.sex == 'Mujer' ].copy().reset_index( drop = True )" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "# get data from lima\n", + "women_work[ 'month' ] = pd.to_datetime( women_work.month , format = '%B' ) \\\n", + " .dt.strftime( '%m' ) \\\n", + " .astype( int )" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "# Sort by department and month\n", + "women_work.sort_values([ 'dpt_code', 'month'], inplace = True )\n", + "\n", + "# Get the total number of women workers by dpt\n", + "dpt_women_work = women_work.groupby( [ 'dpt_code', 'month'], as_index = False )[['empl']] \\\n", + " .sum() \\\n", + " .rename( columns = {'empl' :'women_empl'})\n", + "\n", + "# Sort by dpt code and month\n", + "dpt_women_work.sort_values([ 'dpt_code', 'month'], inplace = True )" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "df2 = dpt_women_work.groupby( ['dpt_code'],as_index = False )[['women_empl']].mean()" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "#SHAPEFILE\n", + "dpt_shp = gpd.read_file(r'../../../QLAB_Summer_Python/_data/INEI_LIMITE_DEPARTAMENTAL/INEI_LIMITE_DEPARTAMENTAL.shp')" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "df3 = dpt_shp.merge( df2, left_on = 'CCDD', right_on = 'dpt_code' )" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'fm' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[4], line 7\u001b[0m\n\u001b[0;32m 5\u001b[0m zoom_start \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m5\u001b[39m\n\u001b[0;32m 6\u001b[0m \u001b[38;5;66;03m#Then we use this information to locate Peru\u001b[39;00m\n\u001b[1;32m----> 7\u001b[0m map1 \u001b[38;5;241m=\u001b[39m fm\u001b[38;5;241m.\u001b[39mMap(location \u001b[38;5;241m=\u001b[39m [lat_palacio, long_palacio], tiles\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mcartodbpositron\u001b[39m\u001b[38;5;124m'\u001b[39m, zoom_start \u001b[38;5;241m=\u001b[39m zoom_start)\n\u001b[0;32m 8\u001b[0m \u001b[38;5;66;03m#Finally we specify the geographical separation by department and the information that will be used to distinguish according to colors.\u001b[39;00m\n\u001b[0;32m 9\u001b[0m \u001b[38;5;66;03m#Because there is no color scheme in follium that goes from white to red, we use the one that goes from yellow to red\u001b[39;00m\n\u001b[0;32m 10\u001b[0m fm\u001b[38;5;241m.\u001b[39mChoropleth( \n\u001b[0;32m 11\u001b[0m geo_data\u001b[38;5;241m=\u001b[39mdf3,\n\u001b[0;32m 12\u001b[0m data\u001b[38;5;241m=\u001b[39mdf3,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 23\u001b[0m nan_fill_color \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mWhite\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 24\u001b[0m )\u001b[38;5;241m.\u001b[39madd_to(map1)\n", + "\u001b[1;31mNameError\u001b[0m: name 'fm' is not defined" + ] + } + ], + "source": [ + "#Map 1\n", + "#First we put Lima as the center of the map,using lat and long\n", + "lat_palacio = -12.0757538\n", + "long_palacio = -76.9863174\n", + "zoom_start = 5\n", + "#Then we use this information to locate Peru\n", + "map1 = fm.Map(location = [lat_palacio, long_palacio], tiles='cartodbpositron', zoom_start = zoom_start)\n", + "#Finally we specify the geographical separation by department and the information that will be used to distinguish according to colors.\n", + "#Because there is no color scheme in follium that goes from white to red, we use the one that goes from yellow to red\n", + "fm.Choropleth( \n", + " geo_data=df3,\n", + " data=df3,\n", + " columns=[\"dpt_code\",\"women_empl\"],\n", + " key_on=\"feature.properties.dpt_code\",\n", + " fill_color=\"YlOrRd\",\n", + " fill_opacity=0.8,\n", + " line_opacity=0.8,\n", + " smooth_factor=0.2,\n", + " legend_name='Women employers',\n", + " Highlight= True,\n", + " line_color = \"#000000\",\n", + " overlay=True,\n", + " nan_fill_color = \"White\"\n", + " ).add_to(map1)\n", + "map1\n", + "\n", + "## MAP 1\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'fm' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[3], line 5\u001b[0m\n\u001b[0;32m 3\u001b[0m long_palacio \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m76.9863174\u001b[39m\n\u001b[0;32m 4\u001b[0m zoom_start \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m5\u001b[39m\n\u001b[1;32m----> 5\u001b[0m map2 \u001b[38;5;241m=\u001b[39m fm\u001b[38;5;241m.\u001b[39mMap(location \u001b[38;5;241m=\u001b[39m [lat_palacio, long_palacio], tiles\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mcartodbpositron\u001b[39m\u001b[38;5;124m'\u001b[39m, zoom_start \u001b[38;5;241m=\u001b[39m zoom_start)\n\u001b[0;32m 6\u001b[0m \u001b[38;5;66;03m#In this case we have to create bins to separate the colors by ranges\u001b[39;00m\n\u001b[0;32m 7\u001b[0m bins \u001b[38;5;241m=\u001b[39m [\u001b[38;5;241m675.33\u001b[39m, \u001b[38;5;241m20000\u001b[39m, \u001b[38;5;241m40000\u001b[39m, \u001b[38;5;241m60000\u001b[39m, \u001b[38;5;241m100000\u001b[39m, \u001b[38;5;241m656477.25\u001b[39m] \n", + "\u001b[1;31mNameError\u001b[0m: name 'fm' is not defined" + ] + } + ], + "source": [ + "##Map2\n", + "lat_palacio = -12.0757538\n", + "long_palacio = -76.9863174\n", + "zoom_start = 5\n", + "map2 = fm.Map(location = [lat_palacio, long_palacio], tiles='cartodbpositron', zoom_start = zoom_start)\n", + "#In this case we have to create bins to separate the colors by ranges\n", + "bins = [675.33, 20000, 40000, 60000, 100000, 656477.25] \n", + "#Finally we specify the geographical separation by department and the information that will be used to distinguish according to colors.\n", + "fm.Choropleth(\n", + " geo_data=df3,\n", + " data=df3,\n", + " columns=[\"dpt_code\", \"women_empl\"],\n", + " key_on=\"feature.properties.dpt_code\",\n", + " fill_color='YlOrRd',\n", + " fill_opacity=0.8,\n", + " line_opacity=0.8,\n", + " smooth_factor=0.2,\n", + " legend_name='Women employers',\n", + " line_color=\"#000000\",\n", + " bins=bins, # Specify the bins\n", + " nan_fill_color=\"White\",\n", + " highlight=True,\n", + " overlay=True,\n", + " threshold_scale=bins, # We adjust the range\n", + ").add_to(map2)\n", + "\n", + "map2" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'df3' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[5], line 3\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m#mapa 3\u001b[39;00m\n\u001b[0;32m 2\u001b[0m \u001b[38;5;66;03m#mapa 3\u001b[39;00m\n\u001b[1;32m----> 3\u001b[0m df3_1\u001b[38;5;241m=\u001b[39mdf3[ df3\u001b[38;5;241m.\u001b[39mCCDD \u001b[38;5;241m!=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m15\u001b[39m\u001b[38;5;124m\"\u001b[39m ]\n\u001b[0;32m 4\u001b[0m \u001b[38;5;66;03m#seteamos el palacio de gobierno\u001b[39;00m\n\u001b[0;32m 5\u001b[0m lat_palacio \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m12.0757538\u001b[39m\n", + "\u001b[1;31mNameError\u001b[0m: name 'df3' is not defined" + ] + } + ], + "source": [ + "#mapa 3\n", + "#mapa 3\n", + "df3_1=df3[ df3.CCDD != \"15\" ]\n", + "#seteamos el palacio de gobierno\n", + "lat_palacio = -12.0757538\n", + "long_palacio = -76.9863174\n", + "zoom_start = 5\n", + "map3 = fm.Map(location = [lat_palacio, long_palacio], tiles='cartodbpositron', zoom_start = zoom_start)\n", + "#In this case we have to create bins to separate the colors by ranges\n", + "bins = [675.33, 20000, 40000, 60000, 100000, 656477.25] \n", + "#Finally we specify the geographical separation by department and the information that will be used to distinguish according to colors.\n", + "fm.Choropleth(\n", + " geo_data=df3_1,\n", + " data=df3_1,\n", + " columns=[\"dpt_code\", \"women_empl\"],\n", + " key_on=\"feature.properties.dpt_code\",\n", + " fill_color='YlOrRd',\n", + " fill_opacity=0.8,\n", + " line_opacity=0.8,\n", + " smooth_factor=0.2,\n", + " legend_name='Women employers',\n", + " line_color=\"#000000\",\n", + " bins=bins, # Specify the bins\n", + " nan_fill_color=\"White\",\n", + " highlight=True,\n", + " overlay=True,\n", + " threshold_scale=bins, # We adjust the range\n", + ").add_to(map3)\n", + "\n", + "map3\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#mapa 4\n", + "#generamos la nueva variable en un data frame nuevo:\n", + "df4 = sex_work.groupby( ['dpt_code', 'month', 'sex'], as_index = False )[['empl']].sum() \\\n", + " .pivot( index = [ 'dpt_code', 'month' ] , columns = 'sex',values='empl') \\\n", + " .reset_index()\n", + "\n", + "df4[ 'prop_wom' ] = ( df4.Mujer * 100 / df4.Hombre )\n", + "df5 = dpt_shp.merge( df4, left_on = 'CCDD', right_on = 'dpt_code' )" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# MAP 4\n", + "\n", + "La creación del mapa 4 vuelve al archivo muy pesado. Por eso la siguiente parte del codigo está comentado. Quitar el comentario y correr en el propio ordenador para poder observar el mapa y se creará un archivo html con el mapa también.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "' # Lista de meses\\nmeses = [\"January\", \"February\", \"March\", \"April\", \"May\", \"June\", \"July\", \"August\", \"September\", \"October\", \"November\", \"December\"]\\n# Coordenadas para centrar el mapa (puedes ajustarlas según tus necesidades)\\nlat_palacio = -12.0757538\\nlong_palacio = -76.9863174\\n#zoom start\\nzoom_start = 5\\n# Crear el mapa inicial\\nmap3 = fm.Map(location=[lat_palacio, long_palacio], tiles=\\'cartodbpositron\\', zoom_start=zoom_start)\\n\\n\\n# Iterar sobre cada mes\\nfor a in meses:\\n # Seleccionar el DataFrame correspondiente al mes\\n df_month = df5.loc[df5[\\'month\\']==a]\\n \\n # Crear la capa Choropleth para el mes actual\\n fm.Choropleth(\\n geo_data=df_month,\\n data=df_month,\\n columns= [\"dpt_code\", \"prop_wom\"],\\n key_on= \"feature.properties.dpt_code\",\\n fill_opacity= 0.8,\\n line_opacity= 0.8,\\n smooth_factor= 0.2,\\n line_color= \"#000000\",\\n overlay= True,\\n nan_fill_color= \"White\",\\n fill_color=\"YlOrRd\",\\n legend_name= \\'Women employers\\',\\n name=a,\\n Highlight=True,\\n show=False,\\n ).add_to(map3)\\n\\n# Añadir el control de capas\\nfm.LayerControl(collapsed=False, autoZIndex=False).add_to(map3)\\n\\n# Mostrar el mapa\\nmap3\\n\\nmap3.save(\"mapa4.html\") '" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"\"\" # Lista de meses\n", + "meses = [\"January\", \"February\", \"March\", \"April\", \"May\", \"June\", \"July\", \"August\", \"September\", \"October\", \"November\", \"December\"]\n", + "# Coordenadas para centrar el mapa (puedes ajustarlas según tus necesidades)\n", + "lat_palacio = -12.0757538\n", + "long_palacio = -76.9863174\n", + "#zoom start\n", + "zoom_start = 5\n", + "# Crear el mapa inicial\n", + "map3 = fm.Map(location=[lat_palacio, long_palacio], tiles='cartodbpositron', zoom_start=zoom_start)\n", + "\n", + "\n", + "# Iterar sobre cada mes\n", + "for a in meses:\n", + " # Seleccionar el DataFrame correspondiente al mes\n", + " df_month = df5.loc[df5['month']==a]\n", + " \n", + " # Crear la capa Choropleth para el mes actual\n", + " fm.Choropleth(\n", + " geo_data=df_month,\n", + " data=df_month,\n", + " columns= [\"dpt_code\", \"prop_wom\"],\n", + " key_on= \"feature.properties.dpt_code\",\n", + " fill_opacity= 0.8,\n", + " line_opacity= 0.8,\n", + " smooth_factor= 0.2,\n", + " line_color= \"#000000\",\n", + " overlay= True,\n", + " nan_fill_color= \"White\",\n", + " fill_color=\"YlOrRd\",\n", + " legend_name= 'Women employers',\n", + " name=a,\n", + " Highlight=True,\n", + " show=False,\n", + " ).add_to(map3)\n", + "\n", + "# Añadir el control de capas\n", + "fm.LayerControl(collapsed=False, autoZIndex=False).add_to(map3)\n", + "\n", + "# Mostrar el mapa\n", + "map3\n", + "\n", + "map3.save(\"mapa4.html\") \"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#mapa 5" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#mapa 6" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#mapa 7" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#mapa 8" + ] + } + ], + "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.11.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}