American Lawful Immigration 2018 : New LPRs by State of Residence

Posted on mar. 13 octobre 2020 in Politics • 7 min read

American Lawful Immigration 2018 - New LPRs by State of Residence


Legal Permanent Residents (LPRs) are non-citizens who are lawfully authorized to live permanently within the United States. Let's explore data from the U.S. Department of Homeland Security to highlight the states in which people who received a green card in 2018 settled.

Import required libraries

In [1]:
import pandas as pd
import plotly.express as px
import plotly.io as pio
from IPython.display import Javascript

Javascript(
"""require.config({
 paths: { 
     plotly: 'https://cdn.plot.ly/plotly-latest.min'
 }
});"""
)

pio.renderers.default = 'notebook_connected'

Data pre-processing

To map the figures of american new Legal Permanent Residents by state of residence in 2018, we need to merge three datasets :

  • The Persons Obtaining Legal Permanent Resident Status by State or Territory of Residence dataset, which is our main dataset containing among other things for each state of residence the number of new LPRs in 2018;
  • The US State Abbreviations dataset, which allows us to merge, for each state of residence, the associated state abreviation;
  • The US Population 2018 dataset, which gives us the numbers of inhabitants of each US state in 2018.

LPRs 2018 by state of residence dataset

In [2]:
df = pd.read_csv('Data/Persons_Obtaining_Lawful_Permanent_Resident_Status_by_State_or_Territory_of_Residence.csv', 
                 sep=';', 
                 skiprows=4)

# Cleaning
df.drop(df.iloc[:, 1:10], inplace = True, axis = 1)
df.columns = ['State or territory of residence', 'LPRs 2018']
df.dropna(inplace=True)
df['LPRs 2018'] = df['LPRs 2018'].str.replace(" ", "")
df['LPRs 2018'] = df['LPRs 2018'].astype('int')

df.head()
Out[2]:
State or territory of residence LPRs 2018
0 Alabama 3737
1 Alaska 1375
2 Arizona 18335
3 Arkansas 3000
4 California 200897

US State Abbreviations dataset

In [3]:
df_state = pd.read_csv('Data/US_State_Abbreviations.csv', 
                       sep=';')

df_state.rename(columns = {'State':'State or territory of residence'}, inplace = True)

df_state.head()
Out[3]:
State or territory of residence Code
0 Alabama AL
1 Alaska AK
2 Arizona AZ
3 Arkansas AR
4 California CA

US Population 2018 dataset

In [4]:
df_pop = pd.read_csv('Data/US_Population_2018.csv', 
                     sep=';', 
                     skiprows=8)

# Cleaning
df_pop.drop(df_pop.iloc[:, 1:11], inplace = True, axis = 1)
df_pop = df_pop.iloc[:, :-1]
df_pop.columns = ['State or territory of residence', 'US Population 2018']
df_pop.dropna(inplace=True)
df_pop['US Population 2018'] = df_pop['US Population 2018'].str.replace(" ", "")
df_pop['US Population 2018'] = df_pop['US Population 2018'].astype('int')

df_pop.head()
Out[4]:
State or territory of residence US Population 2018
0 Alabama 4887681
1 Alaska 735139
2 Arizona 7158024
3 Arkansas 3009733
4 California 39461588

Merging

Now our three datasets are clean, they can be merged. To this, we add two columns that will make the data more meaningful :

  • The percentage of new LPRs 2018;
  • The new LPRs 2018 per 1,000 population.
In [5]:
#Merge LPRs 2018 by state of residence and US State Abbreviations datasets
df_merge = pd.merge(df, df_state, on='State or territory of residence')

#Compute and add Percentage of LPRs 2018 column
df_merge['Percentage of LPRs 2018'] = df_merge['LPRs 2018']/df_merge['LPRs 2018'].sum()*100

#Merge US Population 2018 dataset to the previous merge, giving us our final dataset
df_LPRs_2018 = pd.merge(df_merge, df_pop, on='State or territory of residence')

#Compute and add LPRs 2018 per 1,000 population column
df_LPRs_2018['LPRs 2018 per 1,000 population'] = df_LPRs_2018['LPRs 2018']/df_LPRs_2018['US Population 2018']*1000

df_LPRs_2018 = df_LPRs_2018.sort_values('LPRs 2018', ascending=False)
df_LPRs_2018
Out[5]:
State or territory of residence LPRs 2018 Code Percentage of LPRs 2018 US Population 2018 LPRs 2018 per 1,000 population
4 California 200897 CA 18.350529 39461588 5.090951
32 New York 134839 NY 12.316595 19530351 6.904075
9 Florida 130405 FL 11.911580 21244317 6.138347
44 Texas 104515 TX 9.546711 28628666 3.650711
30 New Jersey 54424 NJ 4.971250 8886025 6.124673
13 Illinois 38287 IL 3.497248 12723071 3.009258
21 Massachusetts 33174 MA 3.030212 6882635 4.819956
47 Virginia 27426 VA 2.505172 8501286 3.226100
10 Georgia 26725 GA 2.441141 10511131 2.542543
38 Pennsylvania 26078 PA 2.382042 12800922 2.037197
48 Washington 26029 WA 2.377566 7523869 3.459523
20 Maryland 24301 MD 2.219726 6035802 4.026143
33 North Carolina 20838 NC 1.903405 10381615 2.007202
22 Michigan 19850 MI 1.813158 9984072 1.988167
35 Ohio 18809 OH 1.718070 11676341 1.610864
2 Arizona 18335 AZ 1.674773 7158024 2.561461
23 Minnesota 16721 MN 1.527346 5606249 2.982565
5 Colorado 13913 CO 1.270855 5691287 2.444614
6 Connecticut 11629 CT 1.062227 3571520 3.256037
28 Nevada 10851 NV 0.991163 3027341 3.584334
14 Indiana 9741 IN 0.889772 6695497 1.454858
37 Oregon 9679 OR 0.884109 4181886 2.314506
43 Tennessee 9590 TN 0.875979 6771631 1.416202
17 Kentucky 8734 KY 0.797790 4461153 1.957790
25 Missouri 7638 MO 0.697678 6121623 1.247708
50 Wisconsin 7433 WI 0.678952 5807406 1.279917
27 Nebraska 6500 NE 0.593729 1925614 3.375547
36 Oklahoma 5938 OK 0.542395 3940235 1.507017
45 Utah 5723 UT 0.522756 3153550 1.814780
16 Kansas 5630 KS 0.514261 2911359 1.933805
15 Iowa 5484 IA 0.500925 3148618 1.741717
11 Hawaii 5430 HI 0.495992 1420593 3.822347
41 South Carolina 5078 SC 0.463840 5084156 0.998789
18 Louisiana 4889 LA 0.446576 4659690 1.049211
40 Rhode Island 4336 RI 0.396063 1058287 4.097187
31 New Mexico 4296 NM 0.392409 2092741 2.052810
0 Alabama 3737 AL 0.341349 4887681 0.764575
39 Puerto Rico 3062 PR 0.279692 3193354 0.958866
3 Arkansas 3000 AR 0.274029 3009733 0.996766
8 District of Columbia 2775 DC 0.253477 701547 3.955544
12 Idaho 2728 ID 0.249184 1750536 1.558380
29 New Hampshire 2200 NH 0.200955 1353465 1.625458
7 Delaware 1831 DE 0.167249 965479 1.896468
19 Maine 1749 ME 0.159759 1339057 1.306143
34 North Dakota 1674 ND 0.152908 758080 2.208210
24 Mississippi 1643 MS 0.150076 2981020 0.551154
1 Alaska 1375 AK 0.125597 735139 1.870395
42 South Dakota 1132 SD 0.103400 878698 1.288270
46 Vermont 824 VT 0.075267 624358 1.319756
49 West Virginia 675 WV 0.061657 1804291 0.374108
26 Montana 565 MT 0.051609 1060665 0.532685
51 Wyoming 409 WY 0.037359 577601 0.708101

Mapping

New LPRs by state of residence in 2018

First, we want to represent the number of new LPRs by state of residence in 2018 :

In [6]:
fig = px.choropleth(df_LPRs_2018, 
                    locations='Code',
                    color='LPRs 2018',
                    hover_name='State or territory of residence',
                    locationmode="USA-states",
                    scope='usa',
                    labels={'LPRs 2018':'New LPRs'},
                    color_continuous_scale=px.colors.sequential.dense,
                    title="<b>U.S. New LPRs by State of Residence in 2018</b><br>" + 
                    "<i>Source : U.S. Department of Homeland Security</i>"
                   )

# Style
fig.update_layout(
    font_family='Helvetica',
    font_color='grey',
    font_size=12,
    title_font_size=18
)

fig.show()
In [7]:
fig = px.treemap(df_LPRs_2018,
                 title="<b>U.S. New LPRs by State of Residence in 2018</b><br>" + 
                 "<i>Source : U.S. Department of Homeland Security</i>",
                 labels={'LPRs 2018':'New LPRs', 'State or territory of residence':''},
                 path=['State or territory of residence'], 
                 values='LPRs 2018',
                 color = 'LPRs 2018',
                 color_continuous_scale=px.colors.sequential.dense
                )

# Style
fig.update_layout(
    font_family='Helvetica',
    font_color='grey',
    font_size=12,
    title_font_size=18
)

fig.show()

New LPRs by state of residence per 1,000 population in 2018

Now, we want to represent the number of new LPRs by state of residence per 1,000 population in 2018 :

In [8]:
df_LPRs_1000_population = df_LPRs_2018.sort_values('LPRs 2018 per 1,000 population', ascending=False)
df_LPRs_1000_population
Out[8]:
State or territory of residence LPRs 2018 Code Percentage of LPRs 2018 US Population 2018 LPRs 2018 per 1,000 population
32 New York 134839 NY 12.316595 19530351 6.904075
9 Florida 130405 FL 11.911580 21244317 6.138347
30 New Jersey 54424 NJ 4.971250 8886025 6.124673
4 California 200897 CA 18.350529 39461588 5.090951
21 Massachusetts 33174 MA 3.030212 6882635 4.819956
40 Rhode Island 4336 RI 0.396063 1058287 4.097187
20 Maryland 24301 MD 2.219726 6035802 4.026143
8 District of Columbia 2775 DC 0.253477 701547 3.955544
11 Hawaii 5430 HI 0.495992 1420593 3.822347
44 Texas 104515 TX 9.546711 28628666 3.650711
28 Nevada 10851 NV 0.991163 3027341 3.584334
48 Washington 26029 WA 2.377566 7523869 3.459523
27 Nebraska 6500 NE 0.593729 1925614 3.375547
6 Connecticut 11629 CT 1.062227 3571520 3.256037
47 Virginia 27426 VA 2.505172 8501286 3.226100
13 Illinois 38287 IL 3.497248 12723071 3.009258
23 Minnesota 16721 MN 1.527346 5606249 2.982565
2 Arizona 18335 AZ 1.674773 7158024 2.561461
10 Georgia 26725 GA 2.441141 10511131 2.542543
5 Colorado 13913 CO 1.270855 5691287 2.444614
37 Oregon 9679 OR 0.884109 4181886 2.314506
34 North Dakota 1674 ND 0.152908 758080 2.208210
31 New Mexico 4296 NM 0.392409 2092741 2.052810
38 Pennsylvania 26078 PA 2.382042 12800922 2.037197
33 North Carolina 20838 NC 1.903405 10381615 2.007202
22 Michigan 19850 MI 1.813158 9984072 1.988167
17 Kentucky 8734 KY 0.797790 4461153 1.957790
16 Kansas 5630 KS 0.514261 2911359 1.933805
7 Delaware 1831 DE 0.167249 965479 1.896468
1 Alaska 1375 AK 0.125597 735139 1.870395
45 Utah 5723 UT 0.522756 3153550 1.814780
15 Iowa 5484 IA 0.500925 3148618 1.741717
29 New Hampshire 2200 NH 0.200955 1353465 1.625458
35 Ohio 18809 OH 1.718070 11676341 1.610864
12 Idaho 2728 ID 0.249184 1750536 1.558380
36 Oklahoma 5938 OK 0.542395 3940235 1.507017
14 Indiana 9741 IN 0.889772 6695497 1.454858
43 Tennessee 9590 TN 0.875979 6771631 1.416202
46 Vermont 824 VT 0.075267 624358 1.319756
19 Maine 1749 ME 0.159759 1339057 1.306143
42 South Dakota 1132 SD 0.103400 878698 1.288270
50 Wisconsin 7433 WI 0.678952 5807406 1.279917
25 Missouri 7638 MO 0.697678 6121623 1.247708
18 Louisiana 4889 LA 0.446576 4659690 1.049211
41 South Carolina 5078 SC 0.463840 5084156 0.998789
3 Arkansas 3000 AR 0.274029 3009733 0.996766
39 Puerto Rico 3062 PR 0.279692 3193354 0.958866
0 Alabama 3737 AL 0.341349 4887681 0.764575
51 Wyoming 409 WY 0.037359 577601 0.708101
24 Mississippi 1643 MS 0.150076 2981020 0.551154
26 Montana 565 MT 0.051609 1060665 0.532685
49 West Virginia 675 WV 0.061657 1804291 0.374108
In [9]:
fig = px.choropleth(df_LPRs_1000_population, 
                    locations='Code',
                    color='LPRs 2018 per 1,000 population',
                    hover_name='State or territory of residence',
                    locationmode="USA-states",
                    scope='usa',
                    labels={'LPRs 2018 per 1,000 population':'New LPRs per<br>1,000 inhabitants'},
                    color_continuous_scale=px.colors.sequential.matter,
                    title="<b>U.S. New LPRs by State of Residence per 1,000 inhabitants in 2018</b><br>" + 
                    "<i>Source : U.S. Department of Homeland Security</i>"
                   )

# Style
fig.update_layout(
    font_family='Helvetica',
    font_color='grey',
    font_size=12,
    title_font_size=18
)

fig.show()
In [10]:
fig = px.treemap(df_LPRs_1000_population,
                 title="<b>U.S. New LPRs by State of Residence per 1,000 inhabitants in 2018</b><br>" + 
                 "<i>Source : U.S. Department of Homeland Security</i>",
                 labels={'LPRs 2018 per 1,000 population':'New LPRs per<br>1,000 inhabitants', 'State or territory of residence':''},
                 path=['State or territory of residence'], 
                 values='LPRs 2018 per 1,000 population',
                 color = 'LPRs 2018 per 1,000 population',
                 color_continuous_scale=px.colors.sequential.matter
                )

# Style
fig.update_layout(
    font_family='Helvetica',
    font_color='grey',
    font_size=12,
    title_font_size=18
)

fig.show()

Sources

In [ ]: