If you can guarantee only one result is returned, use loc and call item:
>>> df.loc[df['Host'] == 'a', 'Port'].item()
'b'
Or, similarly,
>>> df.loc[df['Host'] == 'a', 'Port'].values[0]
'b'
...to get the first value (similarly, .values[1] for the second). Which is better than df.loc[df['Host'] == 'a', 'Port'][0] because, if your DataFrame looks like this,
Host Port
1 a b
Then "KeyError: 0" will be thrown—
df.loc[df['Host'] == 'a', 'Port'][0]
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
Alternatively, use at:
>>> df.at[df['Host'].eq('a').idxmax(), 'Port']
'b'
The drawback is that if 'a' doesn't exist, idxmax will return the first index (and return an incorrect result).
t = df[df['Host'] == 'a']['Port'][0]ort = df[df['Host'] == 'a']['Port'][1]. I have a fuzzy memory of this working for me during debugging in the past.df[df['Host'] == 'a']['Port'][0]or `print(df[df['Host'] == 'a']['Port'][0])