国連の難民データを使ったpandasのtutorial

今回はこのサイトのpandasのtutorialをやる。UNHCR(UN Refugee Agency:国際連合難民高等弁務官事務所)のデータを使用しているチュートリアルで非常に興味深い。

スポンサーリンク

環境設定

今回のtutorialのためのフォルダ作成とデータのダウンロードから始める。

mkdir refu
cd refu
/home/workspace/refu

このサイトからデータをダウンロードフォルダにダウンロードしてから、上で作成した作業用フォルダに移動する。

!mv ../download/unhcr_popstats_export_persons_of_concern_all_data.csv .

データのロード

モジュールをインポートしてデータをロードする。

%matplotlib inline
import pandas as pd
# Reading in the first table
persons = pd.read_csv('unhcr_popstats_export_persons_of_concern_all_data.csv'\
                      , skiprows=4, encoding = "ISO-8859-1")
/root/.pyenv/versions/py365/lib/python3.6/site-packages/IPython/core/interactiveshell.py:2785: DtypeWarning: Columns (3,4,5,8,9,10) have mixed types. Specify dtype option on import or set low_memory=False.
  interactivity=interactivity, compiler=compiler, result=result)
# Showing top 5 rows

persons.head()
1951 Australia Various/Unknown 180000 Unnamed: 4 Unnamed: 5 Unnamed: 6 Unnamed: 7 Unnamed: 8 Unnamed: 9 180000.1
0 1951 Austria Various/Unknown 282000 NaN NaN NaN NaN NaN NaN 282000
1 1951 Belgium Various/Unknown 55000 NaN NaN NaN NaN NaN NaN 55000
2 1951 Canada Various/Unknown 168511 NaN NaN NaN NaN NaN NaN 168511
3 1951 Switzerland Various/Unknown 10000 NaN NaN NaN NaN NaN NaN 10000
4 1951 Germany Various/Unknown 265000 NaN NaN NaN NaN NaN NaN 265000
# Showing last 5 rows

persons.tail()
1951 Australia Various/Unknown 180000 Unnamed: 4 Unnamed: 5 Unnamed: 6 Unnamed: 7 Unnamed: 8 Unnamed: 9 180000.1
124463 2017 Zimbabwe Syrian Arab Rep. 0 0 0 0.0 0.0 0 * *
124464 2017 Zimbabwe Uganda 8 * 0 0.0 0.0 0 * 13
124465 2017 Zimbabwe South Africa * 9 0 0.0 0.0 0 5 15
124466 2017 Zimbabwe Zambia 0 0 0 0.0 0.0 0 * *
124467 2017 Zimbabwe Zimbabwe 0 0 38 0.0 0.0 0 137 175
# Let's get summary information

persons.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 124468 entries, 0 to 124467
Data columns (total 11 columns):
1951               124468 non-null int64
Australia          124468 non-null object
Various/Unknown    124468 non-null object
180000             108643 non-null object
Unnamed: 4         81777 non-null object
Unnamed: 5         33748 non-null object
Unnamed: 6         27971 non-null float64
Unnamed: 7         27769 non-null float64
Unnamed: 8         28152 non-null object
Unnamed: 9         28232 non-null object
180000.1           124468 non-null object
dtypes: float64(2), int64(1), object(8)
memory usage: 10.4+ MB
# Re-read in the data

persons = pd.read_csv('unhcr_popstats_export_persons_of_concern_all_data.csv'\
                      , header=3, na_values = '*', encoding = "latin1")
# Checking if we resolved the issues

persons.tail()
Year Country / territory of asylum/residence Origin Refugees (incl. refugee-like situations) Asylum-seekers (pending cases) Returned refugees Internally displaced persons (IDPs) Returned IDPs Stateless persons Others of concern Total Population
124464 2017 Zimbabwe Syrian Arab Rep. 0.0 0.0 0.0 0.0 0.0 0.0 NaN NaN
124465 2017 Zimbabwe Uganda 8.0 NaN 0.0 0.0 0.0 0.0 NaN 13.0
124466 2017 Zimbabwe South Africa NaN 9.0 0.0 0.0 0.0 0.0 5.0 15.0
124467 2017 Zimbabwe Zambia 0.0 0.0 0.0 0.0 0.0 0.0 NaN NaN
124468 2017 Zimbabwe Zimbabwe 0.0 0.0 38.0 0.0 0.0 0.0 137.0 175.0
persons.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 124469 entries, 0 to 124468
Data columns (total 11 columns):
Year                                        124469 non-null int64
Country / territory of asylum/residence     124469 non-null object
Origin                                      124469 non-null object
Refugees (incl. refugee-like situations)    106575 non-null float64
Asylum-seekers (pending cases)              79698 non-null float64
Returned refugees                           33735 non-null float64
Internally displaced persons (IDPs)         27971 non-null float64
Returned IDPs                               27769 non-null float64
Stateless persons                           28150 non-null float64
Others of concern                           28136 non-null float64
Total Population                            121939 non-null float64
dtypes: float64(8), int64(1), object(2)
memory usage: 10.4+ MB

pandasによるデータいじり

分析に邪魔な長ったらしい列名を短くする。

per_renamed = persons.rename(index=str, columns ={'Country / territory of asylum/residence': 'Residence',
                                    'Refugees (incl. refugee-like situations)': 'Refugees',
                                    'Asylum-seekers (pending cases)': 'Asylum-seekers',
                                    'Internally displaced persons (IDPs)': 'IDPs'})
per_renamed.head()
Year Residence Origin Refugees Asylum-seekers Returned refugees IDPs Returned IDPs Stateless persons Others of concern Total Population
0 1951 Australia Various/Unknown 180000.0 NaN NaN NaN NaN NaN NaN 180000.0
1 1951 Austria Various/Unknown 282000.0 NaN NaN NaN NaN NaN NaN 282000.0
2 1951 Belgium Various/Unknown 55000.0 NaN NaN NaN NaN NaN NaN 55000.0
3 1951 Canada Various/Unknown 168511.0 NaN NaN NaN NaN NaN NaN 168511.0
4 1951 Switzerland Various/Unknown 10000.0 NaN NaN NaN NaN NaN NaN 10000.0

特定のコラムを見るにはどうすればいいのか?

per_renamed['Origin']
0                Various/Unknown
1                Various/Unknown
2                Various/Unknown
3                Various/Unknown
4                Various/Unknown
5                Various/Unknown
6                Various/Unknown
7                Various/Unknown
8                Various/Unknown
9                Various/Unknown
10               Various/Unknown
11               Various/Unknown
12               Various/Unknown
13               Various/Unknown
14               Various/Unknown
15               Various/Unknown
16               Various/Unknown
17               Various/Unknown
18               Various/Unknown
19               Various/Unknown
20               Various/Unknown
21               Various/Unknown
22               Various/Unknown
23               Various/Unknown
24               Various/Unknown
25               Various/Unknown
26               Various/Unknown
27               Various/Unknown
28               Various/Unknown
29               Various/Unknown
                   ...          
124439                    Turkey
124440                    Uganda
124441                   Ukraine
124442           Various/Unknown
124443              South Africa
124444                  Zimbabwe
124445                    Angola
124446                   Burundi
124447                  Botswana
124448      Central African Rep.
124449            Côte d'Ivoire
124450    Dem. Rep. of the Congo
124451                     Congo
124452                     Egypt
124453                   Eritrea
124454                  Ethiopia
124455                     Ghana
124456                     Kenya
124457                   Lebanon
124458                      Mali
124459                Mozambique
124460                    Rwanda
124461                     Sudan
124462                   Somalia
124463                  Slovenia
124464          Syrian Arab Rep.
124465                    Uganda
124466              South Africa
124467                    Zambia
124468                  Zimbabwe
Name: Origin, Length: 124469, dtype: object

何カ国から難民や亡命者が来ているのかを見る。

per_renamed['Origin'].nunique()
225

ソマリアから来た難民にスポットを当てる。

somali = per_renamed[per_renamed['Origin'] == 'Somalia']
somali
Year Residence Origin Refugees Asylum-seekers Returned refugees IDPs Returned IDPs Stateless persons Others of concern Total Population
1230 1975 Zambia Somalia 110.0 NaN NaN NaN NaN NaN NaN 110.0
1283 1976 Kenya Somalia 50.0 NaN NaN NaN NaN NaN NaN 50.0
1391 1977 Kenya Somalia 60.0 NaN NaN NaN NaN NaN NaN 60.0
1528 1978 Kenya Somalia 90.0 NaN NaN NaN NaN NaN NaN 90.0
1682 1979 Kenya Somalia 90.0 NaN NaN NaN NaN NaN NaN 90.0
1871 1980 Italy Somalia 34.0 NaN NaN NaN NaN NaN NaN 34.0
1889 1980 Kenya Somalia 100.0 NaN NaN NaN NaN NaN NaN 100.0
2086 1981 Italy Somalia 34.0 NaN NaN NaN NaN NaN NaN 34.0
2314 1982 Italy Somalia 38.0 NaN NaN NaN NaN NaN NaN 38.0
2334 1982 Kenya Somalia 80.0 NaN NaN NaN NaN NaN NaN 80.0
2577 1983 Italy Somalia 39.0 NaN NaN NaN NaN NaN NaN 39.0
2852 1984 Italy Somalia 39.0 NaN NaN NaN NaN NaN NaN 39.0
2878 1984 Kuwait Somalia 100.0 NaN NaN NaN NaN NaN NaN 100.0
2935 1984 Saudi Arabia Somalia 500.0 NaN NaN NaN NaN NaN NaN 500.0
2995 1985 United Arab Emirates Somalia 500.0 NaN NaN NaN NaN NaN NaN 500.0
3012 1985 Bahrain Somalia 50.0 NaN NaN NaN NaN NaN NaN 50.0
3152 1985 Italy Somalia 40.0 NaN NaN NaN NaN NaN NaN 40.0
3173 1985 Kenya Somalia 90.0 NaN NaN NaN NaN NaN NaN 90.0
3180 1985 Kuwait Somalia 150.0 NaN NaN NaN NaN NaN NaN 150.0
3236 1985 Saudi Arabia Somalia 1000.0 NaN NaN NaN NaN NaN NaN 1000.0
3409 1986 Iraq Somalia 1000.0 NaN NaN NaN NaN NaN NaN 1000.0
3455 1986 Italy Somalia 32.0 NaN NaN NaN NaN NaN NaN 32.0
3474 1986 Kenya Somalia 110.0 NaN NaN NaN NaN NaN NaN 110.0
3533 1986 Saudi Arabia Somalia 2000.0 NaN NaN NaN NaN NaN NaN 2000.0
3669 1987 Ethiopia Somalia 60000.0 NaN NaN NaN NaN NaN NaN 60000.0
3741 1987 Italy Somalia 22.0 NaN NaN NaN NaN NaN NaN 22.0
3762 1987 Kenya Somalia 140.0 NaN NaN NaN NaN NaN NaN 140.0
3950 1988 Egypt Somalia 600.0 NaN NaN NaN NaN NaN NaN 600.0
3954 1988 Ethiopia Somalia 350067.0 NaN NaN NaN NaN NaN NaN 350067.0
4009 1988 United Kingdom Somalia 411.0 NaN NaN NaN NaN NaN NaN 411.0
123046 2017 Portugal Somalia 51.0 0.0 0.0 0.0 0.0 0.0 0.0 51.0
123087 2017 Qatar Somalia 8.0 0.0 0.0 0.0 0.0 0.0 0.0 8.0
123138 2017 Romania Somalia 43.0 11.0 0.0 0.0 0.0 0.0 0.0 54.0
123195 2017 Russian Federation Somalia 0.0 NaN 0.0 0.0 0.0 0.0 0.0 NaN
123220 2017 Rwanda Somalia NaN NaN 0.0 0.0 0.0 0.0 NaN 8.0
123234 2017 Saudi Arabia Somalia 16.0 0.0 0.0 0.0 0.0 0.0 0.0 16.0
123265 2017 Sudan Somalia 208.0 146.0 0.0 0.0 0.0 0.0 0.0 354.0
123314 2017 Senegal Somalia NaN 8.0 0.0 0.0 0.0 0.0 0.0 10.0
123358 2017 Somalia Somalia 0.0 0.0 41479.0 2116705.0 0.0 0.0 114.0 2158298.0
123394 2017 Serbia and Kosovo (S/RES/1244 (1999)) Somalia NaN 17.0 0.0 0.0 0.0 0.0 0.0 20.0
123415 2017 South Sudan Somalia NaN 28.0 0.0 0.0 0.0 0.0 0.0 30.0
123463 2017 Slovakia Somalia 31.0 0.0 0.0 0.0 0.0 0.0 NaN 35.0
123497 2017 Slovenia Somalia 48.0 NaN 0.0 0.0 0.0 0.0 0.0 50.0
123631 2017 Sweden Somalia 21973.0 2326.0 0.0 0.0 0.0 0.0 0.0 24299.0
123675 2017 Swaziland Somalia 73.0 140.0 0.0 0.0 0.0 0.0 0.0 213.0
123709 2017 Syrian Arab Rep. Somalia 404.0 0.0 0.0 0.0 0.0 0.0 0.0 404.0
123743 2017 Chad Somalia 10.0 NaN 0.0 0.0 0.0 0.0 0.0 12.0
123774 2017 Togo Somalia NaN 0.0 0.0 0.0 0.0 0.0 0.0 NaN
123818 2017 Thailand Somalia 223.0 134.0 0.0 0.0 0.0 0.0 0.0 357.0
123886 2017 Tunisia Somalia 9.0 0.0 0.0 0.0 0.0 0.0 0.0 9.0
123953 2017 Turkey Somalia 2219.0 2145.0 0.0 0.0 0.0 0.0 0.0 4364.0
123972 2017 United Rep. of Tanzania Somalia 150.0 0.0 0.0 0.0 0.0 0.0 0.0 150.0
123996 2017 Uganda Somalia 25011.0 12182.0 0.0 0.0 0.0 0.0 0.0 37193.0
124067 2017 Ukraine Somalia 132.0 306.0 0.0 0.0 0.0 0.0 0.0 438.0
124129 2017 Uruguay Somalia NaN 0.0 0.0 0.0 0.0 0.0 0.0 NaN
124292 2017 United States of America Somalia 2297.0 550.0 0.0 0.0 0.0 0.0 0.0 2847.0
124387 2017 Yemen Somalia 255894.0 0.0 0.0 0.0 0.0 0.0 NaN 255895.0
124417 2017 South Africa Somalia 26977.0 4014.0 0.0 0.0 0.0 0.0 0.0 30991.0
124437 2017 Zambia Somalia 2174.0 551.0 0.0 0.0 0.0 0.0 0.0 2725.0
124462 2017 Zimbabwe Somalia 19.0 8.0 0.0 0.0 0.0 0.0 9.0 36.0

2545 rows × 11 columns

2000〜2017年にアメリカに来た難民に焦点を当てる。

somali_us = somali[(somali['Residence'] == 'United States of America') & 
                   (somali['Year'] >= 2000) & (somali['Year'] <= 2017)]
somali_us
Year Residence Origin Refugees Asylum-seekers Returned refugees IDPs Returned IDPs Stateless persons Others of concern Total Population
26770 2000 United States of America Somalia 34005.0 1802.0 NaN NaN NaN NaN NaN 35807.0
31055 2001 United States of America Somalia 33750.0 1804.0 NaN NaN NaN NaN NaN 35554.0
35594 2002 United States of America Somalia 28693.0 1283.0 NaN NaN NaN NaN NaN 29976.0
40372 2003 United States of America Somalia 25421.0 1000.0 NaN NaN NaN NaN NaN 26421.0
45251 2004 United States of America Somalia 31110.0 812.0 NaN NaN NaN NaN NaN 31922.0
50333 2005 United States of America Somalia 34207.0 610.0 NaN NaN NaN NaN NaN 34817.0
55589 2006 United States of America Somalia 72546.0 510.0 NaN NaN NaN NaN NaN 73056.0
61035 2007 United States of America Somalia 12224.0 305.0 NaN NaN NaN NaN NaN 12529.0
66573 2008 United States of America Somalia 10154.0 223.0 NaN NaN NaN NaN NaN 10377.0
72166 2009 United States of America Somalia 7112.0 158.0 NaN NaN NaN NaN NaN 7270.0
78052 2010 United States of America Somalia 4513.0 48.0 NaN NaN NaN NaN NaN 4561.0
84004 2011 United States of America Somalia 2996.0 57.0 NaN NaN NaN NaN NaN 3053.0
90140 2012 United States of America Somalia 2412.0 0.0 NaN NaN NaN NaN NaN 2412.0
96637 2013 United States of America Somalia 2310.0 329.0 NaN NaN NaN NaN NaN 2639.0
103313 2014 United States of America Somalia 2263.0 351.0 0.0 0.0 0.0 0.0 0.0 2614.0
110207 2015 United States of America Somalia 2313.0 669.0 0.0 0.0 0.0 0.0 0.0 2982.0
117121 2016 United States of America Somalia 2319.0 638.0 0.0 0.0 0.0 0.0 0.0 2957.0
124292 2017 United States of America Somalia 2297.0 550.0 0.0 0.0 0.0 0.0 0.0 2847.0

上の数値データを時系列でプロットする。

# Selecting the population-data columns that do not have null values

pops = somali_us.select_dtypes(include=['float'])
pop_nonnull = pops.dropna(axis=1, how='any')
pop_nonnull.columns
Index(['Refugees', 'Asylum-seekers', 'Total Population'], dtype='object')
# Plotting the time series (don't worry if a UserWarning appears due to passing a list of values to the y parameter;
# this is a known issue in pandas and may be resolved in future versions of the library)
plt.rcParams['figure.figsize'] = 16, 8
plt.rcParams["font.size"] = "17"
pl = somali_us.plot(x='Year', y=pop_nonnull.columns)
pl.set_ylabel('Persons')
pl.set_title('Somali-to-U.S.')
Text(0.5,1,'Somali-to-U.S.')

テーブルのマージ

2つのテーブルはマージする。もう一つのテーブルはUNHCRが提供している1959年〜2017年の難民・亡命者数を居住国と出身国に分けてあるテーブル。前回同様、上述のサイトからデータをダウンロードして作業用フォルダに移動する。

!mv ../download/unhcr_popstats_export_resettlement_all_data.csv .
# Reading in resettlement table
resettle = pd.read_csv('unhcr_popstats_export_resettlement_all_data.csv', \
                       header=3, na_values = '*', encoding = "latin1")
resettle.head()
Country / territory of asylum/residence Origin Year Value
0 Canada Albania 1959 17.0
1 Canada Austria 1959 17.0
2 Canada Belgium 1959 2.0
3 Canada Bulgaria 1959 35.0
4 Canada China 1959 2.0

このデータをどうすればpersons-of-concern dataとマージできるのか?先ずResidence列をper_renamedデータフレームのネーミングコンベンションにマッチさせる。

# Also, rename "Value" to "Resettled"
resettle_renamed = resettle.rename(index=str, \
            columns ={'Country / territory of asylum/residence': 'Residence',
                                                        'Value': 'Resettled'})
resettle_renamed.head()
Residence Origin Year Resettled
0 Canada Albania 1959 17.0
1 Canada Austria 1959 17.0
2 Canada Belgium 1959 2.0
3 Canada Bulgaria 1959 35.0
4 Canada China 1959 2.0
# Remember per_renamed?

per_renamed.head()
Year Residence Origin Refugees Asylum-seekers Returned refugees IDPs Returned IDPs Stateless persons Others of concern Total Population
0 1951 Australia Various/Unknown 180000.0 NaN NaN NaN NaN NaN NaN 180000.0
1 1951 Austria Various/Unknown 282000.0 NaN NaN NaN NaN NaN NaN 282000.0
2 1951 Belgium Various/Unknown 55000.0 NaN NaN NaN NaN NaN NaN 55000.0
3 1951 Canada Various/Unknown 168511.0 NaN NaN NaN NaN NaN NaN 168511.0
4 1951 Switzerland Various/Unknown 10000.0 NaN NaN NaN NaN NaN NaN 10000.0

Year, Residence, Originのコンビネーションでマージさせるのが良い。また、再定住データが1959年からスタートしているので、1951〜1959年に対応したper_renamedの行をキープしたいのかどうかについて考える必要がある。同じYear/Residence/Originに該当する行があるかどうかにかかわらずに最初のデータフレームからの全データをキープしたい場合、(SQLのleft joinのように)mergeでhow=’left’を指定できる。

# Let's say we want to keep the earlier data

left_join = pd.merge(per_renamed, resettle_renamed, how='left', \
                     on = ['Year', 'Residence', 'Origin'])
left_join[left_join['Residence'] == 'Japan']    # focusing on those who resettled in Japan
Year Residence Origin Refugees Asylum-seekers Returned refugees IDPs Returned IDPs Stateless persons Others of concern Total Population Resettled
1386 1977 Japan Viet Nam 600.0 NaN NaN NaN NaN NaN NaN 600.0 NaN
1524 1978 Japan Viet Nam 610.0 NaN NaN NaN NaN NaN NaN 610.0 NaN
1678 1979 Japan Viet Nam 1260.0 NaN NaN NaN NaN NaN NaN 1260.0 NaN
1883 1980 Japan Cambodia 90.0 NaN NaN NaN NaN NaN NaN 90.0 NaN
1884 1980 Japan Lao People’s Dem. Rep. 220.0 NaN NaN NaN NaN NaN NaN 220.0 NaN
1885 1980 Japan Viet Nam 2080.0 NaN NaN NaN NaN NaN NaN 2080.0 NaN
2098 1981 Japan Cambodia 220.0 NaN NaN NaN NaN NaN NaN 220.0 NaN
2099 1981 Japan Lao People’s Dem. Rep. 500.0 NaN NaN NaN NaN NaN NaN 500.0 NaN
2100 1981 Japan Viet Nam 1800.0 NaN NaN NaN NaN NaN NaN 1800.0 NaN
2326 1982 Japan China 80.0 NaN NaN NaN NaN NaN NaN 80.0 NaN
2327 1982 Japan Cambodia 370.0 NaN NaN NaN NaN NaN NaN 370.0 NaN
2328 1982 Japan Lao People’s Dem. Rep. 610.0 NaN NaN NaN NaN NaN NaN 610.0 NaN
2329 1982 Japan Viet Nam 3230.0 NaN NaN NaN NaN NaN NaN 3230.0 NaN
2330 1982 Japan Various/Unknown 100.0 NaN NaN NaN NaN NaN NaN 100.0 NaN
2592 1983 Japan Cambodia 540.0 NaN NaN NaN NaN NaN NaN 540.0 NaN
2593 1983 Japan Lao People’s Dem. Rep. 580.0 NaN NaN NaN NaN NaN NaN 580.0 NaN
2594 1983 Japan Viet Nam 3630.0 NaN NaN NaN NaN NaN NaN 3630.0 NaN
2595 1983 Japan Various/Unknown 150.0 NaN NaN NaN NaN NaN NaN 150.0 NaN
2868 1984 Japan Iran (Islamic Rep. of) 50.0 NaN NaN NaN NaN NaN NaN 50.0 NaN
2869 1984 Japan Viet Nam 3917.0 NaN NaN NaN NaN NaN NaN 3917.0 NaN
3168 1985 Japan Viet Nam 4707.0 NaN NaN NaN NaN NaN NaN 4707.0 NaN
3469 1986 Japan Viet Nam 5016.0 NaN NaN NaN NaN NaN NaN 5016.0 NaN
3756 1987 Japan Viet Nam 5601.0 NaN NaN NaN NaN NaN NaN 5601.0 NaN
4109 1988 Japan Viet Nam 6110.0 NaN NaN NaN NaN NaN NaN 6110.0 NaN
4581 1989 Japan Lao People’s Dem. Rep. NaN NaN 1.0 NaN NaN NaN NaN 1.0 NaN
4582 1989 Japan Viet Nam 6479.0 NaN NaN NaN NaN NaN NaN 6479.0 NaN
5063 1990 Japan Lao People’s Dem. Rep. NaN NaN 1.0 NaN NaN NaN NaN 1.0 NaN
5064 1990 Japan Viet Nam 6819.0 NaN NaN NaN NaN NaN NaN 6819.0 NaN
5691 1991 Japan Viet Nam 6397.0 NaN NaN NaN NaN NaN NaN 6397.0 NaN
6369 1992 Japan Viet Nam 6669.0 NaN NaN NaN NaN NaN NaN 6669.0 NaN
121304 2017 Japan Burundi 8.0 0.0 0.0 0.0 0.0 0.0 0.0 8.0 NaN
121305 2017 Japan Bangladesh 27.0 1049.0 0.0 0.0 0.0 0.0 0.0 1076.0 NaN
121306 2017 Japan China 69.0 535.0 0.0 0.0 0.0 0.0 0.0 604.0 NaN
121307 2017 Japan Cameroon 17.0 218.0 0.0 0.0 0.0 0.0 0.0 235.0 NaN
121308 2017 Japan Dem. Rep. of the Congo 7.0 0.0 0.0 0.0 0.0 0.0 0.0 7.0 NaN
121309 2017 Japan Ethiopia 23.0 0.0 0.0 0.0 0.0 0.0 0.0 23.0 NaN
121310 2017 Japan Ghana 0.0 330.0 0.0 0.0 0.0 0.0 0.0 330.0 NaN
121311 2017 Japan Indonesia 0.0 2613.0 0.0 0.0 0.0 0.0 0.0 2613.0 NaN
121312 2017 Japan India 0.0 1257.0 0.0 0.0 0.0 0.0 0.0 1257.0 NaN
121313 2017 Japan Iran (Islamic Rep. of) 17.0 307.0 0.0 0.0 0.0 0.0 0.0 324.0 NaN
121314 2017 Japan Iraq 13.0 0.0 0.0 0.0 0.0 0.0 0.0 13.0 NaN
121315 2017 Japan Cambodia 0.0 1085.0 0.0 0.0 0.0 0.0 0.0 1085.0 NaN
121316 2017 Japan Sri Lanka 59.0 3549.0 0.0 0.0 0.0 0.0 0.0 3608.0 NaN
121317 2017 Japan Myanmar 1469.0 2241.0 0.0 0.0 0.0 0.0 0.0 3710.0 29.0
121318 2017 Japan Mongolia 0.0 70.0 0.0 0.0 0.0 0.0 0.0 70.0 NaN
121319 2017 Japan Nigeria 0.0 328.0 0.0 0.0 0.0 0.0 0.0 328.0 NaN
121320 2017 Japan Nepal 0.0 4520.0 0.0 0.0 0.0 0.0 0.0 4520.0 NaN
121321 2017 Japan Pakistan 34.0 1017.0 0.0 0.0 0.0 0.0 0.0 1051.0 NaN
121322 2017 Japan Philippines 0.0 5298.0 0.0 0.0 0.0 0.0 0.0 5298.0 NaN
121323 2017 Japan Sudan 15.0 0.0 0.0 0.0 0.0 0.0 0.0 15.0 NaN
121324 2017 Japan Senegal 0.0 141.0 0.0 0.0 0.0 0.0 0.0 141.0 NaN
121325 2017 Japan Somalia 5.0 0.0 0.0 0.0 0.0 0.0 0.0 5.0 NaN
121326 2017 Japan Syrian Arab Rep. 66.0 0.0 0.0 0.0 0.0 0.0 0.0 66.0 NaN
121327 2017 Japan Thailand 0.0 52.0 0.0 0.0 0.0 0.0 0.0 52.0 NaN
121328 2017 Japan Tunisia 0.0 155.0 0.0 0.0 0.0 0.0 0.0 155.0 NaN
121329 2017 Japan Turkey 39.0 2949.0 0.0 0.0 0.0 0.0 0.0 2988.0 NaN
121330 2017 Japan Uganda 0.0 160.0 0.0 0.0 0.0 0.0 0.0 160.0 NaN
121331 2017 Japan Viet Nam NaN 2490.0 0.0 0.0 0.0 0.0 0.0 2492.0 NaN
121332 2017 Japan Stateless 9.0 0.0 0.0 0.0 0.0 585.0 0.0 594.0 NaN
121333 2017 Japan Various/Unknown 261.0 840.0 0.0 0.0 0.0 0.0 0.0 1101.0 NaN

709 rows × 12 columns

left_join = pd.merge(per_renamed, resettle_renamed, how='left', \
                     on = ['Year', 'Residence', 'Origin'])
left_join[left_join['Residence'] == 'United States of America']
Year Residence Origin Refugees Asylum-seekers Returned refugees IDPs Returned IDPs Stateless persons Others of concern Total Population Resettled
20 1951 United States of America Various/Unknown 350000.0 NaN NaN NaN NaN NaN NaN 350000.0 NaN
37 1952 United States of America Various/Unknown 500000.0 NaN NaN NaN NaN NaN NaN 500000.0 NaN
54 1953 United States of America Various/Unknown 500000.0 NaN NaN NaN NaN NaN NaN 500000.0 NaN
74 1954 United States of America Various/Unknown 500000.0 NaN NaN NaN NaN NaN NaN 500000.0 NaN
90 1955 United States of America Various/Unknown 500000.0 NaN NaN NaN NaN NaN NaN 500000.0 NaN
106 1956 United States of America Various/Unknown 500000.0 NaN NaN NaN NaN NaN NaN 500000.0 NaN
122 1957 United States of America Various/Unknown 500000.0 NaN NaN NaN NaN NaN NaN 500000.0 NaN
140 1958 United States of America Various/Unknown 500000.0 NaN NaN NaN NaN NaN NaN 500000.0 NaN
158 1959 United States of America Various/Unknown 500000.0 NaN NaN NaN NaN NaN NaN 500000.0 NaN
177 1960 United States of America Various/Unknown 500000.0 NaN NaN NaN NaN NaN NaN 500000.0 NaN
202 1961 United States of America Various/Unknown 500000.0 NaN NaN NaN NaN NaN NaN 500000.0 NaN
228 1962 United States of America Various/Unknown 500000.0 NaN NaN NaN NaN NaN NaN 500000.0 NaN
257 1963 United States of America Various/Unknown 500000.0 NaN NaN NaN NaN NaN NaN 500000.0 NaN
298 1964 United States of America Various/Unknown 500000.0 NaN NaN NaN NaN NaN NaN 500000.0 NaN
345 1965 United States of America Various/Unknown 510000.0 NaN NaN NaN NaN NaN NaN 510000.0 NaN
396 1966 United States of America Various/Unknown 500000.0 NaN NaN NaN NaN NaN NaN 500000.0 NaN
448 1967 United States of America Various/Unknown 480000.0 NaN NaN NaN NaN NaN NaN 480000.0 NaN
516 1968 United States of America Various/Unknown 498000.0 NaN NaN NaN NaN NaN NaN 498000.0 NaN
600 1969 United States of America Various/Unknown 500000.0 NaN NaN NaN NaN NaN NaN 500000.0 NaN
706 1970 United States of America Various/Unknown 500000.0 NaN NaN NaN NaN NaN NaN 500000.0 NaN
807 1971 United States of America Various/Unknown 530000.0 NaN NaN NaN NaN NaN NaN 530000.0 NaN
926 1972 United States of America Various/Unknown 530000.0 NaN NaN NaN NaN NaN NaN 530000.0 NaN
1017 1973 United States of America Various/Unknown 530000.0 NaN NaN NaN NaN NaN NaN 530000.0 NaN
1116 1974 United States of America Various/Unknown 530000.0 NaN NaN NaN NaN NaN NaN 530000.0 NaN
1220 1975 United States of America Various/Unknown 530000.0 NaN NaN NaN NaN NaN NaN 530000.0 NaN
1329 1976 United States of America Various/Unknown 500000.0 NaN NaN NaN NaN NaN NaN 500000.0 NaN
1450 1977 United States of America Various/Unknown 684700.0 NaN NaN NaN NaN NaN NaN 684700.0 NaN
1598 1978 United States of America Various/Unknown 734000.0 NaN NaN NaN NaN NaN NaN 734000.0 NaN
1757 1979 United States of America Various/Unknown 734000.0 NaN NaN NaN NaN NaN NaN 734000.0 NaN
1960 1980 United States of America Various/Unknown 403684.0 NaN NaN NaN NaN NaN NaN 403684.0 NaN
124296 2017 United States of America Slovakia 10.0 15.0 0.0 0.0 0.0 0.0 0.0 25.0 NaN
124297 2017 United States of America Slovenia NaN 5.0 0.0 0.0 0.0 0.0 0.0 9.0 NaN
124298 2017 United States of America Sweden 8.0 8.0 0.0 0.0 0.0 0.0 0.0 16.0 NaN
124299 2017 United States of America Swaziland NaN 8.0 0.0 0.0 0.0 0.0 0.0 11.0 NaN
124300 2017 United States of America Seychelles NaN NaN 0.0 0.0 0.0 0.0 0.0 NaN NaN
124301 2017 United States of America Syrian Arab Rep. 7282.0 3358.0 0.0 0.0 0.0 0.0 0.0 10640.0 3024.0
124302 2017 United States of America Turks and Caicos Islands 14.0 0.0 0.0 0.0 0.0 0.0 0.0 14.0 NaN
124303 2017 United States of America Chad 335.0 218.0 0.0 0.0 0.0 0.0 0.0 553.0 NaN
124304 2017 United States of America Togo 604.0 494.0 0.0 0.0 0.0 0.0 0.0 1098.0 NaN
124305 2017 United States of America Thailand 29.0 465.0 0.0 0.0 0.0 0.0 0.0 494.0 NaN
124306 2017 United States of America Tajikistan 283.0 404.0 0.0 0.0 0.0 0.0 0.0 687.0 NaN
124307 2017 United States of America Turkmenistan 159.0 235.0 0.0 0.0 0.0 0.0 0.0 394.0 NaN
124308 2017 United States of America Tonga 0.0 11.0 0.0 0.0 0.0 0.0 0.0 11.0 NaN
124309 2017 United States of America Trinidad and Tobago 55.0 227.0 0.0 0.0 0.0 0.0 0.0 282.0 NaN
124310 2017 United States of America Tunisia 54.0 204.0 0.0 0.0 0.0 0.0 0.0 258.0 NaN
124311 2017 United States of America Turkey 428.0 2646.0 0.0 0.0 0.0 0.0 0.0 3074.0 NaN
124312 2017 United States of America United Rep. of Tanzania 133.0 154.0 0.0 0.0 0.0 0.0 0.0 287.0 NaN
124313 2017 United States of America Uganda 1301.0 1821.0 0.0 0.0 0.0 0.0 0.0 3122.0 44.0
124314 2017 United States of America Ukraine 1812.0 7574.0 0.0 0.0 0.0 0.0 0.0 9386.0 3089.0
124315 2017 United States of America Uruguay NaN 118.0 0.0 0.0 0.0 0.0 0.0 121.0 NaN
124316 2017 United States of America Uzbekistan 1210.0 1614.0 0.0 0.0 0.0 0.0 0.0 2824.0 39.0
124317 2017 United States of America Saint Vincent and the Grenadines 31.0 17.0 0.0 0.0 0.0 0.0 0.0 48.0 NaN
124318 2017 United States of America Venezuela (Bolivarian Republic of) 5402.0 58811.0 0.0 0.0 0.0 0.0 0.0 64213.0 NaN
124319 2017 United States of America Viet Nam 256.0 444.0 0.0 0.0 0.0 0.0 0.0 700.0 52.0
124320 2017 United States of America Stateless 455.0 0.0 0.0 0.0 0.0 0.0 0.0 455.0 NaN
124321 2017 United States of America Various/Unknown 4506.0 3604.0 0.0 0.0 0.0 0.0 0.0 8110.0 NaN
124322 2017 United States of America Yemen 549.0 908.0 0.0 0.0 0.0 0.0 0.0 1457.0 17.0
124323 2017 United States of America South Africa 40.0 294.0 0.0 0.0 0.0 0.0 0.0 334.0 NaN
124324 2017 United States of America Zambia 44.0 66.0 0.0 0.0 0.0 0.0 0.0 110.0 NaN
124325 2017 United States of America Zimbabwe 1049.0 768.0 0.0 0.0 0.0 0.0 0.0 1817.0 5.0

4497 rows × 12 columns

日本の難民受け入れは先進国としてはあまりにもお粗末過ぎる。アメリカと比べるとその差は歴然で、アメリカに次ぐ世界第二位の経済大国だった時期もあったのにもかかわらずにこの体たらくっぷりだ。日本は移民・難民をもっと受け入れる必要があるが、移民と外国人労働者(奴隷)の区別が付かない輩が多い国なので無理だろう。