Visualizing Freqency Distribution screen 7

Hello,

Screen Link:

My Code:

from numpy import arange
print(wnba['Games Played'].describe())

wnba['Games Played'].plot.hist(grid = True, xticks = arange(2,33,3))
print(wnba['Games Played'].value_counts(bins=10).sort_index())

What I expected to happen:
I don’t understand the output of the above code
Can someone please explain why the output from the generated frequency table dont match with the histogram? For example: in the frequency table, there are 31 players in the interval between (29.0, 32.0], but i’m seeing 61 in the histogram.

maybe, i’m missing something out.
can someone clarify this?

Hi @smartychiz:

Remember that arange() takes the arguments start, stop, step. Look carefully at the requirements for xticks. It starts at 0 (see the 2 zeros at the base of the axes), ends at 35 and each step is 5. Since the stop argument is not inclusive of the specified value, if we specify 35, it would stop at 34.

Thus the solution will be:

from numpy import arange
print(wnba['Games Played'].describe())

# 2nd arg is 36 for "actual" stop value to be 35.
wnba['Games Played'].plot.hist(xticks = arange(0,36,5))
print(wnba['Games Played'].value_counts(bins=10).sort_index())

You will also not need to specify grid=True as it is not required in the expected diagram below. Besides, grid is set to False by default.

image

Hope this clarifies!

1 Like

Hi @smartychiz: If my answer helped you, do you mind marking it as the solution? Thanks!