Project Assignment 3
MAPPING THE ESTIMATED POVERTY RATE OF THE UNITED STATES, 2023
The 'Mapping the Estimated Poverty Rate of the United States, 2023' project aimed to analyze and visualize the poverty rate across states in the United States in 2023. Utilizing CyberGISX Notebook, this project calculated the 2023 U.S. poverty rate, comparing it to 2022's official poverty rate to discern trends. Additionally, this project identified states exceeding the average poverty rate and pinpointed the top five states with the highest poverty rates.
Poverty serves as a crucial socioeconomic metric, and comprehending how it is dispersed across the nation's landscapes can offer valuable insights into the economic well-being of communities and potential areas for targeted interventions. The U.S. Census Bureau announced the official poverty rate in 2022 was 11.5%, with 37.9 million people in poverty.
%matplotlib inline
import os
from geopandas import GeoSeries, GeoDataFrame, read_file, gpd
from pandas import Series
from matplotlib import pyplot as plt
import IPython
import geopandas as gpd
import matplotlib.pyplot as plt
total_pop = 'project/State.shp'
total_pop = gpd.read_file(total_pop)
total_pop[:3]
poverty_pop = 'project/poverty_us_2023.shp'
poverty_pop = gpd.read_file(poverty_pop)
poverty_pop[:3]
total_pop = total_pop.rename(columns={'NAME':'States'})
total_pop = total_pop.rename(columns={'TOTPOP_CY':'Total_pop'})
total_pop[:3]
poverty_pop = poverty_pop.rename(columns={'NAME': 'States'})
poverty_pop = poverty_pop.rename(columns={'B17020_003': 'Poverty_pop'})
poverty_pop[:3]
print(poverty_pop.columns)
print(total_pop.columns)
import geopandas as gpd
import matplotlib.pyplot as plt
# Create a bar chart to show poverty population for each state
plt.figure(figsize=(12,8))
poverty_pop.plot.bar(x='States', y='Poverty_pop', legend=None)
plt.xlabel('States')
plt.ylabel('Poverty Population')
plt.title('Poverty Population by State, 2023')
plt.xticks(rotation=90) # Rotate x-axis labels for better visibility
plt.tight_layout()
plt.show()
total_pop.crs = poverty_pop.crs
# Perform an inner join based on the 'States' column
merged_populations = poverty_pop.merge(total_pop, on='States', how='inner')
# Display the first few rows of the merged GeoDataFrame to verify the join
merged_populations.head()
# Perform the division and create a new column 'Poverty_Rate'
merged_populations['Poverty_rate'] = round(merged_populations['Poverty_pop'] / merged_populations['Total_pop'] * 100,2)
# Display the first few rows of the GeoDataFrame to verify the new column
merged_populations_gdf = gpd.GeoDataFrame(merged_populations, geometry='geometry_y')
merged_populations_gdf.head()
# To calculate mean poverty rate of the United States in 2023 and compare it with 2023
mean_2023_poverty_rate = round(merged_populations_gdf['Poverty_rate'].mean(),2)
print("Mean Poverty Rate for the United States:", mean_2023_poverty_rate,"%.")
poverty_rate_2022 = 11.5
# Calculate the change in poverty rate from 2022 to 2023
poverty_rate_change = mean_2023_poverty_rate - poverty_rate_2022
# Compare the change with the given threshold
if poverty_rate_change > 0:
print(f"The poverty rate increases by {poverty_rate_change:.2f} percentage from 2022 to 2023.")
print("This is higher than the 2022 poverty rate.")
elif poverty_rate_change < 0:
print(f"The poverty rate decreases by {-poverty_rate_change:.2f} percentage from 2022 to 2023.")
print("This is lower than the 2022 poverty rate.")
else:
print("The poverty rate remains the same from 2022 to 2023.")
import geopandas as gpd
import matplotlib.pyplot as plt
# Remove rows for Alaska (AK) and Hawaii (HI)
continental_us_gdf = merged_populations_gdf[~merged_populations_gdf['STUSPS'].isin(['AK', 'HI'])]
continental_us_gdf = continental_us_gdf.to_crs(epsg=5070)
fig, ax = plt.subplots(1, 1, figsize=(12, 8))
# Plot the GeoDataFrame using 'Poverty_Rate' column for coloring
continental_us_gdf.plot(column='Poverty_rate', cmap='YlOrRd', linewidth=0.5, edgecolor='0.8',
legend=True, ax=ax, legend_kwds={'label': "Poverty Rate (%)", 'orientation': "vertical"})
# Annotate states with poverty rate greater than 14%
high_poverty_states = continental_us_gdf[continental_us_gdf['Poverty_rate'] > 11.86]
for x, y, label in zip(high_poverty_states.geometry.centroid.x, high_poverty_states.geometry.centroid.y, high_poverty_states['STUSPS']):
ax.text(x, y, label, fontsize=10, ha='center', va='center')
# Set a clear title for the map
ax.set_title('Poverty Rate by State, 2023', fontsize=16)
# Display the map
plt.axis('off')
plt.show()
import geopandas as gpd
import matplotlib.pyplot as plt
# Filter rows for Alaska (AK)
alaska_gdf = merged_populations_gdf[merged_populations_gdf['STUSPS'] == 'AK'].copy() # Use the copy() method
# Round the 'Poverty_rate' column to 2 decimal points
alaska_gdf['Poverty_rate_rounded'] = alaska_gdf['Poverty_rate'].round(2)
# Create a plot for Alaska with Alaska Albers Equal Area Conic projection (EPSG:3338)
fig, ax = plt.subplots(1, 1, figsize=(12, 8))
alaska_gdf = alaska_gdf.to_crs(epsg=3338) # Change the projection to Alaska Albers Equal Area Conic
# Plot the GeoDataFrame for Alaska using 'Poverty_rate_rounded' column for labeling
alaska_gdf.plot(column='Poverty_rate_rounded', cmap='YlOrRd', linewidth=0.8, edgecolor='0.8',
legend=False, ax=ax)
# Add labels with rounded poverty rates and percentage sign for each state
for x, y, label in zip(alaska_gdf.geometry.centroid.x, alaska_gdf.geometry.centroid.y, alaska_gdf['Poverty_rate_rounded']):
ax.text(x, y, f"{label}%", fontsize=10, ha='center', va='center')
# Set a clear title for the map
ax.set_title('Poverty Rate of Alaska, 2023', fontsize=16)
# Display the map without axis
plt.axis('off')
plt.show()
# Filter rows for Hawaii (HI)
hawaii_gdf = merged_populations_gdf[merged_populations_gdf['STUSPS'] == 'HI'].copy() # Use the copy() method
# Round the 'Poverty_rate' column to 2 decimal points
hawaii_gdf['Poverty_rate_rounded'] = hawaii_gdf['Poverty_rate'].round(2)
# Create a plot for Hawaii with Hawaii Albers Equal Area Conic projection (EPSG:102007)
fig, ax = plt.subplots(1, 1, figsize=(8, 8))
hawaii_gdf = hawaii_gdf.to_crs(epsg=32604) # Change the projection to Hawaii Albers Equal Area Conic
# Plot the GeoDataFrame for Hawaii using 'Poverty_rate_rounded' column for labeling
hawaii_gdf.plot(column='Poverty_rate_rounded', cmap='YlOrRd', linewidth=0.8, edgecolor='0.8',
legend=False, ax=ax)
# Add labels with rounded poverty rates and percentage sign for Hawaii
for x, y, label in zip(hawaii_gdf.geometry.centroid.x, hawaii_gdf.geometry.centroid.y, hawaii_gdf['Poverty_rate_rounded']):
ax.text(x, y, f"{label}%", fontsize=10, ha='center', va='center')
# Set a clear title for the map
ax.set_title('Poverty Rate of Hawaii, 2023', fontsize=16)
# Display the map without axis
plt.axis('off')
plt.show()
# Sort the GeoDataFrame by 'Poverty_rate' column in descending order and select the top 5 states
top_5_states = merged_populations_gdf.sort_values(by='Poverty_rate', ascending=False).head(5)
# Create the choropleth map for the top 5 states with highest poverty rates
continental_us_gdf = continental_us_gdf.to_crs(epsg=5070)
fig, ax = plt.subplots(1, 1, figsize=(12, 8))
# Plot the top 5 states using 'Poverty_rate' column for coloring
top_5_states.plot(column='Poverty_rate', cmap='YlOrRd', linewidth=0.8, edgecolor='0.8',
legend=True, ax=ax, legend_kwds={'label': "Poverty Rate (%)", 'orientation': "horizontal"})
# Add labels and rounded poverty rates for the top 5 states
for x, y, label, rate in zip(top_5_states.geometry.centroid.x, top_5_states.geometry.centroid.y, top_5_states['States'], top_5_states['Poverty_rate']):
ax.text(x, y, f"{label}\nPoverty Rate: {round(rate, 2)}%", fontsize=8, ha='center', va='center')
# Set a clear title for the map
ax.set_title('Top 5 States with Highest Poverty Rate, 2023', fontsize=16)
# Display the map
plt.axis('off')
plt.show()