This refers to the this project in the Analyze Data With Python Skill Path - https://www.codecademy.com/paths/data-science/tracks/intro-statistics-numpy/modules/dspath-intro-statistics/projects/election-binomial
I have two problems with this, one is just a bit of a complaint about the structure, the other is something that seems like maybe a bug? If not I’m completely stuck on what I’m doing wrong.
The whole lesson up to this point has been focused on how to use NumPy to work out distributions, means, medians, etc. So naturally the hints push you in this direction, which is good since that’s what we’re supposed to be learning. However, when you check the Project Walkthrough, the dev eschews NumPy entirely and just uses regular math. Which is fine, but not exactly helpful for solidifying the knowledge learned so far.
The bigger problem - even if I copy the Project Walkthrough line by line, I simply cannot get the project to produce the same histogram. The binomial distribution I end up with is filled entirely with zeros. I’ve deleted and rewritten this line many times to ensure there’s no typos but it always produces the same result: all zeros:
possible_surveys = np.random.binomial(survey_length, .54, size=10000) / survey_length
Anyone able to help and hopefully explain what I’m doing wrong? Or is this a bug with the project?
Edit: I found the answer to the second part of the question - the binomial distribution was producing the right results but when divided by
survey_length the fractional part was being removed as neither of the numbers were a float. I converted
survey_length to a float and it works!