如何从Excel中调用python的值

我目前正在尝试引用来自Excel电子表格中的一个值,该电子表格充满了泰坦尼克号灾难的乘客数据。 这是我坚持的部分。

检查生存统计数字,绝大多数男性没有幸免于沉没。 但是,大多数女性确实在沉没船上幸存下来。 让我们build立在我们以前的预测上:如果一个乘客是女性,那么我们会预测他们幸存下来。 否则,我们会预测乘客没有生存。 填写下面的缺less的代码,以便函数可以做出这个预测。

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

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 

我input了if else语句,而且我的积极性在我的尝试中有很多错误,我希望能够澄清一下如何解决这个问题,excel表格中的数据是存活数据和性别数据。 这是我正在开发的项目的github链接。 https://github.com/udacity/machine-learning/tree/master/projects/titanic_survival_exploration

你的语法是不正确的, else一个缺点: ,你将等号运算符 ==赋值运算符 =

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