-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2567efb
commit 7b2da1e
Showing
1 changed file
with
397 additions
and
0 deletions.
There are no files selected for viewing
397 changes: 397 additions & 0 deletions
397
ODS/cidades_comunidades_sustentaveis/Indicador_16.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,397 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Bibliotecas \n", | ||
"\n", | ||
"import basedosdados as bd\n", | ||
"import pandas as pd\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"%matplotlib inline" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"Downloading: 100%|██████████| 153876/153876 [00:26<00:00, 5710.56rows/s]\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"df_ocorrencias_full = bd.read_table(\n", | ||
" dataset_id='br_sp_gov_ssp',\n", | ||
" table_id='ocorrencias_registradas',\n", | ||
" billing_project_id='opendataday2024-416318'\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Tratamento do campo de municipio\n", | ||
"df_ocorrencias_full['id_municipio'] = pd.to_numeric(df_ocorrencias_full['id_municipio'], errors='coerce').astype('Int64')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Filtro Baixda Santista\n", | ||
"\n", | ||
"# Lista dos municipios da baixada santista usada para filtro\n", | ||
"municipios = [3548500,3551009,3541000,3518701,3513504,3506359]\n", | ||
"\n", | ||
"\n", | ||
"#Filtro dataset esgotameto\n", | ||
"df_ocorrencias_bx = df_ocorrencias_full[df_ocorrencias_full['id_municipio'].isin(municipios)]\n", | ||
"\n", | ||
"\n", | ||
"# Tratamento para adicionar a descrição da cidade\n", | ||
"descricao_dict = {3548500: 'Santos', 3551009: 'São Vicente', 3541000: 'Praia Grande', 3518701: 'Guarujá', 3513504: 'Cubatão', 3506359: 'Bertioga'}\n", | ||
"df_ocorrencias_bx['Descricao_Cidade'] = df_ocorrencias_bx['id_municipio'].map(descricao_dict)\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 28, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"ano Int64\n", | ||
"mes Int64\n", | ||
"id_municipio Int64\n", | ||
"regiao_ssp object\n", | ||
"homicidio_doloso Int64\n", | ||
"numero_de_vitimas_em_homicidio_doloso Int64\n", | ||
"homicidio_doloso_por_acidente_de_transito Int64\n", | ||
"numero_de_vitimas_em_homicidio_doloso_por_acidente_de_transito Int64\n", | ||
"homicidio_culposo_por_acidente_de_transito Int64\n", | ||
"homicidio_culposo_outros Int64\n", | ||
"tentativa_de_homicidio Int64\n", | ||
"lesao_corporal_seguida_de_morte Int64\n", | ||
"lesao_corporal_dolosa Int64\n", | ||
"lesao_corporal_culposa_por_acidente_de_transito Int64\n", | ||
"lesao_corporal_culposa_outras Int64\n", | ||
"latrocinio Int64\n", | ||
"numero_de_vitimas_em_latrocinio Int64\n", | ||
"total_de_estupro Int64\n", | ||
"estupro Int64\n", | ||
"estupro_de_vulneravel Int64\n", | ||
"total_de_roubo_outros Int64\n", | ||
"roubo_outros Int64\n", | ||
"roubo_de_veiculo Int64\n", | ||
"roubo_a_banco Int64\n", | ||
"roubo_de_carga Int64\n", | ||
"furto_outros Int64\n", | ||
"furto_de_veiculo Int64\n", | ||
"Descricao_Cidade object\n", | ||
"dtype: object" | ||
] | ||
}, | ||
"execution_count": 28, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"df_ocorrencias_bx.dtypes" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"df_ocorrencias_bx.head(10)\n", | ||
"\n", | ||
"df_ocorrencias_bx_2021 = df_ocorrencias_bx[df_ocorrencias_bx['ano'] == 2021]\n", | ||
"df_ocorrencias_bx_2021.head(15)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 10, | ||
"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></th>\n", | ||
" <th>lesao_corporal_seguida_de_morte</th>\n", | ||
" <th>tentativa_de_homicidio</th>\n", | ||
" <th>homicidio_culposo_outros</th>\n", | ||
" <th>roubo_outros</th>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>ano</th>\n", | ||
" <th>Descricao_Cidade</th>\n", | ||
" <th></th>\n", | ||
" <th></th>\n", | ||
" <th></th>\n", | ||
" <th></th>\n", | ||
" </tr>\n", | ||
" </thead>\n", | ||
" <tbody>\n", | ||
" <tr>\n", | ||
" <th rowspan=\"5\" valign=\"top\">2002</th>\n", | ||
" <th>Bertioga</th>\n", | ||
" <td>0</td>\n", | ||
" <td>16</td>\n", | ||
" <td>0</td>\n", | ||
" <td>0</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>Cubatão</th>\n", | ||
" <td>0</td>\n", | ||
" <td>80</td>\n", | ||
" <td>1</td>\n", | ||
" <td>0</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>Guarujá</th>\n", | ||
" <td>0</td>\n", | ||
" <td>139</td>\n", | ||
" <td>4</td>\n", | ||
" <td>0</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>Praia Grande</th>\n", | ||
" <td>0</td>\n", | ||
" <td>112</td>\n", | ||
" <td>9</td>\n", | ||
" <td>0</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>Santos</th>\n", | ||
" <td>0</td>\n", | ||
" <td>89</td>\n", | ||
" <td>0</td>\n", | ||
" <td>0</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>...</th>\n", | ||
" <th>...</th>\n", | ||
" <td>...</td>\n", | ||
" <td>...</td>\n", | ||
" <td>...</td>\n", | ||
" <td>...</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th rowspan=\"5\" valign=\"top\">2021</th>\n", | ||
" <th>Cubatão</th>\n", | ||
" <td>0</td>\n", | ||
" <td>10</td>\n", | ||
" <td>0</td>\n", | ||
" <td>264</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>Guarujá</th>\n", | ||
" <td>0</td>\n", | ||
" <td>24</td>\n", | ||
" <td>0</td>\n", | ||
" <td>1726</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>Praia Grande</th>\n", | ||
" <td>1</td>\n", | ||
" <td>22</td>\n", | ||
" <td>2</td>\n", | ||
" <td>1543</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>Santos</th>\n", | ||
" <td>1</td>\n", | ||
" <td>19</td>\n", | ||
" <td>0</td>\n", | ||
" <td>1140</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>São Vicente</th>\n", | ||
" <td>0</td>\n", | ||
" <td>6</td>\n", | ||
" <td>1</td>\n", | ||
" <td>1180</td>\n", | ||
" </tr>\n", | ||
" </tbody>\n", | ||
"</table>\n", | ||
"<p>120 rows × 4 columns</p>\n", | ||
"</div>" | ||
], | ||
"text/plain": [ | ||
" lesao_corporal_seguida_de_morte \\\n", | ||
"ano Descricao_Cidade \n", | ||
"2002 Bertioga 0 \n", | ||
" Cubatão 0 \n", | ||
" Guarujá 0 \n", | ||
" Praia Grande 0 \n", | ||
" Santos 0 \n", | ||
"... ... \n", | ||
"2021 Cubatão 0 \n", | ||
" Guarujá 0 \n", | ||
" Praia Grande 1 \n", | ||
" Santos 1 \n", | ||
" São Vicente 0 \n", | ||
"\n", | ||
" tentativa_de_homicidio homicidio_culposo_outros \\\n", | ||
"ano Descricao_Cidade \n", | ||
"2002 Bertioga 16 0 \n", | ||
" Cubatão 80 1 \n", | ||
" Guarujá 139 4 \n", | ||
" Praia Grande 112 9 \n", | ||
" Santos 89 0 \n", | ||
"... ... ... \n", | ||
"2021 Cubatão 10 0 \n", | ||
" Guarujá 24 0 \n", | ||
" Praia Grande 22 2 \n", | ||
" Santos 19 0 \n", | ||
" São Vicente 6 1 \n", | ||
"\n", | ||
" roubo_outros \n", | ||
"ano Descricao_Cidade \n", | ||
"2002 Bertioga 0 \n", | ||
" Cubatão 0 \n", | ||
" Guarujá 0 \n", | ||
" Praia Grande 0 \n", | ||
" Santos 0 \n", | ||
"... ... \n", | ||
"2021 Cubatão 264 \n", | ||
" Guarujá 1726 \n", | ||
" Praia Grande 1543 \n", | ||
" Santos 1140 \n", | ||
" São Vicente 1180 \n", | ||
"\n", | ||
"[120 rows x 4 columns]" | ||
] | ||
}, | ||
"execution_count": 10, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"df_ocorrencias_bx.groupby(['ano', 'Descricao_Cidade'])['lesao_corporal_seguida_de_morte','tentativa_de_homicidio','homicidio_culposo_outros','roubo_outros'].sum()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"ano Descricao_Cidade\n", | ||
"2002 Bertioga 16\n", | ||
" Cubatão 80\n", | ||
" Guarujá 139\n", | ||
" Praia Grande 112\n", | ||
" Santos 89\n", | ||
" ... \n", | ||
"2021 Cubatão 10\n", | ||
" Guarujá 24\n", | ||
" Praia Grande 22\n", | ||
" Santos 19\n", | ||
" São Vicente 6\n", | ||
"Name: tentativa_de_homicidio, Length: 120, dtype: Int64" | ||
] | ||
}, | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"df_ocorrencias_bx.groupby(['ano', 'Descricao_Cidade'])['tentativa_de_homicidio'].sum()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 9, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"ano Descricao_Cidade\n", | ||
"2002 Bertioga 1\n", | ||
" Cubatão 5\n", | ||
" Guarujá 6\n", | ||
" Praia Grande 2\n", | ||
" Santos 16\n", | ||
" ..\n", | ||
"2021 Cubatão 20\n", | ||
" Guarujá 20\n", | ||
" Praia Grande 47\n", | ||
" Santos 10\n", | ||
" São Vicente 10\n", | ||
"Name: roubo_de_carga, Length: 120, dtype: Int64" | ||
] | ||
}, | ||
"execution_count": 9, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"df_ocorrencias_bx.groupby(['ano', 'Descricao_Cidade'])['roubo_de_carga'].sum()" | ||
] | ||
} | ||
], | ||
"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.10" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |