Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this problem, we will determine the distribution of males and females for each of the three passenger classes, and for each of the

In this problem, we will determine the distribution of males and females for each of the three passenger

In this problem, we will determine the distribution of males and females for each of the three passenger classes, and for each of the two survival outcomes. To accomplish this task, we will first need to add two new columns to the titanic DataFrame. Add two new columns to titanic. The names of the new columns should be Female and Male. The values in the Female column should be equal to 1 for any record corresponding to a female, and 0 for any record corresponding to a male. The values in the Male column should be equal to 1 for any record corresponding to a male, and 0 for any record corresponding to a female. This task can be accomplished in a number of ways, but I would recommend using np.where() along with the Sex column. Use the head () method to display the first 8 rows of the new titanic DataFrame. Create a DataFrame named sex_dist_by_class by selecting the Pclass, Female, and Male columns from titanic, grouping the results by Pclass, and then summing the remaining two columns within each group. Display this DataFrame. Create a DataFrame named sex_dist_by_outcome by selecting the Survived, Female, and Male columns from titanic, grouping the results by Survived, and then summing the remaining two columns within each group. Display this DataFrame.

Step by Step Solution

3.37 Rating (144 Votes )

There are 3 Steps involved in it

Step: 1

Step 1 Add two new columns to the titanic DataFrame Female and Male Set the values in the Female column to 1 for female passengers and 0 for male pass... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Statistics

Authors: Michael Sullivan III

4th Edition

978-032184460, 032183870X, 321844602, 9780321838704, 978-0321844606

More Books

Students also viewed these Programming questions