import pandas as pd
# UNODC human trafficking dataframe with additional data on citizenship of victims / traffickers
repats = pd.read_excel('../../data/raw-data/UNODC_TIP_data.xlsx', skiprows=2) # remove first two rows
# 1. subset to Region == "Europe"
repats = repats[repats['Region'] == 'Europe']
# 2. subset indicator to only detected trafficking victims
repats = repats[repats['Indicator'] == 'Detected trafficking victims']
# 3. subset dimension column to only include "Total" and "by country of repatriation"
repats = repats[repats['Dimension'].isin(['Total', 'by country of repatriation'])]
# 4. subset to the Sex == "Total"
repats = repats[repats['Sex'] == 'Total']
# 5. subset to Age == "Total"
repats = repats[repats['Age'] == 'Total']
# 6. rename txtVALUE --> "Counts"
repats = repats.rename(columns={'txtVALUE': 'Counts'})
# 7. convert observations where Counts = "<5" to numeric value 5
repats['Counts'] = repats['Counts'].replace("<5", 5)
repats['Counts'] = pd.to_numeric(repats['Counts'], errors='coerce')
# 8. remove unnecessary columns
columns_to_drop = ['Iso3_code', 'Region', 'Sex', 'Age', 'Unit of measurement', 'Source']
repats = repats.drop(columns=columns_to_drop)
# 9. group and get the sum of total repatriated victims for each country each year
foreign_victims = repats[
(repats['Dimension'] == 'by country of repatriation') &
(repats['Category'] != repats['Country'])
]
repat_totals = foreign_victims.groupby(['Country', 'Year'])['Counts'].sum().reset_index()
repat_totals = repat_totals.rename(columns = {'Counts': 'Number_Repatriated_Victims'})
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