0

I have a dataframe that is constructed with numbers from 1 to 16, but without number 15.

df = pd.DataFrame({'rand_int_no_15':[random.choice([ 1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 16]) for cnt in range(100) ]})

Now I would like to display histogram in which I will see that there is no number 15. In order to do so, I have executed

df.rand_int_no_15.hist(bins=np.arange(1, df.rand_int_no_15.max() + 1))

enter image description here

but, what I got is histogram from which I cannot conclude that number 15 doesn't exist. I would have expected that bar above number 15 is empty.

Am I doing something wrongly?

Regards.

user3225309
  • 1,183
  • 3
  • 15
  • 31
  • Are you sure you want a histogram and not a bar chart? – Sheldore Sep 20 '19 at 13:21
  • 1
    The rightmost bin in numpy/matplotlib histograms is closed. Hence you need `bins=np.arange(1, df.rand_int_no_15.max() + 2)` – ImportanceOfBeingErnest Sep 20 '19 at 13:23
  • It works as you suggested. If I use align='left' (I don't know why but) then each number is between its bar. df.rand_int_no_15.hist(bins=np.arange(1, df.rand_int_no_15.max() + 2), align='left') – user3225309 Sep 20 '19 at 13:36

0 Answers0