我创建了一个结构化数组,如下所示:
name = ['Alice', 'Beth', 'Cathy', 'Dorothy']
studentid = [1,2,3,4]
score = [85.4, 90.4, 87.66, 78.9]
student_data = np.zeros(4, dtype={'names':('name', 'studentId', 'score'),
'formats':('U10', 'i4', 'f8')})
student_data['name'] = name
student_data['studentId'] = studentid
student_data['score']=score
student_data[student_data['score'] > 85]['name']
但是,如果我试图检索另一个列和“name”,就会得到一个错误:
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
例如,我尝试了以下方法:
student_data[student_data['score'] < 90]['name','studentid']
student_data[student_data['score'] < 90]['name']['studentid']
两者都会导致错误:
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-189-7ad7c151f0e3> in <module>
----> 1 student_data[student_data['score'] < 90]['name']['studentid']
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
有人能告诉我我在这里犯了什么错误吗?我怎样才能有条件地检索多个列?