Question

In: Computer Science

Consider below dataframe, df2, which provides the number of males and females in a population as...

Consider below dataframe, df2, which provides the number of males and females in a population as well as their socio-economic breakdown. Provide python codes to calculate following probabilities:

  • (2.a) For a randomly selected person from this population, probability of being female ("F")
  • (2.b) For a randomly selected person from this population, probability of being working class ("working")
  • (2.c) For a randomly selected person from this population, joint probability of being male ("M") and middle class ("middle")

df2 = pd.DataFrame({"M": [30,250,20], "F":[10,150,40]}, index=["upperMiddle", "middle", "working"])

df2

Solutions

Expert Solution

RAW CODE

import pandas as pd

df2 = pd.DataFrame({"M":[30,250,20],"F":[10,150,40]},index = ["UpperMiddle","middle","working"])

#randomly selected person from this population, probability of being female ("F")

total_females = df2.iloc[:,1].sum() ### female is at index 1 of column. (summing all the females present)
total_peoples = df2.iloc[:,0].sum() + df2.iloc[:,1].sum() ### Sum of total population

print("Probability of being female: ",total_females/total_peoples) ### Probability = favourable/total_outcomes

#randomly selected person from this population, probability of being working class ("working")

total_working_class = df2.iloc[2,:].sum() ### Working is at the index 2, we can also use -1 instead of 2 as it is last index.

print("Probability of being working class: ",total_working_class/total_peoples)

#randomly selected person from this population, joint probability of being male ("M") and middle class ("middle")

total_male_middle_class = df2.iloc[1,0] ### middle class row is at 1 index and  Male is at 0 index. (Just one value so no need of sum)

print("Probability of being middle class male: ",total_male_middle_class/total_peoples)

SCREENSHOTS (CODE AND OUTPUT)

CODE

OUTPUT

##### FOR ANY QUERY, KINDLY GET BACK, THANKYOU. #####


Related Solutions

Data below shows counts of males and females in a sample population and the political party...
Data below shows counts of males and females in a sample population and the political party they voted for. Create the observations matrix using the provided R syntax below Select the appropriate statistical test, Formulate the null hypothesis in your own words, Compute the test statistic, Find the critical value in Chi square table with the corresponding degrees of freedom Find and interpret the statistical decision at the 0.01 significance level # Gender and political affiliation observed <- as.table(rbind(c(762, 327,...
Question 2. Below is a crosstab table for the number of smokers among males and females...
Question 2. Below is a crosstab table for the number of smokers among males and females in a sample of 100 people. Is there a statistically significant association between Gender and Smoking? (Use Chi-Square). Male Female Total Smoking 22 18 40 Not smoking 26 34 60 Totals 48 52 100
which structure varies between males and females
which structure varies between males and females
For the 2015 General Social Survey, a comparison of females and males on the number of...
For the 2015 General Social Survey, a comparison of females and males on the number of hours a day that the subject watched TV gave the following results. Group n Mean Females 504 3.07 Males 398 2.87 (a) Set up the hypotheses of a significance test to analyze whether the population means differ for females and males. Ho: 1 Correct: Your answer is correct. 2 Ha: 1 Correct: Your answer is correct. 2 (b) Conduct all parts of the significance...
For the 2015 General Social Survey, a comparison of females and males on the number of...
For the 2015 General Social Survey, a comparison of females and males on the number of hours a day that the subject watched TV gave the following results. Group n Mean Females 500 3.09 Males 401 2.88 (a) Set up the hypotheses of a significance test to analyze whether the population means differ for females and males. Ho:   1    ---Select---  =  not equal  >  <   2 Ha:   1    ---Select---  =  not equal  >  <   2 (b) Conduct all parts of the significance test if df = 499 and standard error = 0.163...
A population of 20,000 students at UCSC. 10,400 are Males, 9,200 are Females, and 400 are...
A population of 20,000 students at UCSC. 10,400 are Males, 9,200 are Females, and 400 are Other. You take a random sample of n = 100 students. Sample has: 52 Male, 46 Female, 2 Other. In this case, the Chance Error is 0%. *(But it won’t always be 0, in other cases!).    *(For A, B: SHOW YOUR WORK!) A) What is the Population Percentage (e.g., composition)? (HINT: Is it 50%-50%? Something else? Etc.) B) What is the Sample Percentage...
Below is a two-way table which describes the breakdown of majors by gender MALES FEMALES Total...
Below is a two-way table which describes the breakdown of majors by gender MALES FEMALES Total SCIENCE 29 85 114 ENGINEERING 41 91 132 BUSINESS 63 123 186 LIBERAL ARTS 58 79 137 Total a. Which type of test should be carried out to test the hypothesis that there is no association between major and gender in the source population,?                            [ Select ]                       ["Goodness of...
Is the life expectancy among African-American females and males and Caucasian females and males different. What...
Is the life expectancy among African-American females and males and Caucasian females and males different. What factors may account for these differences?
Assume that a human population consists of 5,000 reproducing females and 7,000 reproducing males. (a) What...
Assume that a human population consists of 5,000 reproducing females and 7,000 reproducing males. (a) What is the effective population size on the autosomes? (b) What is the expected time (in generations) for a pair of autosomes to coalesce? (c) What is the effective population size on the Y-chromosome? (d) What is the expected time (in generations) for a pair of Y chromosomes to reach their most recent common ancestor?
Statistics indicate that 4% of males and 0.3% of females are color-blind.Assume thata population is half...
Statistics indicate that 4% of males and 0.3% of females are color-blind.Assume thata population is half female.What is the probability that a randomly selected person isfemale, given that the person is color-blind?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT