Code
import pandas as pd
For the three dependent varaibles real GDP per capita (REALGDPpercapita), median household income (MedHHInc), and percentage of bachelor’s degree graduate (PctBach), I plotted a time-series to analyse the general trend. I did not do for life expectancy as I do not have data for 2022 and 2023.
Each line is further colour coded by each US states to identify whether there are disparities over time.
import pandas as pd
### Merge ACS 2019 to 2023 together
= combined_df = pd.concat([USA_acs_data_2019, USA_acs_data_2020, USA_acs_data_2021, USA_acs_data_2022, USA_acs_data_2023], ignore_index=True) USA_acs_data
# Initialize an empty list to store dataframes
= []
dataframes
# Loop through each year and fetch the data
for year in range(2019, 2023 + 1):
= beaapi.get_data(
df
beakey,='Regional',
datasetname='STATE',
GeoFips='1',
LineCode='SAGDP9N',
TableName=str(year)
Year
)
dataframes.append(df)
# Concatenate all the dataframes into one
= pd.concat(dataframes, ignore_index=True) bea_tbl
!pip install geopandas hvplot panel
import geopandas as gpd
import altair as alt
import pandas as pd
import altair as alt
# Create the Altair plot for PctBach
alt.Chart(us_rescaled_final).mark_line().encode(=alt.X('YEAR:Q', scale=alt.Scale(domain=[2019, 2023]), axis=alt.Axis(values=[2019, 2020, 2021, 2022, 2023], tickCount=5)),
x='PctBach:Q',
y='NAME_x:N',
color=['YEAR', 'PctBach', 'NAME_x']
tooltip
).properties(='PctBach against Year',
title=800,
width=600
height )
# Create the Altair plot for REALGDPpercapita
alt.Chart(us_rescaled_final).mark_line().encode(=alt.X('YEAR:Q', scale=alt.Scale(domain=[2019, 2023]), axis=alt.Axis(values=[2019, 2020, 2021, 2022, 2023], tickCount=5)),
x='REALGDPpercapita:Q',
y='NAME_x:N',
color=['YEAR', 'REALGDPpercapita', 'NAME_x']
tooltip
).properties(='REALGDPpercapita against Year',
title=800,
width=600
height )
# Create the Altair plot for MedHHInc
alt.Chart(us_rescaled_final).mark_line().encode(=alt.X('YEAR:Q', scale=alt.Scale(domain=[2019, 2023]), axis=alt.Axis(values=[2019, 2020, 2021, 2022, 2023], tickCount=5)),
x='MedHHInc:Q',
y='NAME_x:N',
color=['YEAR', 'MedHHInc', 'NAME_x']
tooltip
).properties(='MedHHInc against Year',
title=800,
width=600
height )
The three dependent varaibles real GDP per capita (REALGDPpercapita), median household income (MedHHInc), and percentage of bachelor’s degree graduate (PctBach) appear to be increasing over time from 2019 to 2023.
Percentage of bachelor’s degree graduate appears to be increasing between 2019 to 2023 for all states. There are clear disparities between states as to the percentage of bachelor’s degree graduate, which is supported by the map plot in our exploratory analysis.
Real GDP per capita appears to be relatively constant between 2019 to 2023 for most states. This could be due to the economic impact of the Covid-19 pandemic that resulted in fewer economic activities.
Finally, the gradient of the median household income line looks relatively similar across states, suggesting that all states are experiencing relative growth in median household income.