#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue Apr 10 14:11:57 2018 @author: teacher """ import pandas as pd import numpy as np # Sets the seed for the random number generator. Code with the same seed will always produce # the same ("random") results. #np.random.seed(3) # Set up the distribution of the population: 26% Black, 74% Other (non-black) #population = ['Black','Other'] population = ['B','O'] weight = [0.26,0.74] # create a new list num_list = [] # generate 10,000 samples for i in range(10000): # generate 1 sample: #----- # create a jury panel of 100 people sampled from the local population sample_array = np.random.choice(population,p=weight,size=100) #print(sample_array) # turn the sample, which is a numpy array, into a pandas series sample = pd.Series(sample_array) #print(sample) # count the nuumber of Black and Other men on the jury panel counts = sample.value_counts() #print(counts) # store the number of Black men on the jury panel num = counts['B'] #print(num) #---- # add number to our list num_list.append(num) # convert our list into a series and plot a histogram of its contents num_series = pd.Series(num_list) num_series.plot.hist(bins=20)