Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SMPPIR-Tables
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SMPPIR
SMPPIR-Tables
Commits
cb67b934
Commit
cb67b934
authored
5 years ago
by
Edu Trevisan
Browse files
Options
Downloads
Patches
Plain Diff
Add script to new table
parent
777aa523
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Scripts/homicidios_jovens.py
+85
-0
85 additions, 0 deletions
Scripts/homicidios_jovens.py
with
85 additions
and
0 deletions
Scripts/homicidios_jovens.py
0 → 100644
+
85
−
0
View file @
cb67b934
# Copyright (C) 2019 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
# This file is part of SMPPIR-Tables.
# SMPPIR-Tables is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# SMPPIR-Tables is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with SMPPIR-Tables. If not, see <https://www.gnu.org/licenses/>.
# Para conseguir os dados dos homicídios de jovens siga os seguintes passos:
# 1 - Acesse o tabnet em estatísticas vitais nos dados de mortalidade geral em:
# http: // tabnet.datasus.gov.br/cgi/deftohtm.exe?sim/cnv/obt10uf.def
# 2 - Selecione os seguintes filtros:
# No filtro de linha selecione "Unidade de Federação"
# Na coluna selecione "Cor/Raça"
# No conteúdo selecione "Óbitos p/Ocorrência"
# Selecione o ano desejado
# Na Causa - CID-BR-10 selecione ".110 Agressões"
# Na Faixa Etária selecione o intervalo de 15 a 29 anos(use Ctrl para selecionar os 2)
# 3 - Selecione Colunas separadas por ";" e clique em "Mostra"
# 4 - Copie o resultado descartando o "&" no folder dados em um arquivo chamado
# homicidios_jovens_201X.csv
# 5 - Execute o script homicidios_jovens.py
# 6 - O resultado está no folder dadosProcessados
import
os
import
csv
import
sys
folder
=
"
dados/
"
fileName
=
"
homicidios_jovens_
"
year
=
int
(
input
(
"
Ano:
"
))
# Tentar abrir arquivo
try
:
ifile
=
open
(
folder
+
fileName
+
str
(
year
)
+
'
.csv
'
,
'
r
'
)
except
IOError
:
print
(
'
Arquivo nao encontrado:
'
+
folder
+
fileName
+
str
(
year
)
+
'
.csv
'
)
exit
()
if
not
os
.
path
.
exists
(
'
dadosProcessados
'
):
os
.
makedirs
(
'
dadosProcessados
'
)
# Se nao houve erro tratar csv
reader
=
csv
.
reader
(
ifile
,
delimiter
=
'
;
'
)
ofile
=
open
(
'
dadosProcessados/
'
+
fileName
+
str
(
year
)
+
'
.csv
'
,
'
w
'
)
writer
=
csv
.
writer
(
ofile
,
delimiter
=
'
|
'
)
# Escrever header no arquivo
headers
=
next
(
reader
,
None
)
headers
.
insert
(
0
,
'
estado_id
'
)
headers
.
append
(
'
ANO_CENSO
'
)
writer
.
writerow
(
headers
)
# Escrever linhas no arquivo com informacoes do ano
for
row
in
reader
:
row
.
insert
(
0
,
row
[
0
].
split
()[
0
])
for
i
,
string
in
enumerate
(
row
):
row
[
i
]
=
string
.
replace
(
"
-
"
,
"
0
"
)
row
.
append
(
year
)
if
row
[
0
]
!=
'
Total
'
:
writer
.
writerow
(
row
)
ifile
.
close
()
ofile
.
close
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment