2016-09-16 45 views
1

我目前正在尝试从Excel电子表格中提取一个值,该值充满了泰坦尼克号灾难的乘客数据。这是我被卡住的部分。如何从Excel中调用Excel的值

检查生存统计,绝大多数男性没有 幸免于船沉没。然而,大多数女性确实能够幸免于船下沉 。让我们建立在我们之前的预测上:如果乘客是女性,那么我们会预测他们幸存下来。否则,我们会预测乘客没有生存。填写下面的 缺少的代码,以便该函数将进行此预测。

提示:您可以访问像 字典这样的乘客的每个功能的值。例如,乘客['性']是乘客的性别。

def predictions_1(data): 
    """ Model with one feature: 
      - Predict a passenger survived if they are female. """ 

    predictions = [] 
    for _, passenger in data.iterrows(): 

     # Remove the 'pass' statement below 
     # and write your prediction conditions here 
     if passenger['Sex'] == 'female': 
      survived == 1 
     else survived == 0 

    # Return our predictions 
    return pd.Series(predictions) 
​ 
# Make the predictions 
predictions = predictions_1(data) 


    File "<ipython-input-75-6b2fca23446d>", line 12 
    else survived == 0 
       ^

SyntaxError: invalid syntax 

我输入的if else语句,我敢肯定有我尝试了许多错误,我会很感激一些清晰度如何解决这个问题,从Excel工作表中的数据的存活和性别数据。这是我正在开发的项目的github链接。 https://github.com/udacity/machine-learning/tree/master/projects/titanic_survival_exploration

回答

3

你的语法不正确与else缺少:,而你与assignment operator=混合equality operator==

if passenger['Sex'] == 'female': 
     survived = 1 # bind int value 1 to the name 'survived' 
    else: 
     survived = 0