import pandas as pd
# UNODC human trafficking dataframe with additional data on citizenship of victims / traffickers
= pd.read_excel('../../data/raw-data/UNODC_TIP_data.xlsx', skiprows=2) # remove first two rows
repats
# 1. subset to Region == "Europe"
= repats[repats['Region'] == 'Europe']
repats
# 2. subset indicator to only detected trafficking victims
= repats[repats['Indicator'] == 'Detected trafficking victims']
repats
# 3. subset dimension column to only include "Total" and "by country of repatriation"
= repats[repats['Dimension'].isin(['Total', 'by country of repatriation'])]
repats
# 4. subset to the Sex == "Total"
= repats[repats['Sex'] == 'Total']
repats
# 5. subset to Age == "Total"
= repats[repats['Age'] == 'Total']
repats
# 6. rename txtVALUE --> "Counts"
= repats.rename(columns={'txtVALUE': 'Counts'})
repats
# 7. convert observations where Counts = "<5" to numeric value 5
'Counts'] = repats['Counts'].replace("<5", 5)
repats['Counts'] = pd.to_numeric(repats['Counts'], errors='coerce')
repats[
# 8. remove unnecessary columns
= ['Iso3_code', 'Region', 'Sex', 'Age', 'Unit of measurement', 'Source']
columns_to_drop = repats.drop(columns=columns_to_drop)
repats
# 9. group and get the sum of total repatriated victims for each country each year
= repats[
foreign_victims 'Dimension'] == 'by country of repatriation') &
(repats['Category'] != repats['Country'])
(repats[
]
= foreign_victims.groupby(['Country', 'Year'])['Counts'].sum().reset_index()
repat_totals = repat_totals.rename(columns = {'Counts': 'Number_Repatriated_Victims'})
repat_totals
repat_totals
Country | Year | Number_Repatriated_Victims | |
---|---|---|---|
0 | Albania | 2014 | 5.0 |
1 | Albania | 2016 | 5.0 |
2 | Albania | 2017 | 21.0 |
3 | Albania | 2018 | 21.0 |
4 | Albania | 2019 | 10.0 |
... | ... | ... | ... |
231 | United Kingdom of Great Britain and Northern I... | 2012 | 47.0 |
232 | United Kingdom of Great Britain and Northern I... | 2013 | 30.0 |
233 | United Kingdom of Great Britain and Northern I... | 2014 | 29.0 |
234 | United Kingdom of Great Britain and Northern I... | 2015 | 23.0 |
235 | United Kingdom of Great Britain and Northern I... | 2016 | 114.0 |
236 rows × 3 columns