Hi I hope someone can help.
In chapter three of Mission 146 I was able to complete the Histogram task but did so in a very ‘clunky’ way. I looked at the solution guide to find a better way but it seems that either I or the solution guide is doing something incorrect.
The below is from the solution guide
cols = [“Sample_size”, “Median”, “Employed”, “Full_time”, “ShareWomen”, “Unemployment_rate”, “Men”, “Women”]
fig = plt.figure(figsize=(5,12))
for r in range(1,5):
ax = fig.add_subplot(4,1,r)
ax = recent_grads[cols[r]].plot(kind=‘hist’, rot=40)
fig = plt.figure(figsize=(5,12))
for r in range(4,8):
ax = fig.add_subplot(4,1,r-3)
ax = recent_grads[cols[r]].plot(kind=‘hist’, rot=40)
I duplicated this because it was so much cleaner than mine but wanted to make it a little better and add titles etc. But when I did this it appeared that the first code was displaying graphs [“Median”, “Employed”, “Full_time”, “ShareWomen”,] and the second was displaying [“ShareWomen”, “Unemployment_rate”, “Men”, "Women]. Basically it looks like the ‘SharedWomen’ graph is being displayed twice and column ‘Sample_size’ is not being displayed. If I attempt to set the range(1,5) to range(0,5) I get an error. If I add a filler into the first position of the cols list such as ‘xxxxx’ and rerun the code I appear to get the correct graphs.
col = [‘xxxxx’,‘Sample_size’,‘Median’,‘Employed’,‘Full_time’,‘ShareWomen’,‘Unemployment_rate’,‘Men’,‘Women’]
fig = plt.figure(figsize =(5,12))
for r in range(1,5):
ax = fig.add_subplot(4,1,r)
ax = recent_grads[col[r]].plot(kind=‘hist’,rot=30).set_title(col[r])
My questions are:
A - Am I correct that the solution guide is missing one graph and displaying the other twice? Or am I going crazy.
B - Why won’t the range() accept ‘0’ as a starting point? Basically how do I reference the first item in the cols list without using the filler workaround that I have in there?