Created
February 11, 2017 21:41
-
-
Save gabrielrojasnyc/edd87ec63c2040cd644fc3e84570ebf3 to your computer and use it in GitHub Desktop.
submission_1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
# In[24]: | |
import csv | |
fh = open('train.csv') | |
reader_csv = csv.reader(fh) | |
passanger_list = list(reader_csv) | |
passanger_list = passanger_list[1:] | |
print(passanger_list[0]) | |
# In[68]: | |
for row in passanger_list: | |
if row[5] == '': | |
row[5] = '100' | |
# In[270]: | |
count_age_30 = 0 | |
count_age_50 = 0 | |
count_age_f_30 = 0 | |
total_passanger = 0 | |
class_count_1 = 0 | |
for row in passanger_list: | |
passanger_class = int(row[2]) | |
passanger_age = float(row[5]) | |
if passanger_age <= 30 and row[4] == 'male': | |
count_age_30 += 1 | |
if passanger_age > 50 and row[4] == 'male': | |
count_age_50 += 1 | |
if passanger_age > 30 and row[4] == 'female': | |
count_age_f_30 += 1 | |
if passanger_class == 1: | |
class_count_1 += 1 | |
print('Male younger than 31',count_age_30) | |
print('Male older than 50',count_age_50) | |
print('Female older than 30',count_age_f_30) | |
print('Passangers 2nd class', class_count_1) | |
# In[273]: | |
count_age_died_30 = 0 | |
count_age_died_50 = 0 | |
total_passanger = 0 | |
count_age_s_f_30 = 0 | |
class_count_s_1 = 0 | |
for row in passanger_list: | |
passanger_class = int(row[2]) | |
passanger_age = float(row[5]) | |
if passanger_age <= 30 and row[1] == '0' and row[4] == 'male': | |
count_age_died_30 += 1 | |
if passanger_age > 50 and row[1] == '0' and row[4] == 'male': | |
count_age_died_50 += 1 | |
if passanger_age > 30 and row[1] == '1' and row[4] == 'female': | |
count_age_s_f_30 += 1 | |
if passanger_class == 1 and row[1] == '1': | |
class_count_s_1 += 1 | |
print('Male younger than 31 died',count_age_died_30) | |
print('Male older than 50 died',count_age_died_50) | |
print('Female older than 30 survived',count_age_s_f_30) | |
print('Passangers 2nd class died', class_count_s_1) | |
# In[274]: | |
print(count_age_died_30/count_age_30) | |
print(count_age_died_50/count_age_50) | |
print(count_age_s_f_30/count_age_f_30) | |
print(class_count_s_1/class_count_1) | |
# In[275]: | |
47 * 0.60 | |
# In[ ]: | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment