''Series' object is not callable (Central Limit Theorem) Sample Mean

I want to know the result of the sample means using Central Limit Theorem. I had trouble with my own jupyter notebook, then I tried in the reference notebook with the same step, and it worked.

df_sale_price = df['SALE PRICE']
df_sale_price
1        499000.0
3        529500.0
4        423000.0
5        501000.0
6        450000.0
           ...   
36578    590000.0
36579    580000.0
36580    509000.0
36581    450000.0
36582    550000.0
Name: SALE PRICE, Length: 32003, dtype: float64

Here's my code and the output:

n = 100
m = 1000
sample_mean_sale_price = []
for i in range(m):
    sample_values = np.random.choice(a=df_sale_price,size=n)
    sample_mean_sale_price.append(np.mean(sample_values))


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [70], in <cell line: 4>()
      2 m = 1000
      3 sample_mean_sale_price = []
----> 4 for i in range(m):
      5     sample_values = np.random.choice(a=df_sale_price,size=n)
      6     sample_mean_sale_price.append(np.mean(sample_values))

TypeError: 'Series' object is not callable

Any help would be greatly appreciated!



Solution 1:[1]

To make your code works i made some changes in the creation of your array , it needs a 1D numpy array so as an example:

import pandas as pd 
import numpy as np

data=[1.0,499000.0,10.0,529500.0,423000.0,590000.0,580000.0,509000.0]

df=pd.DataFrame(data=data, columns=['SALE PRICE'])
df_sale_price=df['SALE PRICE'].values
np.shape(df_sale_price) 
n = 100
m = 1000
sample_mean_sale_price = []
for i in range(m):
  sample_values = np.random.choice(a=df_sale_price,size=n)
  sample_mean_sale_price.append(np.mean(sample_values))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ran A