Question: Input the following data into a data frame called titanic, and display the entire data frame: Sex, Class, Survived, Died Children, First, 6, 0 Children,



  1. Input the following data into a data frame called titanic, and display the entire data frame:

 Sex, Class, Survived, Died

 Children, First, 6, 0

 Children, Second, 24, 0

 Children, Third, 27, 52

 Men, First, 57, 118

 Men, Second, 14, 154

 Men, Third, 75, 387

 Men, Crew, 192, 693

 Women, First, 140, 4

 Women, Second, 80, 13

 Women, Third, 76, 89

 Women, Crew, 20, 3 

 

  1. Using Boolean Indexing (See hereLinks to an external site.), show the data of the people in first class.

 

  1. Delete the crew members from the data (use Boolean indexing).

 

  1. Create a new column that is the total number of people for that group (those who survived + died.  Use Boolean Indexing in conjunction with selection of non-existent column).

 

  1. Create a new column with the percentage of people who survived.

 

  1. Delete the column indicating the total number of people in that group.

 

  1. Only show the rows where more than 80% of the people survived.

 

  1. Then only show the rows where less than 40% of the people survived.

 

  1. Calculate the total number of people that survived and died for each class, then report the percentages. (Hint: Use a grouped calculation.)

 

  1. Save your table in CSV format (as e.g. titanic_data.csv) with the first line as headers for the columns (see examples:  hereLinks to an external site.)

 

  1. Duplicate the CSV file on your computer since you will be editing the copied version (e.g. titanic_data2.csv). Open the new CSV file in a text editor. Note the way the data is organized. Now, in the text editor, add new lines including the data for the crew that was removed earlier. (Help: the percentage of male crew and female crew that survived was 21.69% and 86.96%.)

 

  1. Now read that updated CSV file into a new data frame called titanic2, and display the data.

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!