<jupyter_start><jupyter_text>url_download = r'https://www.inegi.org.mx/contenidos/programas/ccpv/2020/microdatos/ageb_manzana/RESAGEBURB_16_2020_csv.zip'input_path = 'inputs/'urllib.request.urlretrieve(url_download, 'RESAGEBURB_16_2020_csv.zip')unzip = zipfile.ZipFile('RESAGEBURB_16_2020_csv.zip')unzip.extractall(input_path) url_download = r'https://www.inegi.org.mx/contenidos/productos/prod_serv/contenidos/espanol/bvinegi/productos/geografia/marcogeo/889463849568/16_michoacandeocampo.zip'input_path = 'inputs/'urllib.request.urlretrieve(url_download, '16_michoacandeocampo.zip')unzip = zipfile.ZipFile('16_michoacandeocampo.zip')unzip.extractall(input_path)<jupyter_code>michoacan_full = pd.read_csv('inputs/RESAGEBURB_16CSV20.csv')
michoacan_shp = gpd.read_file('inputs/conjunto_de_datos/16m.shp')
morelia = michoacan_full.loc[(michoacan_full["MUN"] ==53) & (michoacan_full["MZA"] !=0) ]
morelia.to_csv('outputs/morelia_manzanas_original.csv')
morelia["ENTIDAD"] = morelia["ENTIDAD"].astype(str)
morelia['MUN'] = morelia['MUN'].apply(lambda x: '{0:0>3}'.format(x))
morelia['LOC'] = morelia['LOC'].apply(lambda x: '{0:0>4}'.format(x))
morelia['MZA'] = morelia['MZA'].apply(lambda x: '{0:0>3}'.format(x))
morelia['CVEGEO']= morelia['ENTIDAD'] + morelia['MUN'] +morelia['LOC'] +morelia['AGEB'] +morelia['MZA']

morelia_shp = michoacan_shp.loc[(michoacan_shp["CVE_MUN"] =='053') ]
morelia_shp.to_file('outputs/morelia_original.shp')
shape_full = pd.merge(morelia_shp, morelia[['MUN','LOC','MZA','CVEGEO','POBTOT','P_18YMAS','TVIVHAB']], on = 'CVEGEO')
shape_full.to_file('outputs/morelia_con_poblacion.shp')
morelia_urbano = shape_full.loc[(shape_full["AMBITO"] =='Urbana') ]

morelia_urbano = morelia_urbano.replace({'*': '0'})
morelia_urbano_habitado = morelia_urbano.loc[(morelia_urbano["TVIVHAB"] !=0) ]
morelia_urbano_habitado.to_file('outputs/morelia_urbano_habitado.shp')
morelia_urbano_habitado.to_csv('outputs/morelia_urbano_habitado.csv')
colonias_michoacan = gpd.read_file("inputs/COLONIA.shp" )
colonias_morelia = colonias_michoacan.loc[(colonias_michoacan["MUNICIPIO"] ==54) ]

colonias_morelia = colonias_morelia.to_crs('EPSG:4326')

morelia_urbano_habitado = morelia_urbano_habitado.to_crs('EPSG:4326')
morelia_urbano_habitado['centroid'] = morelia_urbano_habitado.centroid
join = gpd.sjoin(colonias_morelia, morelia_urbano_habitado.set_geometry('centroid'), how="right", predicate="contains")

join.P_18YMAS = join.P_18YMAS.fillna(0)
join.TVIVHAB = join.TVIVHAB.fillna(0)
join.P_18YMAS = join.P_18YMAS.astype('int64')
join.TVIVHAB = join.TVIVHAB.astype('int64')
habitantes_colonia = join.groupby(['NOMBRE'])[['POBTOT', "P_18YMAS", "TVIVHAB"]].agg('sum').reset_index()
join.to_csv('outputs/paso_faltante.csv')
pob_col_mor = pd.merge(colonias_morelia, habitantes_colonia,on='NOMBRE')
pob_col_mor.to_file('outputs/poblacion_colonias_morelia.shp')
pob_col_mor.to_csv('outputs/poblacion_colonias_morelia.csv')
habitantes_colonia

cuadrantes_morelia = gpd.read_file("inputs/redudasproyectomorelia (1)/sectores_processed.shp" )



cuadrantes_morelia = cuadrantes_morelia.to_crs('EPSG:4326')
pob_col_mor['centroid'] = pob_col_mor.centroid

join_cuadrantes = gpd.sjoin(cuadrantes_morelia, pob_col_mor.set_geometry('centroid'), how="left", predicate="contains")

join_cuadrantes.to_csv('outputs/colonias_con_poblacion_y_cuadrantes.csv')

join_cuadrantes

tabla_cuadrantes = join_cuadrantes.groupby('Sector')['POBTOT',"P_18YMAS",'TVIVHAB'].sum()
tabla_cuadrantes.to_csv('outputs/tabla_poblacion.csv')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16280384397964953, 'fraction_numerical': 0.027699265121537593, 'mean_word_length': 10.836120401337793, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '561321', 'license': 'Apache-2.0', 'n_tokens_mistral': 1596, 'n_tokens_neox': 1528, 'n_words': 112, 'path': 'muestreo_morelia.ipynb', 'repo_name': 'unmexicano/muestreo_morelia', 'size': '3538'}