我有以下示例DataFrame
<form>
在此示例中,我想在“位置” =“ nyc”的“值”行中检索数字,因此在这种情况下,我想检索数字5。我正在尝试使用.loc布尔值,但不能完全正确
答案 0 :(得分:1)
您可能需要两个def as_two_col_layout(self):
return self._html_output(
normal_row='<div class="form-group m-form__group row">'
'<label class="col-sm-3 col-form-label">%(label)s</label>'
'<div class="col-sm-9">%(field)s%(help_text)s</div></div>',
error_row='%s',
row_ender='</div></div>',
help_text_html=' <span class="m-form__help">%s</span>',
errors_on_separate_row=True)
.loc
如果只需要输出值
df2.loc['value',df2.loc['location']=='nyc']
Out[269]:
col1 5
Name: value, dtype: object
答案 1 :(得分:0)
这将为您提供value
行中的值,但是我正在使用iloc
而不是loc
对其进行索引:
df2.iloc[0, np.where(df2.loc['location', ] == 'nyc')[0]].values
输出:
array(['5'], dtype=object)