Plotting Margins of Error over Time
In this exercise you will inspect changing home prices in Philadelphia, PA, using a line plot with error bars. The data come from ACS 1-year sample Table B25077. The estimates and margin of error for each year from 2011 to 2017 have been downloaded and concatenated into a pandas DataFrame named philly. ACS table variables for the estimate and margin of error have been renamed to median_home_value and median_home_value_moe, respectively. (See the DataFrame in the console.)
pandas has been imported as pd.
This exercise is part of the course
Analyzing US Census Data in Python
Exercise instructions
- Import
matplotlib.pyplotusing the aliasplt - Create column
rmoe(to hold the median home value Relative MOE) as100times the margin of error column divided by the estimate column printthe DataFrame to inspect the Relative MOE- Create an error bar plot: set the first argument to
"year"; set the second argument to the name of the median home value column; set parameteryerrto the median home value MOE column; finally, set the data argument to thephillyDataFrame
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import graphics packages
import seaborn as sns
sns.set()
____
# Calculate and inspect Relative Margin of Error
philly["rmoe"] = ____
____
# Create line plot with error bars of 90% MOE
plt.errorbar(____, ____, yerr = ____, data = ____)
plt.show()