Bessel's correction, error executing the code

Screen Link:

My Code:

import matplotlib.pyplot as plt
houses = pd.read_table('AmesHousing_1.txt')
pop_stdev = standard_deviation(houses['SalePrice'])
from math import sqrt
def standard_deviation(array):
    reference_point = sum(array) / len(array)
    
    distances = []
    for value in array:
        squared_distance = (value - reference_point)**2
        distances.append(squared_distance)
    
    variance = sum(distances) / (len(distances)-1)
    
    return sqrt(variance)

import matplotlib.pyplot as plt
st_devs = []

for i in range(5000):
    sample = houses['SalePrice'].sample(10, random_state = i)
    st_dev = standard_deviation(sample)
    st_devs.append(st_dev)

plt.hist(st_devs)
plt.axvline(pop_stdev)  

What I expected to happen:

Nice work! solution check

What actually happened:

Keep getting this error, but the code seems ok.

TypeErrorTraceback (most recent call last)
<ipython-input-1-0b221cbdffe4> in <module>()
     23 st_devs = []
     24 
---> 25 for i in range(5000):
     26     sample = houses['SalePrice'].sample(10, random_state = i)
     27     st_dev = standard_deviation(sample)

<ipython-input-1-0e34e76ec935> in range(x)
      4 
      5 def range (x):
----> 6     return max(x) - min(x)
      7 
      8 range_by_year = {}

TypeError: 'int' object is not iterable

I tried to reload the page, write the code again and check line by line if something was wrong.

Thank you very much!!

1 Like

Hi @BorjaMunitizGutierre,

Welcome to the Community!

As for your question, you can find useful this post.

It worked perfectly!! Thank you very much!

1 Like