Analysis of Violence in Rio de Janeiro

Translated from the original Portuguese article. Ler o original em português

Cover of the article Analysis of Violence in Rio de Janeiro

Figure 1 of the article Analysis of Violence in Rio de Janeiro

Ah, Rio de Janeiro, what a marvelous city! The beautiful hills that surround it, the huge Christ the Redeemer statue, not to mention the beaches and museums spread all over the city. But not everything is rosy, right?

Due to "n" delicate historical factors, which I won't get into, violence in the city has reached alarming levels, as we see in every newspaper and TV show out there. However, Agência Brasil, a federal government agency, reports a reduction in crime, such as intentional homicides, which fell by 21% in 2019. The agency relies on data published by the State of Rio de Janeiro, more specifically by the Instituto de Segurança Pública (ISP, the state's Public Security Institute), the body responsible for recording incidents reported to Civil Police stations.

So I decided to explore the Institute's databases. Knowing full well that these issues are not black and white, I ran an exploratory analysis of some of the variables to extract a few insights, as you'll see. The full project is in my repository, which contains the notebook I used.

The data used here was obtained from the Instituto de Segurança Pública of the State of Rio de Janeiro. It has 61 variables and 6,992 records, extracted on June 11, 2020, showing the categories of crimes recorded in the municipalities where they occurred, as a time series starting in 2014.

#Importar os dados                                                                         
df="http://www.ispdados.rj.gov.br/Arquivos/BaseMunicipioMensal.csv"
data=pd.read_csv(df,sep=";",encoding='latin-1')

As we can see in the first five entries below:

fmun_cod fmun ano mes mes_ano regiao hom_doloso lesao_corp_morte latrocinio hom_por_interv_policial letalidade_violenta tentat_hom lesao_corp_dolosa estupro hom_culposo lesao_corp_culposa roubo_comercio roubo_residencia roubo_veiculo roubo_carga roubo_transeunte roubo_em_coletivo roubo_banco roubo_cx_eletronico roubo_celular roubo_conducao_saque roubo_apos_saque roubo_bicicleta outros_roubos total_roubos furto_veiculos furto_transeunte furto_coletivo furto_celular furto_bicicleta outros_furtos total_furtos sequestro extorsao sequestro_relampago estelionato apreensao_drogas posse_drogas trafico_drogas apreensao_drogas_sem_autor recuperacao_veiculos apf aaapai cmp cmba ameaca pessoas_desaparecidas encontro_cadaver encontro_ossada pol_militares_mortos_serv pol_civis_mortos_serv indicador_cvli indicador_roubo_rua indicador_roubo_veic indicador_roubo_carga registro_ocorrencias fase
0 3300100 Angra dos Reis 2014 1 2014m1 Interior 11 0 0 1 12 2 96 7 4 37 4 0 8 0 5 1 0 0 1 0 0 0 5 23 18 3 3 11 0 98 134 0 0 0 21 35 18 12 5 9 28 6 8 0 98 13 3 0 0 0 11 7 8 0 561 3
1 3300159 Aperibé 2014 1 2014m1 Interior 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3
2 3300209 Araruama 2014 1 2014m1 Interior 2 0 0 0 2 6 69 7 1 45 3 2 9 0 6 0 0 0 1 0 0 0 2 23 16 2 1 10 0 76 105 0 2 0 18 13 9 4 1 4 34 5 5 0 91 10 1 0 0 0 2 7 9 0 480 3
3 3300225 Areal 2014 1 2014m1 Interior 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3
4 3300233 Armação dos Búzios 2014 1 2014m1 Interior 2 0 0 0 2 0 44 6 0 26 0 0 2 0 5 0 0 0 1 0 0 0 20 12 9 9 2 7 0 74 117 0 0 0 4 16 6 10 2 2 26 8 3 2 46 0 0 0 0 0 2 6 2 0 309 3

However, for this work I had to apply a few filters. First I set the fmun_cod column, which holds the identifier of each municipality in the state, as the index. That way, I filtered only the data for the city of Rio de Janeiro.

#Localizar ID do Rio de Janeiro
data_rj=data.loc[3304557]

Then I started to understand how the dataset behaves, first making a copy of the original data. I began by dropping the mes_ano, mes, regiao and fmun columns, then filtered out all 2020 data, since at the time of the project that year was still under way. Finally, I set the year column as the index and aggregated the values of each variable by year.

#Agrupar pelo ano
data_time = data_time.groupby(['ano']).sum()

As a result, we end up with the following data, with 6 entries and 57 variables.

hom_doloso lesao_corp_morte latrocinio hom_por_interv_policial letalidade_violenta tentat_hom lesao_corp_dolosa estupro hom_culposo lesao_corp_culposa roubo_comercio roubo_residencia roubo_veiculo roubo_carga roubo_transeunte roubo_em_coletivo roubo_banco roubo_cx_eletronico roubo_celular roubo_conducao_saque roubo_apos_saque roubo_bicicleta outros_roubos total_roubos furto_veiculos furto_transeunte furto_coletivo furto_celular furto_bicicleta outros_furtos total_furtos sequestro extorsao sequestro_relampago estelionato apreensao_drogas posse_drogas trafico_drogas apreensao_drogas_sem_autor recuperacao_veiculos apf aaapai cmp cmba ameaca pessoas_desaparecidas encontro_cadaver encontro_ossada pol_militares_mortos_serv pol_civis_mortos_serv indicador_cvli indicador_roubo_rua indicador_roubo_veic indicador_roubo_carga registro_ocorrencias fase
ano
2014 1237 17 51 247 1552 2265 34853 1781 573 21791 3668 487 13725 3436 39686 4412 23 23 4745 57 818 0 11363 79204 7515 24662 8207 10232 0 50637 104492 0 855 106 20151 9839 4813 3622 1522 10941 12591 4586 10039 457 32621 2566 180 12 0 0 1305 48843 13725 3436 395717 36
2015 1200 11 44 307 1562 2466 30341 1610 495 19114 3201 442 15478 4195 37014 4471 19 12 7082 58 723 85 10988 81617 7178 21923 7932 12001 529 46338 98052 2 989 89 20287 9593 4716 3828 1154 11166 11090 3397 5667 349 27521 3066 188 19 15 2 1255 48567 15478 4195 376655 36
2016 1330 28 88 463 1909 2223 27245 1499 502 16399 3118 544 19314 4964 45029 7048 14 28 10120 50 448 121 15454 103014 6710 18563 8113 11262 939 48691 97516 9 804 48 21707 7658 3996 2913 836 13811 12747 3810 5050 571 23875 2710 195 11 21 2 1446 62197 19314 4964 389539 36
2017 1492 19 93 527 2131 2225 23758 1565 647 11984 3272 499 25894 5371 45518 8749 14 45 13650 31 411 90 20748 123126 6839 12665 6230 10464 1104 47866 86334 3 811 62 17305 4226 1440 2228 615 19344 11564 2607 5844 853 19088 2117 122 6 18 1 1604 67917 25894 5371 375212 36
2018 1338 25 66 558 1987 1986 24457 1642 642 12076 3262 413 24798 4018 44903 9143 11 33 14622 48 614 109 20276 121111 7050 13043 6781 10000 847 43630 82490 0 830 66 20073 3878 1204 1998 726 18705 10749 2072 5601 1406 20439 2005 134 7 15 4 1429 68668 24798 4018 375027 36
2019 1134 19 34 726 1913 1635 23907 1726 603 11916 2564 392 18466 3145 40456 9775 12 21 14433 79 642 128 14026 104139 6862 13943 6399 11949 1339 50576 91068 0 886 67 23648 4326 1271 2266 827 12812 11711 2078 8456 2050 20532 2009 125 12 10 0 1187 64664 18466 3145 379989 36

With the dataset organized, I started asking it questions, beginning with: "What is the average number of vehicle robberies per year?" Vehicle robbery is a common occurrence in state capitals; national statistics indicate that a car is robbed every minute.

Its descriptive statistics show an average of 19,612.50 vehicle robberies per year. In addition, the maximum was 25,894 and the minimum 13,725, which are fairly high values.

count        6.000000
mean     19612.500000
std       4888.905061
min      13725.000000
25%      16225.000000
50%      18890.000000
75%      23427.000000
max      25894.000000
Name: roubo_veiculo, dtype: float64

When we compare the values for each year, we get the following chart, which shows fairly similar values:


Continuing with the questions: what about thefts? Their values turned out to be much lower than robberies and fairly linear over time. This data has an average of 7,025.66 per year, a maximum of 7,515 and a minimum of 6,710.


With this, I was able to calculate the percentage of recovered vehicles using the following equation:

#Porcentagem de veículos recuperados
rec_vec = (data_time.recuperacao_veiculos)/(data_time.furto_veiculos+data_time.roubo_veiculo)*100

For the percentage of recovered vehicles, I noticed fairly similar values, with an average of 53.71% per year, a maximum of 59.09% and a minimum of 49.28%. In addition, the percentage of recovered vehicles over the entire 6-year period was 54.29%.

count     6.000000
mean     53.713210
std       4.214933
min      49.284958
25%      50.816075
50%      52.290771
75%      57.316638
max      59.096325
dtype: float64

Next, I asked: "What is the temporal distribution of robbery-homicides (latrocínios)?" Latrocínio refers to robbery followed by death, an important indicator of urban violence. There were 62 cases per year on average, with a maximum of 93 and a minimum of 34.

count     6.000000
mean     62.666667
std      23.997222
min      34.000000
25%      45.750000
50%      58.500000
75%      82.500000
max      93.000000
Name: latrocinio, dtype: float64

Robbery-homicides in the city of Rio peaked in 2017, followed by a drop in 2018 and 2019.


I also looked at robberies on public transport (buses, vans, trains, subways and others), which was a common practice among criminals a few years ago. However, the data shows that this practice is on the rise, with a very high average of 7,266 cases, a maximum of 9,775 and a minimum of 4,412.

count       6.000000
mean     7266.333333
std      2367.376748
min      4412.000000
25%      5115.250000
50%      7898.500000
75%      9044.500000
max      9775.000000
Name: roubo_em_coletivo, dtype: float64

It's worth stressing that this is a preliminary study that shows the potential of using Python, basic descriptive statistics and data to extract insights and support decision-making. The project was an exercise from the Data Science na Prática course.

It showed that the average number of vehicle robberies has decreased, while thefts have remained practically unchanged. When we compare these with the number of recovered vehicles, the overall average across all years is 54%, which means that a little over 50% of stolen vehicles are returned to their owners.

I also ran a quick analysis of the number of robbery-homicides over the period, which showed a drastic drop in 2018 and 2019. Finally, I analyzed robberies on public transport, which have been growing strongly since 2016.

Keep reading

All articles

Credit Card Fraud Detection

Credit card fraud is one of the main concerns of financial institutions. In this post, I explore a dataset of European card transactions and build a …