<s> """<STR_LIT>""" <EOL> import csv as csv <EOL> import numpy as np <EOL> csv_file_object = csv . reader ( open ( '<STR_LIT>' , '<STR_LIT:rb>' ) ) <EOL> header = csv_file_object . next ( ) <EOL> data = [ ] <EOL> for row in csv_file_object : <EOL> data . append ( row [ <NUM_LIT:0> : ] ) <EOL> data = np . array ( data ) <EOL> number_passengers = np . size ( data [ <NUM_LIT:0> : : , <NUM_LIT:1> ] . astype ( np . float ) ) <EOL> number_survived = np . sum ( data [ <NUM_LIT:0> : : , <NUM_LIT:1> ] . astype ( np . float ) ) <EOL> proportion_survivors = number_survived / number_passengers <EOL> women_only_stats = data [ <NUM_LIT:0> : : , <NUM_LIT:4> ] == "<STR_LIT>" <EOL> men_only_stats = data [ <NUM_LIT:0> : : , <NUM_LIT:4> ] != "<STR_LIT>" <EOL> women_onboard = data [ women_only_stats , <NUM_LIT:1> ] . astype ( np . float ) <EOL> men_onboard = data [ men_only_stats , <NUM_LIT:1> ] . astype ( np . float ) <EOL> proportion_women_survived = np . sum ( women_onboard ) / np . size ( women_onboard ) <EOL> proportion_men_survived = np . sum ( men_onboard ) / np . size ( men_onboard ) <EOL> print '<STR_LIT>' % proportion_women_survived <EOL> print '<STR_LIT>' % proportion_men_survived <EOL> test_file = open ( '<STR_LIT>' , '<STR_LIT:rb>' ) <EOL> test_file_object = csv . reader ( test_file ) <EOL> header = test_file_object . next ( ) <EOL> predictions_file = open ( "<STR_LIT>" , "<STR_LIT:wb>" ) <EOL> predictions_file_object = csv . writer ( predictions_file ) <EOL> predictions_file_object . writerow ( [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> for row in test_file_object : <EOL> if row [ <NUM_LIT:3> ] == '<STR_LIT>' : <EOL> predictions_file_object . writerow ( [ row [ <NUM_LIT:0> ] , "<STR_LIT:1>" ] ) <EOL> else : <EOL> predictions_file_object . writerow ( [ row [ <NUM_LIT:0> ] , "<STR_LIT:0>" ] ) <EOL> test_file . close ( ) <EOL> predictions_file . close ( ) </s>
