Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Q 4 . Please create two bar plots as per below that show: 1 ) The number of individuals who have a High School Graduate
Q Please create two bar plots as per below that show:
The number of individuals who have a High School Graduate Diploma AND earn K in the United States
The number of individuals who have a High School Graduate Diploma AND earn K in the United States
Working on a python question and they are asking to create a separate graph for each of these.
Code :
hsgraduateslowincome dfdfDegree Status' 'High School Grad' & dfEarnings & dfCountry 'United States'
hsgraduateshighincome dfdfDegree Status' 'High School Grad' & dfEarnings & dfCountry 'United States'
# Step : Count the number of individuals in each category.
lowincomecounts hsgraduateslowincome.shape
highincomecounts hsgraduateshighincome.shape
# Step : Create bar plots.
# Bar plot for individuals with High School Graduate Diploma and K income
pltbarKlowincomecounts color'blue', labelK
# Bar plot for individuals with High School Graduate Diploma and K income
pltbarKhighincomecounts color'orange', labelK
# Add labels and title
pltxlabelEarnings
pltylabelNumber of Individuals'
plttitleNumber of High School Graduates by Income in the United States'
# Add legend
pltlegend
# Show the plot
show
error
KeyError Traceback most recent call last
File ~anacondalibsitepackagespandascoreindexesbasepy: in Index.getlocself key, method, tolerance
try:
return self.engine.getloccastedkey
except KeyError as err:
File ~anacondalibsitepackagespandaslibsindexpyx: in pandas.libs.index.IndexEngine.getloc
File ~anacondalibsitepackagespandaslibsindexpyx: in pandas.libs.index.IndexEngine.getloc
File pandaslibshashtableclasshelper.pxi: in pandas.libs.hashtable.PyObjectHashTable.getitem
File pandaslibshashtableclasshelper.pxi: in pandas.libs.hashtable.PyObjectHashTable.getitem
KeyError: 'Degree Status'
The above exception was the direct cause of the following exception:
KeyError Traceback most recent call last
Cell In line
hsgraduateslowincome dfdfDegree Status' 'High School Grad' & dfEarnings & dfCountry 'United States'
hsgraduateshighincome dfdfDegree Status' 'High School Grad' & dfEarnings & dfCountry 'United States'
# Step : Count the number of individuals in each category.
File ~anacondalibsitepackagespandascoreframepy: in DataFrame.getitemself key
if self.columns.nlevels :
return self.getitemmultilevelkey
indexer self.columns.getlockey
if isintegerindexer:
indexer indexer
File ~anacondalibsitepackagespandascoreindexesbasepy: in Index.getlocself key, method, tolerance
return self.engine.getloccastedkey
except KeyError as err:
raise KeyErrorkey from err
except TypeError:
# If we have a listlike key, checkindexingerror will raise
# InvalidIndexError. Otherwise we fall through and reraise
# the TypeError.
self.checkindexingerrorkey
KeyError: 'Degree Status'
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started