<jupyter_start><jupyter_text>Criminology in Portugal (2011) Introduction> In this _study case_, it will be analysed the **_crimes occurred_** in **_Portugal_**, during the civil year of **_2011_**. It will analysed all the _categories_ or _natures_ of this **_crimes_**, _building some statistics and making some filtering of data related to them_.> It will be applied some _filtering_ and made some _analysis_ on the data related to **_Portugal_** as _country_, like the following:* _Crimes by **Nature/Category**_* _Crimes by **Geographical Zone**_* _Crimes by **Region/City** (only considered th 5 more populated **regions/cities** in **Portugal**)_* _Conclusions_> It will be applied some _filtering_ and made some _analysis_ on the data related to the **_5 biggest/more populated regions/cities_** (_Metropolitan Area of Lisbon_, _North_, _Center_, _Metropolitan Area of Porto_, and _Algarve_) of **_Portugal_**, like the following:* **_Metropolitan Area of Lisbon_**  * _Crimes by **Nature/Category**_  * _Crimes by **Locality/Village**_  * _Conclusions_* **_North_**  * _Crimes by **Nature/Category**_  * _Crimes by **Locality/Village**_  * _Conclusions_* **_Center_**  * _Crimes by **Nature/Category**_  * _Crimes by **Locality/Village**_  * _Conclusions_* **_Metropolitan Area of Porto_**  * _Crimes by **Nature/Category**_  * _Crimes by **Locality/Village**_  * _Conclusions_* **_Algarve_**  * _Crimes by **Nature/Category**_  * _Crimes by **Locality/Village**_  * _Conclusions_<jupyter_code># Importing pandas library
import pandas as pd

import matplotlib.pyplot as plt

%matplotlib inline
crimes_by_geozone_2011 = pd.read_csv("datasets/ine.pt/2011/dataset-crimes-portugal-2011-by-geozone-2.csv" , header=1)

crimes_by_geozone_2011 = crimes_by_geozone_2011.rename(columns={'Unnamed: 0': 'Zona Geográfica'})

crimes_by_geozone_2011 = crimes_by_geozone_2011.set_index("Zona Geográfica", drop = True)<jupyter_output><empty_output><jupyter_text>Data Available in the Dataset> All the data available and used for this _study case_ can be found in the following _hyperlink_:* [dataset-crimes-portugal-2011-by-geozone-2.csv](datasets/ine.pt/2011/dataset-crimes-portugal-2011-by-geozone-2.csv) Note:> If you pretend to see all the data available and used for this _study case_, uncomment the following line.<jupyter_code># Just for debug
#crimes_by_geozone_2011<jupyter_output><empty_output><jupyter_text>Starting the Study Case  Criminology in **_Metropolitan Area of Lisbon_** (**_2011_**)  Analysing the **_crimes occurred_** in **_Metropolitan Area of Lisbon_**, during **_2011_** * The total of **_crime occurrences_** in **_Metropolitan Area of Lisbon_**, during **_2011_**, filtered by _category or nature of the crime_:<jupyter_code>crimes_lisbon_2011 = crimes_by_geozone_2011.loc["170: Área Metropolitana de Lisboa", : ]

crimes_lisbon_2011<jupyter_output><empty_output><jupyter_text>* The total number of **_crime occurrences_** in **_Metropolitan Area of Lisbon_**, during **_2011_**, filtered by _category or nature of the crime_ (_organised as a Data Frame_):<jupyter_code>crimes_lisbon_2011 = pd.DataFrame(crimes_lisbon_2011).T

crimes_lisbon_2011 = crimes_lisbon_2011.iloc[:,1:8]

crimes_lisbon_2011
# Just for debug
#crimes_lisbon_2011.columns
crimes_lisbon_2011.values[0,3] = 0

crimes_lisbon_2011.values[0,6] = 0

crimes_lisbon_2011.values[0,0] = int(crimes_lisbon_2011.values[0,0])
crimes_lisbon_2011.values[0,1] = int(float(crimes_lisbon_2011.values[0,1]))
crimes_lisbon_2011.values[0,2] = int(crimes_lisbon_2011.values[0,2])
crimes_lisbon_2011.values[0,4] = int(float(crimes_lisbon_2011.values[0,4]))
crimes_lisbon_2011.values[0,5] = int(float(crimes_lisbon_2011.values[0,5]))

# Just for debug
#crimes_lisbon_2011.values
# Just for debug
#crimes_lisbon_2011<jupyter_output><empty_output><jupyter_text>* The total number of **_crime occurrences_** in **_Metropolitan Area of Lisbon_**, during **_2011_**, filtered by _category or nature of the crime_ (_organised as a Data Frame_ and excluding some _redundant fields and data_):<jupyter_code>del crimes_lisbon_2011['Crimes contra a identidade cultural e integridade pessoal']
del crimes_lisbon_2011['Crimes contra animais de companhia']

crimes_lisbon_2011
crimes_lisbon_2011_categories = crimes_lisbon_2011.columns.tolist()

# Just for debug
#crimes_lisbon_2011_categories
crimes_lisbon_2011_values = crimes_lisbon_2011.values[0].tolist()

# Just for debug
#crimes_lisbon_2011_values<jupyter_output><empty_output><jupyter_text>* A _plot_ of a representation of the total of **_crime occurrences_** in **_Metropolitan Area of Lisbon_**, during **_2011_**, filtered by _category or nature of the crime_ (_organised as a Data Frame_ and excluding some _redundant fields and data_):<jupyter_code>plt.bar(crimes_lisbon_2011_categories, crimes_lisbon_2011_values)

plt.xticks(crimes_lisbon_2011_categories, rotation='vertical')

plt.xlabel('\nCrime Category/Nature\n')
plt.ylabel('\nNum. Occurrences\n')

plt.title('Crimes in Metropolitan Area of Lisbon, during 2011 (by Crime Category/Nature) - Bars Chart\n')

print('\n')

plt.show()
plt.pie(crimes_lisbon_2011_values, labels=crimes_lisbon_2011_categories, autopct='%.2f%%')

plt.title('Crimes in Metropolitan Area of Lisbon, during 2011 (by Crime Category/Nature) - Pie Chart\n\n')
plt.axis('equal')

print('\n')

plt.show()<jupyter_output><jupyter_text>* The total number of **_crime occurrences_** in all the **_localities/villages_** of the **_Metropolitan Area of Lisbon_**, during **_2011_**, filtered by _category or nature of the crime_ (_organised as a Data Frame_):<jupyter_code>crimes_lisbon_2011_by_locality = crimes_by_geozone_2011.loc["1701502: Alcochete":"1701114: Vila Franca de Xira", : ]

crimes_lisbon_2011_by_locality<jupyter_output><empty_output><jupyter_text>* The total number of **_crime occurrences_** in all the **_localities/villages_** of the **_Metropolitan Area of Lisbon_**, during **_2011_**, filtered by _category or nature of the crime_ (_organised as a Data Frame_ and excluding some _redundant fields and data_):<jupyter_code>del crimes_lisbon_2011_by_locality['Crimes de homicídio voluntário consumado']
del crimes_lisbon_2011_by_locality['Crimes contra a identidade cultural e integridade pessoal']
del crimes_lisbon_2011_by_locality['Crimes contra animais de companhia']

crimes_lisbon_2011_by_locality
top_6_crimes_lisbon_2011_by_locality = crimes_lisbon_2011_by_locality.sort_values(by='Total', ascending=False).head(6)

top_6_crimes_lisbon_2011_by_locality
top_6_crimes_lisbon_2011_by_locality_total = top_6_crimes_lisbon_2011_by_locality.loc[:,"Total"]

top_6_crimes_lisbon_2011_by_locality_total
top_6_crimes_lisbon_2011_by_locality_total = pd.DataFrame(top_6_crimes_lisbon_2011_by_locality_total).T

top_6_crimes_lisbon_2011_by_locality_total = top_6_crimes_lisbon_2011_by_locality_total.iloc[:,0:6]

top_6_crimes_lisbon_2011_by_locality_total
top_6_crimes_lisbon_2011_by_locality_total_localities = top_6_crimes_lisbon_2011_by_locality_total.columns.tolist()

# Just for debug
#top_6_crimes_lisbon_2011_by_locality_total_localities
top_6_crimes_lisbon_2011_by_locality_total_values = top_6_crimes_lisbon_2011_by_locality_total.values[0].tolist()

# Just for debug
#top_6_crimes_lisbon_2011_by_locality_total_values
plt.bar(top_6_crimes_lisbon_2011_by_locality_total_localities, top_6_crimes_lisbon_2011_by_locality_total_values)

plt.xticks(top_6_crimes_lisbon_2011_by_locality_total_localities, rotation='vertical')

plt.xlabel('\nLocality/Village')
plt.ylabel('\nNum. Occurrences\n')

plt.title('Crimes in Metropolitan Area of Lisbon, during 2011 (by Locality/Village in Top 6) - Bars Chart\n')

print('\n')

plt.show()
plt.pie(top_6_crimes_lisbon_2011_by_locality_total_values, labels=top_6_crimes_lisbon_2011_by_locality_total_localities, autopct='%.2f%%')

plt.title('Crimes in Metropolitan Area of Lisbon, during 2011 (by Locality/Village in Top 6) - Pie Chart\n\n')
plt.axis('equal')

print('\n')

plt.show()<jupyter_output>
{'fraction_non_alphanumeric': 0.10101262657832229, 'fraction_numerical': 0.05575696962120265, 'mean_word_length': 7.918617614269788, 'pattern_counts': {'":': 1, '<': 31, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '7018', 'license': 'MIT', 'n_tokens_mistral': 3223, 'n_tokens_neox': 2752, 'n_words': 651, 'path': 'criminology-portugal/Criminology in Portugal - 2011.ipynb', 'repo_name': 'rubenandrebarreiro/studying-crimonology-worldwide', 'size': '7999'}