Question: ` ` ` In [ ] : import pandas as pd import matplotlib.pyplot as plt data = pd . read _ csv ( .

```
In []: import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_csv("./alleghenyCensusTractIncome_processed.csv")
data = data[data["Type"]== "Households"][["Census Tract","Mean income (dollars)"]]
print("Number of Census Tracts: %d"% len(data))
data["Mean income (dollars)"].hist()
plt.xlabel("Avg. Annual Household Income ($)",fontsize=15)
plt.ylabel("Number of Census Tracts",fontsize=15)
data.head()
```
If I take a random sample of 50 Census Tracts, what is the probability that the sample's expected value falls between \(\$ 100,000\) and \(\$ 110,0000\)?
Previously, we answered this kind of question by referring to the following plot of the normal distribution. We will discuss how to calculate these probabilities for any interval on the distribution in a future module. But, for now, know that the area under the curve is representing the probability that the sample mean falls within an interval. For example, the probability that the sample mean is between the population mean and 1 standard error above the mean (i.e., between 0 and \(1\sigma \) in the plot) is \(34.1\%\).
For now, I want you to use the Scipy Python package to answer this question with an exact probability. Scipy is a Python package designed for scientific computing and it contains many useful functions for statistics and machine learning. The "scipy.stats.norm" is a Python class for representing the Normal Distribution given an expected value and the standard deviation. ```
In []: # Here is an example using scipy.stats.norm to calculate the probability that the sample mean is below 2 given that the populatic
import scipy
popExpectedValue =3,
standardError =1
N = scipy.stats.norm(loc=3,scale=1)
p = N.cdf(2)
print("Probability the expected value of the sample is below 2 is %0.3f"% p)
```
Use the cell below to answer the question about Allegheny County Census Tracts: If I take a random sample of Census Tracts, what is the probability that the sample's expected value falls between \(\$ 100,000\) and \(\$ 110,0000\)?
```
In []: import scipy
def calculate_income_distribution(data):
# your code here
raise NotImplementedError
return #your code here.
calculate_income_distribution(data)
```
` ` ` In [ ] : import pandas as pd import

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!